Parent-Child Relationships
Elasticsearch contains the ability to establish parent-child relationships. This relationship maps closely to SQL JOIN functionality. The driver models these parent-child relationships in a way to enable the ability to perform JOIN queries.
Elasticsearch Versions 6 and Above:
In version 6 and above of Elasticsearch, relationships are established by using the join datatype. Included in this functionality is the ability to define multiple children for a single parent and to create multiple levels of relations.
The driver supports all of these relationships and will generate a separate table for each relation in Elasticsearch. The table name will be in the form: [index]_[relation].
All child tables will have an additional column containing the parent table id. The column name will be in the form: _[parent_table]_id. This column is a foreign key to the _id column of the parent table and can be used to perform SQL JOIN queries.
When querying these tables individually, filtering logic is pushed to the server to improve performance by only returning the data relevant to the table selected.
Elasticsearch Versions Prior to Version 6:
In versions prior to 6, a relationship is established between two types via a _parent field. This creates a single parent-child relationship.
The tables identified in this parent-child relationship do not change (they are still based on the Elasticsearch type). However the child table will have an additional column containing the parent id. The column name will be in the form: _[parent_table]_id. This column is a foreign key to the _id column of the parent table and can be used to perform SQL JOIN queries.