Sandy
Sandy

Reputation: 107

Is there any way to retrive children doc with the query on parent document in elasticsearch?

I have a parent doc u1 contain {userId:1} with routing u1r1 and I have 3 children related to this doc u1 ie o1u1,o2u1,o3u1.

o1u1 contain {city:a},
o2u1 contain {city:b},
o3u1 contain {city:a}

I want both userId with two document contain {city:a}.

Upvotes: 0

Views: 26

Answers (1)

Richa
Richa

Reputation: 7649

You can use inner_hits if you want child documents along with parent documents.

{
"query": {
  "has_child": {
     "type": "child",
     "query": {
        "query_string": {
           "default_field": "city",
           "query": "a"
        }
     },
     "inner_hits": {}
     }
   }
}

Study about inner_hits here

Upvotes: 1

Related Questions