This is the query that throws the exception using ES 2.0:
bool query does not support filter
How to use Exists and Missing query?
Query:
{
"bool":{
"must":[
{
"bool":{
"should":[
{
"bool":{
"must":[
{
"range":{
"startDate":{
"lte":"2016-10-27T11:24:49.6616538+05:30"
}
}
}
],
"filter":[
{
"bool":{
"must_not":[
{
"exists":{
"field":"endDate"
}
}
]
}
}
]
}
}
]
}
}
]
}
}
Well first off, that error is generally from use on a 1.x version of Elasticsearch. (in that case you need a FilteredQuery)
Next it appears you have many levels of unnecessary nesting. Not sure if maybe you stripped other things out to make a simpler example. I have rewritten your query like this (and added the outer braces):
{
"query" : {
"bool" : {
"must" : [{
"range" : {
"startDate" : { "lte" : "2016-10-27T11:24:49.6616538+05:30" }
}
}
],
"filter" : [{
"bool" : {
"must_not" : [{
"exists" : { "field" : "endDate" }
}
]
}
}
]} }
}
Both your original query and my rewritten one work fine on my server (v2.3.1) so I'm guessing really you have ES 1.x ?
Also, if you are not leveraging the lucene scoring, and just want to return the documents (or apply your own sort) then you can drop the filter altogether and simplify it further:
{
"query" : {
"bool" : {
"must" : [{
"range" : {
"startDate" : { "lte" : "2016-10-27T11:24:49.6616538+05:30"}
}
}
],
"must_not" : [{
"exists" : { "field" : "endDate" }
}
]} }
}
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