Leibale Eidelman
Leibale Eidelman

Reputation: 3194

Search for null and values (but not for non exists) in elasticsearch

I have three documents, first: I have an empty images object, second: I have a null in images.front, and third: I have object in images.front.

As follows:

[{
  "images": {}
}, {
  "images": {
    "front": null
  }
}, { 
  "images": {
    "front": {
      "id": 1
    }
  }
}]

How can I search only for the documents that have front image (documents two and three, but not first)?

Many thanks :)

Upvotes: 3

Views: 876

Answers (1)

user3775217
user3775217

Reputation: 4803

As far i know(i worked only till 1.7.2), document 1 and 2 will have same json structure in _source document of the elastic.As elasticsearch doesn't support null values.

So if you want to search for documents which have images , do a exists filters in the must bool filter.

elastic null values

Exists filter in elasticsearch

Upvotes: 1

Related Questions