我希望搜索一个文档的方式是,根据“from”和“to”字段的精确值进行过滤。我使用传递给bool查询示例的daterangequery对象。
当只过滤一个日期时,此过滤器工作正常,但当两个日期都处于活动状态时,它根本不返回任何文档。代码波纹管
DateRangeQuery fromDateRangeQuery = new DateRangeQuery()
{
Name = "from_query",
Field = "from",
GreaterThanOrEqualTo = dateFrom,
LessThanOrEqualTo = dateFrom,
};
queryContainers.Add(fromDateRangeQuery);
DateRangeQuery ToDateRangeQuery = new DateRangeQuery()
{
Name = "to_query",
Field = "to",
GreaterThanOrEqualTo = dateTo,
LessThanOrEqualTo = dateTo,
};
queryContainers.Add(ToDateRangeQuery);
//more terms filters not related to the 2 fields
var searchRequest = new SearchRequest("0___aggregate_");
searchRequest.SearchType = SearchType.QueryThenFetch;
searchRequest.From = 0;
searchRequest.Size = 10000;
searchRequest.Query = boolQuery;
var searchResponse = Get().SearchAsync<AggregationHolder>(searchRequest);
searchResponse.Wait(60000);
var status = searchResponse.Result;
datefrom和dateto都是常规的日期时间对象。我做错了什么,为什么我不能合并这两个过滤器?
1条答案
按热度按时间nzkunb0c1#
也许,问题是你的约会方式。你能试试下面的吗?