Get both parent and child document


(Toujou Aya) #1

Is it possible to return both parent data and child with an Elasticsearch query?
Example :

PUT my_index/posts/_search { { "query": { "has_child": {"type": "comments"}}}}

It will return only posts data. How can I get the comments data too?


(Martijn Van Groningen) #2

You can use inner hits for this:

{
   "query" : {
       "has_child" : {
          "type" "comments",
          "inner_hits" : {}
      }
}

This will include per post hit the top 3 matching comment hits.


(system) #3

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