Search for records with both 'match' or does not 'exists'?

(Jeffrey) #1

I have a use case where I need to find records where a field is both missing or contains a specific value. Anyone have any idea how to do this? I can use the must_not with exists to find the fields that are missing and I can use the should with match to find the records with the value I am looking for. I cannot figure out how to combine these into a single query.

In the sample below, I want to find records with a 'lastname' of 'Smith' or where the last name is missing.
In other words, I want to return both records 1 and 3.

Sample records:
PUT /my_index/my_name/1
"firstname": "John",
"lastname": "Smith"

PUT /my_index/my_name/2
"firstname": "Jane",
"lastname": "Brown"

PUT /my_index/my_name/3
"firstname": "Joe"

(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.