Reputation: 1982
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.
Upvotes: 53
Views: 132152
Reputation: 25136
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
Upvotes: 113