Skip to main content

邻接矩阵聚合 adjacency_matrix

Adjacency Matrix Aggregation

一个返回邻接矩阵形式的桶聚合,该请求提供一个名为filter表达式的集合,类似于filters聚合请求,响应中的每个桶表示交叉滤波器矩阵中的非空单元格。

给定名为A、B和C的filters,响应将返回具有以下名称的桶:

ABC
AAA&BA&C
BBB&C
CC

使用由&号字符分隔的两个过滤器名称的组合来标记相交的桶例如A&C。

如果客户端希望使用除&符号(默认值)的以外的分隔符字符串,则可以在请求中传递separator替换。

例子

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

GET emails/_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)一起使用时,结果可以提供执行动态网络分析所需的额外级别的数据,在动态网络分析中,随着时间的推移检查交互变得重要。

局限性

对于N个过滤器,生成的桶矩阵可以是N²/2,因此默认最大值为100个过滤器。可以使用索引更改此设置。max_ajacency_matrix_filters索引级别设置。