原文地址: https://www.elastic.co/guide/en/elasticsearch/reference/7.7/joining-queries.html, 原文档版权归 www.elastic.co 所有
IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Joining queriesedit
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.
-
nested
query -
Documents may contain fields of type
nested
. These fields are used to index arrays of objects, where each object can be queried (with thenested
query) as an independent document. -
has_child
andhas_parent
queries -
A
join
field relationship can exist between documents within a single index. Thehas_child
query returns parent documents whose child documents match the specified query, while thehas_parent
query 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.