您好我可以使用DateRangeQuery数组填充QueryContainer,如下所示:QueryContainer marriageDateQuerys = null;
if (!string.IsNullOrEmpty((item.marriage_date)))
{
DateRangeQuery query = new DateRangeQuery();
query.Field = "marriages.marriage_date";
query.Name = item.marriage_date;
query.GreaterThanOrEqualTo = item.marriage_date;
query.LessThanOrEqualTo = item.marriage_date;
marriageDateQuerys &= query;
}
但是当我使用QueryContainer来使用MatchQuery / TermQuery填充数据时,它就不会发生。
QueryContainer marriageSpouseFirstNameQuerys = null;
if (!string.IsNullOrEmpty((item.spouse_first_name)))
{
MatchQuery query = new MatchQuery();
query.Field = "marriages.spouse_first_name";
query.Name = item.spouse_first_name;
marriageSpouseFirstNameQuerys &= query;
}
查询对象是在last if if条件中创建的,但是weddingSpouseFirstNameQuerys没有填充相同的内容。我甚至试过了weddingSpouseFirstNameQuerys + = query;但没有任何成功
答案 0 :(得分:1)
没有尝试过,但你可以尝试这样的事情
Query = new QueryContainer(new BoolQuery
{
Must = new List<QueryContainer>
{
new MatchQuery
{
//props
},
new TermQuery
{
Field = field
Value = value
},
}
})
答案 1 :(得分:0)
在使用eyildiz答案进行更改后,下面的代码对我有用
if (!string.IsNullOrEmpty((item.spouse_last_name)))
{
marriageSpouseLastNameQuery = new QueryContainer(
new MatchQuery
{
Field = "marriages.spouse_last_name",
Query = item.spouse_last_name
});
lstmarriageSpouseLastNameQuerys.Add(marriageSpouseLastNameQuery);
}