# 邻接矩阵聚合(Adjacency Matrix Aggregation)

一个返回[邻接矩阵](https://en.wikipedia.org/wiki/Adjacency_matrix)形式的桶聚合，该请求提供一个名为filter表达式的集合，类似于filters聚合请求，响应中的每个桶表示交叉滤波器矩阵中的非空单元格。

> adjacency\_matrix聚合是一个新功能，我们可能会随着我们获得有关其使用的反馈而发展设计。 因此，此功能的API可能以非向后兼容的方式更改

给定名为A，B和C的过滤器，响应将返回具有以下名称的buckets（桶）：

|   | A | B    | C    |
| - | - | ---- | ---- |
| A | A | A\&B | A\&C |
| B |   | B    | B\&C |
| C |   |      | C    |

使用由和号字符分隔的两个过滤器名称的组合来标记相交的桶例如A和C。 请注意，响应也不包括“C＆A”桶，因为这将与“A＆C”相同的一组文档。 矩阵被称为对称的，所以我们只返回一半。 为此，我们对过滤器名称字符串进行排序，并始终使用最低的一对作为“＆”分隔符左侧的值。

如果客户端希望使用除＆符号的默认值以外的分隔符字符串，则可以在请求中传递替代分隔符参数。

例如：

```
PUT /emails/message/_bulk?refresh
{ "index" : { "_id" : 1 } }
{ "accounts" : ["hillary", "sidney"]}
{ "index" : { "_id" : 2 } }
{ "accounts" : ["hillary", "donald"]}
{ "index" : { "_id" : 3 } }
{ "accounts" : ["vladimir", "donald"]}

GET emails/message/_search
{
  "size": 0,
  "aggs" : {
    "interactions" : {
      "adjacency_matrix" : {
        "filters" : {
          "grpA" : { "terms" : { "accounts" : ["hillary", "sidney"] }},
          "grpB" : { "terms" : { "accounts" : ["donald", "mitt"] }},
          "grpC" : { "terms" : { "accounts" : ["vladimir", "nigel"] }}
        }
      }
    }
  }
}
```

在上面的例子中，我们分析电子邮件，以查看哪些人已经交换了消息。 我们将分别获取每个组的计数，并且还记录已记录交互的组对的消息计数。

响应：

```
{
  "took": 9,
  "timed_out": false,
  "_shards": ...,
  "hits": ...,
  "aggregations": {
    "interactions": {
      "buckets": [
        {
          "key":"grpA",
          "doc_count": 2
        },
        {
          "key":"grpA&grpB",
          "doc_count": 1
        },
        {
          "key":"grpB",
          "doc_count": 2
        },
        {
          "key":"grpB&grpC",
          "doc_count": 1
        },
        {
          "key":"grpC",
          "doc_count": 1
        }
      ]
    }
  }
}
```

## 用法

自己可以提供创建无向加权图所需的所有数据。 然而，当与诸如date\_histogram的子集合一起使用时，结果可以提供执行[dynamic network analysis](https://en.wikipedia.org/wiki/Dynamic_network_analysis)（动态网络分析）所需的附加级别的数据，其中随着时间的推移，检查交互变得重要。

## 局限性

N过滤桶的矩阵可以产生N²/ 2，因此默认最大值为100个过滤器。可以使用index.max\_adjacency\_matrix\_filters索引级别设置更改此设置


---

# 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/36aggregationsju-he-fen-679029/362tong-ju540828-bucketaggregations/adjacency-matrix-aggregation.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.
