0

Suppose we have the following filtering: field > 0 AND field != value

I am a bit mixed up on the many ways that elasticsearch has to express that filter using the bool query.Consider the following queries:

Query one

"bool":{
    "must_not":{
        "term":{
            "field": value        
        }    
    },
    "must":{
        "range":{
            "field":{
                "gt":0
            }
        }
    }

}

Query 2:

"bool":{
    "must_not":{
        "term":{
            "field": value        
        }    
    },
    "filter":{
        "range":{
            "field":{
                "gt":0
            }
        }
    }

}

Query 3

"bool":{
    "must":{
        "bool":{
            "must":{
                "range":{
                    "field":{
                        "gte":value
                    }
                }
            },
            "must_not":{
                "field":value
            }
        }
    }        
}

Do query 1 and 2 mean the same thing? Also although I have seen many examples in the form of the query 3 (bool query inside a must|should|must_not clause), it produces an error when validating the query:

org.elasticsearch.index.query.QueryParsingException: [_na] query malformed, no field after start_object'}

What does this error mean? How is the correct form? And why so many ways to filter results?

3
  • In query 3 in you have "must_not":{ "field":value }. Are you missing term query there or what? Commented Oct 7, 2016 at 9:45
  • You are right...Didn't see that!!! So it validated true, but what is the difference between those three queries? Is there one? Why so many ways? Commented Oct 7, 2016 at 9:51
  • Possible duplicate of Difference between Elasticsearch Range Query and Range Filter Commented Oct 7, 2016 at 9:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.