WARNING: The 2.x versions of Elasticsearch have passed their EOL dates. If you are running a 2.x version, we strongly advise you to upgrade.
This documentation is no longer maintained and may be removed. For the latest information, see the current Elasticsearch documentation.
Parent-Child Mappingedit
All that is needed in order to establish the parent-child relationship is to
specify which document type should be the parent of a child type. This must
be done at index creation time, or with the update-mapping
API before the
child type has been created.
As an example, let’s say that we have a company that has branches in many cities. We would like to associate employees with the branch where they work. We need to be able to search for branches, individual employees, and employees who work for particular branches, so the nested model will not help. We could, of course, use application-side-joins or data denormalization here instead, but for demonstration purposes we will use parent-child.
All that we have to do is to tell Elasticsearch that the employee
type has
the branch
document type as its _parent
, which we can do when we create
the index: