ElasticSearch 学习笔记 - 10.指标聚合
1、基础数据
GET /my-index/_search { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 1, "hits": [ { "_index": "my-index", "_type": "person", "_id": "5", "_score": 1, "_source": { "name": "kobe", "age": 28, "salary": 10000 } }, { "_index": "my-index", "_type": "person", "_id": "6", "_score": 1, "_source": { "name": "hadron", "age": 19, "salary": 5000 } } ] } }
2、max
GET /my-index/_search { "size": 1, "aggs": { "max_age": { "max": { "field": "age" } } } } { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 1, "hits": [ { "_index": "my-index", "_type": "person", "_id": "5", "_score": 1, "_source": { "name": "kobe", "age": 28, "salary": 10000 } } ] }, "aggregations": { "max_age": { "value": 28 } } }
3、min
GET /my-index/_search { "size": 2, "aggs": { "min_age": { "min": { "field": "age" } } } }
4、avg
GET /my-index/_search { "size": 2, "aggs": { "avg_age": { "avg": { "field": "age" } } } }
5、sum
GET /my-index/_search { "size": 20, "aggs": { "sum_salary": { "sum": { "field": "salary" } } } }
6、 stat
GET my-index/_search { "size": 0, "aggs": { "stats_salary": { "stats": {"field": "salary"} } } } { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 0, "hits": [] }, "aggregations": { "stats_salary": { "count": 2, "min": 5000, "max": 10000, "avg": 7500, "sum": 15000 } } }
7、高级统计
GET my-index/_search { "size": 0, "aggs": { "stats_salary": { "extended_stats": {"field": "salary"} } } } { "took": 0, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 2, "max_score": 0, "hits": [] }, "aggregations": { "stats_salary": { "count": 2, "min": 5000, "max": 10000, "avg": 7500, "sum": 15000, "sum_of_squares": 125000000, "variance": 6250000, "std_deviation": 2500, "std_deviation_bounds": { "upper": 12500, "lower": 2500 } } } }
8、文档数量统计
GET my-index/_search { "size": 0, "aggs": { "doc_count": { "value_count": {"field": "salary"} } } } { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 3, "max_score": 0, "hits": [] }, "aggregations": { "doc_count": { "value": 2 } } }
9、百分位统计
GET my-index/_search { "size": 0, "aggs": { "persion_salary": { "percentiles": {"field": "salary"} } } } { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 3, "max_score": 0, "hits": [] }, "aggregations": { "persion_salary": { "values": { "1.0": 5000, "5.0": 5000, "25.0": 5000, "50.0": 7500, "75.0": 10000, "95.0": 10000, "99.0": 10000 } } } }
相关推荐
newbornzhao 2020-09-14
做对一件事很重要 2020-09-07
renjinlong 2020-09-03
明瞳 2020-08-19
李玉志 2020-08-19
mengyue 2020-08-07
molong0 2020-08-06
AFei00 2020-08-03
molong0 2020-08-03
wenwentana 2020-08-03
YYDU 2020-08-03
另外一部分,则需要先做聚类、分类处理,将聚合出的分类结果存入ES集群的聚类索引中。数据处理层的聚合结果存入ES中的指定索引,同时将每个聚合主题相关的数据存入每个document下面的某个field下。
sifeimeng 2020-08-03
心丨悦 2020-08-03
liangwenrong 2020-07-31
sifeimeng 2020-08-01
mengyue 2020-07-30
tigercn 2020-07-29
IceStreamLab 2020-07-29