Skip to content

"exists" query in "nested" query never matches for fields without doc_values within nested fields #76362

@yrodiere

Description

@yrodiere

Elasticsearch version (bin/elasticsearch --version): 7.14.0 (docker)
Everything works on 7.13.4.

Plugins installed: []

JVM version (java -version): whatever comes with the docker container

OS version (uname -a if on a Unix-like system):

Linux yrodiere.redhat 5.13.6-200.fc34.x86_64 #1 SMP Wed Jul 28 15:31:21 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:

Given this mapping:

{
  "mappings": {
    "properties": {
      "mynested": {
        "type": "nested",
        "properties": {
          "mykeyword": {
            "type": "keyword",
            "doc_values": "false"
          }
        }
      }
    }
  }
}

The following search query will never match on ES 7.14.0, regardless of the content of the index:

{
  "query": {
    "nested": {
      "path": "mynested",
      "query": {
        "exists": {
          "field": "mynested.mykeyword"
        }
      }
    }
  }
}

It used to match on ES 7.13.4 (and many previous versions).

Enabling doc_values makes it match again. Removing the "nested" query around the "exists" query makes it match again.

Steps to reproduce:

curl -XPUT -H "Content-Type: application/json" 'localhost:9200/test/' -d'{"mappings": {"properties": {"mynested": {"type": "nested", "properties": {"mykeyword": { "type": "keyword", "doc_values": "false" } } } } } }'
curl -XPUT -H "Content-Type: application/json" 'localhost:9200/test/_doc/1' -d '{"mynested": { "mykeyword" : "present" } }'
curl -XPOST -H "Content-Type: application/json" 'localhost:9200/test/_search' -d '{"query": { "nested": { "path": "mynested", "query": { "exists": { "field" : "mynested.mykeyword" } } } } }'

Results on 7.14.0:

{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  }
}

Results on 7.13.4:

{
  "took": 79,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "test",
        "_type": "_doc",
        "_id": "1",
        "_score": 1,
        "_source": {
          "mynested": {
            "mykeyword": "present"
          }
        }
      }
    ]
  }
}

Provide logs (if relevant): N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Search Foundations/MappingIndex mappings, including merging and defining field types>bugTeam:Search FoundationsMeta label for the Search Foundations team in Elasticsearch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions