Problems with unmapped nested type in sort

Hi,

I have more elasticsearch indices, some of them have mapped nested field and the other not.
Example of an index with nested field:

PUT index-nested 
{
  "mappings": {
    "doc": {
      "properties": {
        "notNestedField": {
          "type": "keyword"
        },
        "Nested": {
          "type": "nested",
          "properties": {
            "nestedField": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}

And an index without nested field:

PUT index-not-nested
{
  "mappings": {
    "doc": {
      "properties": {
        "notNestedField": {
          "type": "keyword"
        }
      }
    }
  }
}

In my case I need to query over all the indices (with and without nested type) and sort the results by the type under nested object. According a documentation, It can be done in such a way:

GET index-nested,index-not-nested/_search
{
  "sort": [
    {
      "Nested.nestedField": {
        "unmapped_type" : "keyword",
        "nested": {
          "path": "Nested"
        }, 
        "order": "desc"
      }
    }
  ]
}

Despite unmapped flag, all shards belonging to indices without nested field are failing.

...
"failures": [
      {
        "shard": 0,
        "index": "index-not-nested",
        "node": "w8_R6Fg8TLGsKq7zCRAXKg",
        "reason": {
          "type": "query_shard_exception",
          "reason": "[nested] failed to find nested object under path [Nested]",
          "index_uuid": "1D0UTBwaRHmnG2TC6PJZdg",
          "index": "index-not-nested"
        }
      }
    ]
...

The behavior I supposed is to sort the data without nested field by default value of the type keyword (empty string) as is stated by unmapped_type in the query.

My question is, whether the current behavior is bug and is planned to fix it in further releases. If not, exists other way how to achieve this behavior?

Thanks,
Marian

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