I want to get values between 1000 and 2000. I tried this query:
{ "query": { "bool": { "filter": [{ "range": { "price": { "gte": 1000 }, "price": { "lte": 2000 } } }] } } }
But this doesn't give satisfactory results. Greater than works fine. I am using elasticsearch v6.3. Please help with solution for both inclusive and exclusive of both values.
By default, Elasticsearch uses the date format provided in the <field> 's mapping. This value overrides that mapping format. For valid syntax, see format . If a format or date value is incomplete, the range query replaces any missing components with default values.
Returns documents where the price
value between 1000 and 2000 inclusive.
{ "query": { "range" : { "price" : { "gte" : 1000, "lte" : 2000 } } } }
Range Query
Matches documents with fields that have terms within a certain range. The type of the Lucene query depends on the field type, for string fields, the TermRangeQuery, while for number/date fields, the query is a NumericRangeQuery.
gte
- Greater-than or equal to
lte
- Less-than or equal to
gt
- Greater-than
lt
- Less-than
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With