2015-06-03 19:59:22 -04:00
|
|
|
[[joining-queries]]
|
|
|
|
== 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.
|
|
|
|
|
|
|
|
<<query-dsl-nested-query,`nested` query>>::
|
2016-10-05 08:54:32 -04:00
|
|
|
Documents may contain fields of type <<nested,`nested`>>. These
|
2015-06-03 19:59:22 -04:00
|
|
|
fields are used to index arrays of objects, where each object can be queried
|
|
|
|
(with the `nested` query) as an independent document.
|
|
|
|
|
|
|
|
<<query-dsl-has-child-query,`has_child`>> and <<query-dsl-has-parent-query,`has_parent`>> queries::
|
2017-07-05 06:30:19 -04:00
|
|
|
A <<parent-join,`join` field relationship>> can exist between
|
|
|
|
documents within a single index. The `has_child` query returns parent
|
2015-06-03 19:59:22 -04:00
|
|
|
documents whose child documents match the specified query, while the
|
|
|
|
`has_parent` query returns child documents whose parent document matches the
|
|
|
|
specified query.
|
|
|
|
|
|
|
|
Also see the <<query-dsl-terms-lookup,terms-lookup mechanism>> in the `terms`
|
|
|
|
query, which allows you to build a `terms` query from values contained in
|
|
|
|
another document.
|
|
|
|
|
2020-08-12 14:01:10 -04:00
|
|
|
[discrete]
|
|
|
|
[[joining-queries-notes]]
|
|
|
|
==== Notes
|
|
|
|
|
|
|
|
[discrete]
|
|
|
|
===== Allow expensive queries
|
|
|
|
Joining queries will not be executed if <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>>
|
|
|
|
is set to false.
|
|
|
|
|
2015-06-03 19:59:22 -04:00
|
|
|
include::nested-query.asciidoc[]
|
|
|
|
|
|
|
|
include::has-child-query.asciidoc[]
|
|
|
|
|
|
|
|
include::has-parent-query.asciidoc[]
|
|
|
|
|
2016-01-17 16:49:07 -05:00
|
|
|
include::parent-id-query.asciidoc[]
|
|
|
|
|
2020-08-12 14:01:10 -04:00
|
|
|
|