Nested query mixed with parent query

Hi
I'm trying to do a nested query in combination with query on fields in the parent. But how do I figure out if a match hits the parent field in the same time as I get an inner hit?

Best regards
Jens Christiansen

You could use a bool query with a must clause that has two queries: the nested query and the query on the parent field. Only documents that match both queries will be returned as a hit.

GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "path_to_nested_doc",
            "query": { YOUR_NESTED_QUERY }
          }
        },
        {
          YOUR_QUERY_ON_THE_PARENT_FIELD
        }
      ]
    }
  }
}
1 Like

Dear Abdon
Great :slight_smile:

Thanks for your solution and nice to hear from you again.

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