本地英文版地址: ../en/search-aggregations-matrix-stats-aggregation.html
matrix_stats聚合是一种数值聚合,它对一组文档字段计算以下统计信息:
|
|
计算中包含的每字段样本数。 |
|
|
每个字段的平均值。 |
|
|
(方差,离散)每个字段的测量对样本平均值的分布情况。 (原文: Per field Measurement for how spread out the samples are from the mean. |
|
|
(偏度)每个字段的测量量化平均值周围的不对称分布。 |
|
|
(峰态)对分布形状进行量化的字段测量。 (原文: Per field measurement quantifying the shape of the distribution. |
|
|
(协方差)定量描述一个领域中的变化如何与另一个领域相关联的矩阵。 |
|
|
协方差(covariance)矩阵限定在-1到1(包括-1和1)范围内。 描述字段分布之间的关系。 |
下面的例子演示了如何使用矩阵统计来描述收入和贫困之间的关系。
GET /_search
{
"aggs": {
"statistics": {
"matrix_stats": {
"fields": ["poverty", "income"]
}
}
}
}
聚合类型是matrix_stats,fields设置定义了用于计算统计数据的一组字段(数组格式)。
上述请求返回以下响应:
{
...
"aggregations": {
"statistics": {
"doc_count": 50,
"fields": [{
"name": "income",
"count": 50,
"mean": 51985.1,
"variance": 7.383377037755103E7,
"skewness": 0.5595114003506483,
"kurtosis": 2.5692365287787124,
"covariance": {
"income": 7.383377037755103E7,
"poverty": -21093.65836734694
},
"correlation": {
"income": 1.0,
"poverty": -0.8352655256272504
}
}, {
"name": "poverty",
"count": 50,
"mean": 12.732000000000001,
"variance": 8.637730612244896,
"skewness": 0.4516049811903419,
"kurtosis": 2.8615929677997767,
"covariance": {
"income": -21093.65836734694,
"poverty": 8.637730612244896
},
"correlation": {
"income": -0.8352655256272504,
"poverty": 1.0
}
}]
}
}
}
doc_count字段指示统计计算中涉及的文档数量。
matrix_stats聚合将每个文档字段视为一个独立的样本。
参数mode控制聚合将对数组或多值字段使用什么数组值。
该参数的值可以是下列之一:
|
|
(默认) 使用所有值的平均值。 |
|
|
选择最低值。 |
|
|
选择最高值。 |
|
|
使用所有值的总和。 |
|
|
使用所有值的中位数。 |