Handling Null Values

Take a look at building a bool query with two should clauses. You can use a bool query as one of the should clauses in order to invert an exists query using a must_not clause

{
  "query": {
    "bool" : {
      "should" : [
        { "bool" : { 
            "must_not" : [
              { "exists": { "field" : "brand_name" } } 
            ] 
          } 
        },
        { "term" : { "brand_name" : "some brand name" } }
      ]
    }
  }
}
1 Like