How does ElasticSearch index nested fields in which all values of said nested field are null?

12 Views Asked by At

I'm trying to run an exists query against a nested field in which all fields within that nested field are null.

Concretely, when fetching the document, the nested object within my top-level document is shaped similarly to this:

            "nestedObject": [
              {
                "fieldA": null,
                "fieldB": null,
                "fieldC": null,
                "fieldD": null
              }
            ]

When I form a query clause against this, a la:

                    {
                      "nested" : {
                        "query" : {
                          "exists" : {
                            "field" : "topLevelObject.nestedObject",
                            "boost" : 1.0
                          }
                        },
                        "path" : "topLevelObject.nestedObject",
                        "ignore_unmapped" : false,
                        "score_mode" : "avg",
                        "boost" : 1.0
                      }
                    }

I get no hits.

However, the moment I update the document to have a non-null value, such as:

            "nestedObject": [
              {
                "fieldA": "Something not null",
                "fieldB": null,
                "fieldC": null,
                "fieldD": null
              }
            ]

The same query does yield a hit. What confuses me is that at a glance, this seems like it's indexing a document for nestedObject, since generally if I do not provide a null-only object, it fetches during other queries as:

            "nestedObject": []
0

There are 0 best solutions below