Skip to content

Inner_hits in should clauses override each other #37584

Closed
@imotov

Description

@imotov

This issues is somewhat similar to #16218, but it manifests itself if two should clauses contain has_child with inner_hits and different queries and only one of the query in the last clause doesn't matches the document returned by the first clause.

This is a repro for 6.x

DELETE test
PUT test
{
  "mappings": {
    "_doc": {
      "properties": {
        "my_join_field": {
          "type": "join",
          "relations": {
            "question": "answer"
          }
        },
        "text": {
          "type": "text"
        }
      }
    }
  }
}

POST test/_doc/_bulk
{"index":{"_id": "1"}}
{"text": "This is a question","my_join_field": {"name": "question"}}
{"index":{"_id": "2"}}
{"text": "This is another question","my_join_field": {"name": "question"}}
{"index":{"_id": "3", "_routing": "1"}}
{"text": "This is an answer", "my_join_field": {"name": "answer","parent":"1"}}
{"index":{"_id": "4", "_routing": "1"}}
{"text": "This is another answer", "my_join_field": {"name": "answer","parent":"1"}}

POST test/_search

# Doesn't return inner hits
POST test/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "has_child": {
            "type": "answer",
            "query": {
              "match": {
                "text": "answer"
              }
            },
            "inner_hits": {}
          }
        },
        {
          "has_child": {
            "type": "answer",
            "query": {
              "match": {
                "text": "noanswer"
              }
            },
            "inner_hits": {}
          }
        }
      ]
    }
  }
}

# Returns inner hits:
POST test/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "has_child": {
            "type": "answer",
            "query": {
              "match": {
                "text": "noanswer"
              }
            },
            "inner_hits": {}
          }
        },
        {
          "has_child": {
            "type": "answer",
            "query": {
              "match": {
                "text": "answer"
              }
            },
            "inner_hits": {}
          }
        }
      ]
    }
  }
}

Repro for 7.x can be found here

Originally reported in https://discuss.elastic.co/t/inner-hits-has-child/164627/10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions