parent_id query

In the has_parent query example, we already knew the ID of the parent document. There is actually a handier query to get all children documents if we know the ID of the parent document.

You guessed correctly; it is the parent_id query, where we obtain all children using the parent's ID:

GET /amazon_products_with_features/_search
{
"query": {
"parent_id": {
"type": "feature",
"id": "c0001"
}
}
}

The response of this query will be exactly the same as the has_parent query we wrote earlier. The key difference between the has_parent query and the parent_id query is that the former is used to get all children based on an arbitrary Elasticsearch query executed against the parent_type query, whereas the latter (parent_id query) is useful if you know the ID.

Covering all types of queries is beyond the scope of this book. Having learned different types of full-text queries, compound queries, and relationship queries in depth, you are now well equipped to try other queries that aren't covered here. Please refer to the Elasticsearch reference documentation to learn about their usage.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.199.27