# 3.5.6.Joining 查询（连接查询）

在像 ElasticSearch 这样的分布式系统中执行全 SQL 风格的连接查询代价昂贵，是不可行的。相应地，为了实现水平规模地扩展，ElasticSearch 提供了两种形式的 join。

[**nested query (嵌套查询)**](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-nested-query.html)

文档中可能包含嵌套类型的字段，这些字段用来索引一些数组对象，每个对象都可以作为一条独立的文档被查询出来(用嵌套查询)

[**has\_child**](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-has-child-query.html) **(有子查询) 和** [**has\_parent**](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-has-parent-query.html) **(有父查询)**&#x20;

一类父子关系可以存在单个的索引的两个类型的文档之间。has\_child 查询将返回其子文档能满足特定的查询的父文档，而 has\_parent 则返回其父文档能满足特定查询的子文档

参考 term 查询中的[terms-lookup mechanism ](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/query-dsl-terms-query.html#query-dsl-terms-lookup)，它允许你在另一个文档的值中创建一个term 查询。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/35query-dsldslfang-shi-cha-8be229/356joining-cha-xun-ff08-lian-jie-cha-xun-ff09.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
