What is the parent-child relationship (join field) in Elasticsearch?
Answer
The join field allows you to define parent-child relationships between documents within the same index, enabling queries that span related document types. Unlike nested documents (which are separate hidden Lucene docs), parent and child documents are separate, individually updateable documents. A has_child query returns parent documents that have matching children, and a has_parent query returns children whose parent matches. The critical constraint is that parent and child documents must be on the same shard — enforce this by including the parent ID as the routing value when indexing children. Parent-child is useful for one-to-many relationships where children are updated frequently (e.g., a product catalog with frequently updated stock levels).
Previous
What field data types does Elasticsearch support?
Next
What is the multi-search (msearch) API in Elasticsearch?
More Elasticsearch Questions
View all →- Intermediate What is the difference between query context and filter context in Elasticsearch?
- Intermediate What is a bool query in Elasticsearch?
- Intermediate What are aggregations in Elasticsearch?
- Intermediate What is the difference between text and keyword field types?
- Intermediate What are index templates and component templates in Elasticsearch?