Closed
Description
Combining multiple queries into a single boolean query but the query generated is empty for the queries that are created from a raw string.
With this method call
ConvertQueryToESD("{\"term\":\"fieldname\":\"value\"}"
,null
,a range filter)
.From(0)
.Take(50)
.SortMulti(a sort)
internal SearchDescriptor<T> ConvertQueryToESD<T>(string queryString, string filterId, List<QueryContainer> filters) where T : class
{
var filterQueryString = GetFilter(filterId);
if (!string.IsNullOrWhiteSpace(filterQueryString))
{
var qd = new QueryDescriptor<T>();
filters.Add(qd.Raw(filterQueryString));
}
if (!string.IsNullOrWhiteSpace(queryString))
{
var qd = new QueryDescriptor<T>();
filters.Add(qd.Raw(queryString));
}
var sd = new SearchDescriptor<T>();
sd.Query(q => q.Bool(b => b.Must(filters.ToArray())));
return sd;
}
Resulting query is
{
"from": 0,
"size": 50,
"sort": [
{
"startTimeLocal": {
"order": "desc"
}
}
],
"query": {
"bool": {
"must": [
{
"range": {
"startTimeLocal": {
"gte": "0001-01-01T00:00:00",
"lte": "2015-12-22T16:28:22"
}
}
},
{}
]
}
}
}
The {}
is where I would expect to see the raw term query. Inspecting the SearchDescriptor before the search is ran shows all the expected fields are populated with the correct values. I have also tested only adding the raw string term query without the range filter and the search descriptor serializes as expected
Metadata
Metadata
Assignees
Labels
No labels