Joining queries
Performing full SQL-style joins in a distributed system like Elasticsearch is prohibitively expensive. Instead, Elasticsearch offers two forms of join which are designed to scale horizontally.
-
nestedquery - Documents may contain fields of type
nested. These fields are used to index arrays of objects, where each object can be queried (with thenestedquery) as an independent document. -
has_childandhas_parentqueries - A
joinfield relationship can exist between documents within a single index. Thehas_childquery returns parent documents whose child documents match the specified query, while thehas_parentquery returns child documents whose parent document matches the specified query.
Also see the terms-lookup mechanism in the terms query, which allows you to build a terms query from values contained in another document.
Notes
Allow expensive queries
Joining queries will not be executed if search.allow_expensive_queries is set to false.
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/joining-queries.html