Reputation: 910
Lets say I am putting documents in elastic search as following:
{
"name": "xyz",
"address": {
"pincode": "111111",
"area": "downtown"
}
}
I want to get all the documents which have pincode
in them. Ofcourse, some documents entered in ES might not have pincode
field.
I tried with something like this, but was unsuccessful:
XGET _search
{
"query": {
"terms": {
"_field_names": [ "pincode" ]
}
}
}
Upvotes: 0
Views: 840
Reputation: 217254
You need to use the missing
filter. The exists
filter will not work if the field is missing altogether in your document.
{
"query": {
"filtered": {
"filter": {
"bool": {
"must_not": [
{
"missing": {
"field": "address.pincode"
}
}
]
}
}
}
}
}
Upvotes: 1