ElasticSearch 6.x 学习笔记:21.指标聚合
2019-03-13 08:33
417 查看
ElasticSearch 6.x 学习笔记:21.指标聚合
原文:https://www.geek-share.com/detail/2727345033.html
为了方便聚合统计,增加两条文档
PUT my-index/person/5 { "name":"程裕强", "age":28, "salary":10000 } PUT my-index/person/6 { "name":"hadron", "age":19, "salary":5000 }
GET my-index/_search { "size": 0, "aggs": { "max_age": { "max": {"field": "age"} } } }
{ "took": 4, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 6, "max_score": 0, "hits": [] }, "aggregations": { "max_age": { "value": 28 } } }
21.2 min
GET my-index/_search { "size": 0, "aggs": { "min_age": { "min": {"field": "age"} } } }
{ "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 6, "max_score": 0, "hits": [] }, "aggregations": { "min_age": { "value": 19 } } }
21.3 avg
GET my-index/_search { "size": 0, "aggs": { "avg_salary": { "avg": {"field": "salary"} } } }
{ "took": 7, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 6, "max_score": 0, "hits": [] }, "aggregations": { "avg_salary": { "value": 7166.666666666667 } } }
21.4 sum
GET my-index/_search { "size": 0, "aggs": { "sum_salary": { "sum": {"field": "salary"} } } }
{ "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 6, "max_score": 0, "hits": [] }, "aggregations": { "sum_salary": { "value": 43000 } } }
21.5 stats
GET my-index/_search { "size": 0, "aggs": { "stats_salary": { "stats": {"field": "salary"} } } }
{ "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 6, "max_score": 0, "hits": [] }, "aggregations": { "stats_salary": { "count": 6, "min": 5000, "max": 10000, "avg": 7166.666666666667, "sum": 43000 } } }
21.6 高级统计
GET my-index/_search { "size": 0, "aggs": { "stats_salary": { "extended_stats": {"field": "salary"} } } }
{ "took": 4, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 6, "max_score": 0, "hits": [] }, "aggregations": { "stats_salary": { "count": 6, "min": 5000, "max": 10000, "avg": 7166.666666666667, "sum": 43000, "sum_of_squares": 325000000, "variance": 2805555.5555555522, "std_deviation": 1674.9792701868141, "std_deviation_bounds": { "upper": 10516.625207040295, "lower": 3816.7081262930387 } } } }
21.7 基数统计
工资基数(等级)
GET my-index/_search { "size": 0, "aggs": { "class_salary": { "cardinality": {"field": "salary"} } } }
{ "took": 44, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 6, "max_score": 0, "hits": [] }, "aggregations": { "class_salary": { "value": 4 } } }
21.8 文档数量统计
为了方便统计某一个字段(比如salary)的文档数,这里添加一个不含该字段的文档
PUT my-index/persion/7 { "name":"test", "age":26 }
GET my-index/_search { "size": 0, "aggs": { "doc_count": { "value_count": {"field": "salary"} } } }
{ "took": 10, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 7, "max_score": 0, "hits": [] }, "aggregations": { "doc_count": { "value": 6 } } }
21.9 百分位统计
GET my-index/_search { "size": 0, "aggs": { "persion_salary": { "percentiles": {"field": "salary"} } } }
{ "took": 19, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 7, "max_score": 0, "hits": [] }, "aggregations": { "persion_salary": { "values": { "1.0": 5050, "5.0": 5250, "25.0": 6000, "50.0": 7000, "75.0": 8000, "95.0": 9500, "99.0": 9900 } } } }
相关文章推荐
- ElasticSearch 6.x 学习笔记:21.指标聚合
- ElasticSearch 6.x 学习笔记:33.Java API之指标聚合
- ElasticSearch 6.x 学习笔记:34.Java API之桶聚合
- ElasticSearch 6.x 学习笔记:22.桶聚合
- ElasticSearch学习笔记之二十一 指标聚合
- ElasticSearch 6.x 学习笔记:25.Java API之索引管理
- ElasticSearch 6.x 学习笔记:37.新闻搜索之页面设计
- ElasticSearch 6.x 学习笔记:24.Java API连接Elasticsearch
- ElasticSearch 6.x 学习笔记:15.检索入门
- ElasticSearch 6.x 学习笔记:16.全文检索
- ElasticSearch 6.x 学习笔记:36.新闻搜索之Maven项目创建
- ElasticSearch 6.x 学习笔记:18.复合查询
- ElasticSearch学习笔记之二十 聚合
- ElasticSearch 6.x 学习笔记:3.Kibana插件
- ElasticSearch 6.x 学习笔记:20.搜索排序
- ElasticSearch 6.x 学习笔记:9.版本控制
- Elasticsearch学习笔记2----聚合操作及常见问题解决
- ElasticSearch 6.x 学习笔记:13.mapping元字段
- ElasticSearch 6.x 学习笔记:28.Java API之文档批量操作
- ElasticSearch 6.x 学习笔记:1.下载安装与配置