June 2017
Beginner to intermediate
404 pages
8h 22m
English
We can use the has_parent to query child documents based on a query on the parent. For example, we want to find all the reviews written for a given product. The parent document is product, and the child document is product_review. The has_parent query is shown here:
#Has_Parent (Reviews for iphone) POST chapter7/product_review/_search { "query" : { "has_parent": { "parent_type": "product", "query": { "term": { "product_name": "iphone" } } } } }
The response will contain the product reviews for iphone. The response to the preceding query is as follows:
{ .... "hits": { "total": 1, "max_score": 1, "hits": [ { "_index": "chapter7", "_type": "product_review", "_id": "AVsMFvpeF21JdiUIl1RT", "_score": 1, "_routing": "1", ...Read now
Unlock full access