# Problems with unmapped nested type in sort

**URL:** <https://discuss.elastic.co/t/problems-with-unmapped-nested-type-in-sort/147813>\
**Category:** Elasticsearch\
**Created:** [September 8, 2018, 12:29pm UTC](https://discuss.elastic.co/t/problems-with-unmapped-nested-type-in-sort/147813 "2018-09-08T12:29:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Majo](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@Majo](https://discuss.elastic.co/u/Majo)\
**Post date:** [September 8, 2018, 12:29pm UTC](https://discuss.elastic.co/t/problems-with-unmapped-nested-type-in-sort/147813/1 "2018-09-08T12:29:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 6, 2018, 12:29pm UTC](https://discuss.elastic.co/t/problems-with-unmapped-nested-type-in-sort/147813/2 "2018-10-06T12:29:18Z")

</div>

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