Help with querying with nested fields and range


(chandu) #1

Hi

Could someone help with the query?

Here is couple of sample records (simplified) that are stored in elasticsearch

record#1
{
"some_field": true,
"products": {
"a": { "dt": "2018-08-28"},
"b": { "dt": "2018-08-29"},
"c": { "dt": "2018-08-27"},
"d": { "dt": "2018-08-20"},
}
}

record#2
{
"some_field": false,
"products": {
"a": { "dt": "2018-08-27"},
"d": { "dt": "2018-08-21"},
}
}

I am trying to write a query that would fetch the following result:
All records that have products "b" with dt in the range of 2018-08-20 and 2018-08-30 sorted by products.b.dt

I am running ES 2.4

Any help is appreciated.

I tried running the below query but it is throwing error. Basically, I wanted to run "range" only if the field exist

{ "query": { "bool": { "must": [ {"exists": { "field": "products.b"}}, {"range":{"products.b.dt": {"lt":" 2018-08-30", "gt": " 2018-08-20"} }} ] } } }


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.