ES extended_stats 函数
Posted fly-kaka
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ES extended_stats 函数相关的知识,希望对你有一定的参考价值。
在进行ES聚合分析的时候,发现了一个非常有用的函数,extended_stats,可以对聚合的结果进行更近一步的分析 ,常见的 count sum avg min max 等都可以一目了然
GET cars/transactions/_search
{
"size": 0,
"aggs": {
"makes": {
"terms": {
"field": "make",
"size": 10
},
"aggs": {
"stats": {
"extended_stats": {
"field": "price"
}
}
}
}
}
}
结果如下
1 {
2 "took": 87,
3 "timed_out": false,
4 "_shards": {
5 "total": 5,
6 "successful": 5,
7 "failed": 0
8 },
9 "hits": {
10 "total": 8,
11 "max_score": 0,
12 "hits": []
13 },
14 "aggregations": {
15 "makes": {
16 "doc_count_error_upper_bound": 0,
17 "sum_other_doc_count": 0,
18 "buckets": [
19 {
20 "key": "honda",
21 "doc_count": 3,
22 "stats": {
23 "count": 3,
24 "min": 10000,
25 "max": 20000,
26 "avg": 16666.666666666668,
27 "sum": 50000,
28 "sum_of_squares": 900000000,
29 "variance": 22222222.22222221,
30 "std_deviation": 4714.045207910315,
31 "std_deviation_bounds": {
32 "upper": 26094.757082487296,
33 "lower": 7238.5762508460375
34 }
35 }
36 },
37 {
38 "key": "ford",
39 "doc_count": 2,
40 "stats": {
41 "count": 2,
42 "min": 25000,
43 "max": 30000,
44 "avg": 27500,
45 "sum": 55000,
46 "sum_of_squares": 1525000000,
47 "variance": 6250000,
48 "std_deviation": 2500,
49 "std_deviation_bounds": {
50 "upper": 32500,
51 "lower": 22500
52 }
53 }
54 },
55 {
56 "key": "toyota",
57 "doc_count": 2,
58 "stats": {
59 "count": 2,
60 "min": 12000,
61 "max": 15000,
62 "avg": 13500,
63 "sum": 27000,
64 "sum_of_squares": 369000000,
65 "variance": 2250000,
66 "std_deviation": 1500,
67 "std_deviation_bounds": {
68 "upper": 16500,
69 "lower": 10500
70 }
71 }
72 },
73 {
74 "key": "bmw",
75 "doc_count": 1,
76 "stats": {
77 "count": 1,
78 "min": 80000,
79 "max": 80000,
80 "avg": 80000,
81 "sum": 80000,
82 "sum_of_squares": 6400000000,
83 "variance": 0,
84 "std_deviation": 0,
85 "std_deviation_bounds": {
86 "upper": 80000,
87 "lower": 80000
88 }
89 }
90 }
91 ]
92 }
93 }
94 }
以上是关于ES extended_stats 函数的主要内容,如果未能解决你的问题,请参考以下文章