Find all documents with a missing field (“index”: false, “store”: true)

ElasticSearch version: 6.8.2

Index metadata fragment:

    {
      "my_index": {
        "mappings": {
            "type": {
                "properties": {
                    "my_field": {
                        "type": "text",
                        "index": false,
                        "store": true
                    },

I want to find all documents in the index, where:

  • "my_field" is absent OR
  • "my_field" is present, field value is null OR
  • "my_field" is present, field value is an empty array

I would use "exists" query (Exists query | Elasticsearch Reference [7.10] | Elastic) for my purpose, but, as far as I understand, it only works with the indexed fields. In my case, it always returns all the documents.

How can I find all documents in this case, by the criteria defined above?

You can use the Script Query | Elasticsearch Reference [6.8] | Elastic. This query won't run very quickly though.

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