Skip to content

Sorting by unmapped nested field #33644

@marian-margeta

Description

@marian-margeta

Elasticsearch version (bin/elasticsearch --version): 6.4.0

Plugins installed: []

JVM version (java -version): 1.8.0_171

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

Description of the problem including expected versus actual behavior:

Field unmapped_type in sort section inside query doesn't work properly in case of nested properties. If I query for the data sorted by non-existing (unmapped) nested field I get query_shard_exception. The behavior I expect is to sort the data without nested field by a default value of a type specified in unmapped_type field. It would be consistent with current behavior for non-nested fields.

Steps to reproduce:

Let's say I have 2 indices (One with nested field and one without):

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

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

The query for sorted data from both indices:

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

Only data from index-nested are returned, 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"
        }
      }
    ]
...

Metadata

Metadata

Assignees

Labels

:Search/SearchSearch-related issues that do not fall into other categories>bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions