Range filter
is used to perform operations like greater than(>), less than (<),
greater than or equal to (>=) and less than or equal to (<=).
Example
"range"
: {
"id" : {
"gte" : 1,
"lt" : 400
}
}
Above
snippet return all documents where id’s >=1 and <400.
Range filter
accepts below parameters.
Parameter
|
Meaning
|
gte
|
Greater
than or equal to
|
gt
|
Greater
than
|
lte
|
Less than
or equal to
|
lt
|
Less than
|
Get all employees whose ids are between 10 and 20.
GET /organization/employee/_search
{
"query": {
"filtered": {
"filter": {
"range": {
"id": {
"gte": 10,
"lte": 20
}
}
}
}
}
}
Above query
return following response.
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "organization",
"_type": "employee",
"_id": "5",
"_score": 1,
"_source": {
"id": 12,
"firstName": "Sailaja",
"lastName": "Navakotla",
"designation": "Software Engineer",
"mailId": "wxyasdf@wxyz.com",
"hobbies": [
"climbing hills",
"shopping",
"travelling"
],
"address": {
"street": "TNagar",
"city": "Chennai",
"state": "Tamilnadu",
"country": "India",
"PIN": "5609126"
}
}
}
]
}
}
No comments:
Post a Comment