Exists query problem

Hello friends, I need your help on a subject. There is a field with a nested type in an index and another field with a string type in this field. Any record has this field, but I would be very happy if you could help me to get count 0 when I query with exists.When I try it for any other nested field it works but not for one.

my index mapping:

 "MyFieldName1" : {
          "type" : "nested",
          "properties" : {
            "MyFieldName2" : {
              "type" : "keyword"
            },
            "MyFieldName3" : {
              "type" : "float"
            }
          }
        },

My exists query:

GET myindexname/_count
{
  "query": {
    "nested": {
      "path": "MyFieldName1",
      "query": {
        "exists": {
          "field": "MyFieldName1.MyFieldName2"
        }
      }
    }
  }
}

Result:
{
  "count" : 0,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}

but I'm sure there is a document with this field. Any ideas would be very helpful, thanks in advance.:hugs:

I suppose there is typo or somet trivial error.
Your problem was not reproduced in my environment 7.16.3.

PUT test_nested
{
  "mappings": {
    "properties": {
      "MyFieldName1" : {
        "type" : "nested",
        "properties" : {
          "MyFieldName2" : {
            "type" : "keyword"
          },
          "MyFieldName3" : {
            "type" : "float"
          }
        }
      }
    }
  }
}

POST test_nested/_doc
{
  "MyFieldName1":{
    "MyFieldName2": "foo",
    "MyFieldName3": 1.5
  }
}

GET test_nested/_search

GET test_nested/_count
{
  "query": {
    "nested": {
      "path": "MyFieldName1",
      "query": {
        "exists": {
          "field": "MyFieldName1.MyFieldName2"
        }
      }
    }
  }
}
{
  "count" : 1,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}

The count was 1.

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