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?

Apostolos
  • 7,763
  • 17
  • 80
  • 150
  • In query 3 in you have "must_not":{ "field":value }. Are you missing term query there or what? – Vova Bilyachat Oct 07 '16 at 09: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? – Apostolos Oct 07 '16 at 09:51
  • Possible duplicate of [Difference between Elasticsearch Range Query and Range Filter](http://stackoverflow.com/questions/24560746/difference-between-elasticsearch-range-query-and-range-filter) – DJanssens Oct 07 '16 at 09:59

0 Answers0