Exists and missing queries

Exists query is used to find the document that contains a non-null value for the field specified in the query. For example, if you want to find all the document that contain product reviews. The query looks like the following:

 #Exists POST chapter6/product/_search {   "query": {     "exists" : {       "field" : "reviews"     }   } }

If you want to find all the products that don't contain reviews, we can use the bool must_not query to find the documents that don't contain the field. The query looks like the following:

 #Missing POST chapter6/product/_search {   "query": {     "bool": {       "must_not": {         "exists": {           "field": "reviews"         }       }     }   } }

Get Learning Elasticsearch now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.