Skip to content

inner_hits does not work for nested filters when searching multiple indices #29071

@gognjanovski

Description

@gognjanovski

Elasticsearch version
Version: 6.2.2, Build: 10b1edd/2018-02-16T19:01:30.685723Z, JVM: 1.8.0_73

I'm trying to search multiple indices which both have nested objects. To keep it simple I will use this example. In the query I use "inner_hits" property.

PUT /sales
{
    "mappings": {
        "_doc" : {
            "properties" : {
                "tags" : { "type" : "keyword" },
                "comments" : { 
                    "type" : "nested",
                    "properties" : {
                        "username" : { "type" : "keyword" },
                        "comment" : { "type" : "text" }
                    }
                }
            }
        }
    }
}

PUT /sales/_doc/1?refresh
{
    "tags": ["car", "auto"],
    "comments": [
        {"username": "baddriver007", "comment": "This car could have better brakes"},
        {"username": "dr_who", "comment": "Where's the autopilot? Can't find it"},
        {"username": "ilovemotorbikes", "comment": "This car has two extra wheels"}
    ]
}

PUT /markets
{
    "mappings": {
        "_doc" : {
            "properties" : {
                "name" : { "type" : "keyword" },
                "products" : { 
                    "type" : "nested",
                    "properties" : {
                        "name" : { "type" : "keyword" },
                        "sku" : { "type" : "text" }
                    }
                }
            }
        }
    }
}

POST /sales,markets/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "should": [
              {
                "nested": {
                  "path": "comments",
                  "inner_hits": {
                    
                  },
                  "ignore_unmapped": true,
                  "query": {
                    "match_all": {}
                  }
                }   
              }]
          }
        },
        {
          "bool": {
            "should": [
              {
                "nested": {
                  "path": "products",
                  "inner_hits": {
                    
                  },
                  "ignore_unmapped": true,
                  "query": {
                    "match_all": {}
                  }
                }
              }
            ]
          }
        }
      ]
    }
  }
}

So this query gives an error

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_state_exception",
        "reason": "[match_all] no mapping found for type [comments]"
      },
      {
        "type": "illegal_state_exception",
        "reason": "[match_all] no mapping found for type [products]"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "markets",
        "node": "-22psoQNRLa8_Y9GeHBXaw",
        "reason": {
          "type": "illegal_state_exception",
          "reason": "[match_all] no mapping found for type [comments]"
        }
      },
      {
        "shard": 0,
        "index": "sales",
        "node": "-22psoQNRLa8_Y9GeHBXaw",
        "reason": {
          "type": "illegal_state_exception",
          "reason": "[match_all] no mapping found for type [products]"
        }
      }
    ]
  },
  "status": 500
}

But when I add "ignore_unmapped": true inside each "inner_hits": { "ignore_unmapped": true } everything works fine. This is not implemented in NEST .net library so I wanted to be sure before I open an issue there.

Is it right to use "ignore_unmapped" inside "inner_hits", because I didn't find this as "inner_hits" property in the documentation ?

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions