Is it possible to add multiple range queries using the Java API[5.0] ?
Sure. Combine them with a boolQuery
in whatever way make the most sense to you. Here is the documentation for that query. Most stuff should translate cleanly from the rest-based examples on that page to the java transport API.
Hi Nik I have gone through that link whichever you mentioned in above post , I meant to say that can we make multiple ranges on single field. e.g I have a requirement like, I have one duration field in facet that ranges from 0-15,16-30,31-45,46-60 and >61 mins.
I tried range query like as below but it is not giving any result can you please help me where I am doing wrong or how can I achieve this ?
GET _search
{
"query": {"bool" : {
"filter" : [
{
"range" : {
"callDuration" : {
"from" : "60",
"to" : "900",
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
{
"range" : {
"callDuration" : {
"from" : "960",
"to" : "1800",
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
{
"range" : {
"callDuration" : {
"from" : "1860",
"to" : "2700",
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
},
{
"range" : {
"callDuration" : {
"from" : "2760",
"to" : "3600",
"include_lower" : true,
"include_upper" : true,
"boost" : 1.0
}
}
}
]
}
}
}
In your example you're using a bool query with two filters. This means that you want to filter documents that have a callDuration between 60 and 900 AND 960 and 1800. What you want is all documents with a callDuration that is between 60 and 900 OR 960 and 1800. You can achieve this by changing your filter
clauses into should
clauses:
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html#query-dsl-bool-query
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.