白话Elasticsearch46-深入聚合数据分析之Cardinality Aggs-cardinality去重算法以及每月销售品牌数量统计
2019-08-25 15:40
357 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/yangshangwei/article/details/100060266
文章目录
概述
继续跟中华石杉老师学习ES,第46篇
课程地址: https://www.roncoo.com/view/55
官方说明
Cardinality Aggregation:戳这里
es中的去重,cartinality metric,对每个bucket中的指定的field进行去重,取去重后的count,类似于count(distcint)
示例
GET /tvs/sales/_search { "aggs": { "month":{ "date_histogram": { "field": "sold_date", "interval": "month" }, "aggs": { "distinct_brand_cnt": { "cardinality": { "field": "brand" } } } } }, "size": 0 }
返回:
{ "took": 8, "timed_out": false, "_shards": { "total": 5, "successful": 5, "skipped": 0, "failed": 0 }, "hits": { "total": 8, "max_score": 0, "hits": [] }, "aggregations": { "month": { "buckets": [ { "key_as_string": "2016-05-01T00:00:00.000Z", "key": 1462060800000, "doc_count": 1, "distinct_brand_cnt": { "value": 1 } }, { "key_as_string": "2016-06-01T00:00:00.000Z", "key": 1464739200000, "doc_count": 0, "distinct_brand_cnt": { "value": 0 } }, { "key_as_string": "2016-07-01T00:00:00.000Z", "key": 1467331200000, "doc_count": 1, "distinct_brand_cnt": { "value": 1 } }, { "key_as_string": "2016-08-01T00:00:00.000Z", "key": 1470009600000, "doc_count": 1, "distinct_brand_cnt": { "value": 1 } }, { "key_as_string": "2016-09-01T00:00:00.000Z", "key": 1472688000000, "doc_count": 0, "distinct_brand_cnt": { "value": 0 } }, { "key_as_string": "2016-10-01T00:00:00.000Z", "key": 1475280000000, "doc_count": 1, "distinct_brand_cnt": { "value": 1 } }, { "key_as_string": "2016-11-01T00:00:00.000Z", "key": 1477958400000, "doc_count": 2, "distinct_brand_cnt": { "value": 1 } }, { "key_as_string": "2016-12-01T00:00:00.000Z", "key": 1480550400000, "doc_count": 0, "distinct_brand_cnt": { "value": 0 } }, { "key_as_string": "2017-01-01T00:00:00.000Z", "key": 1483228800000, "doc_count": 1, "distinct_brand_cnt": { "value": 1 } }, { "key_as_string": "2017-02-01T00:00:00.000Z", "key": 1485907200000, "doc_count": 1, "distinct_brand_cnt": { "value": 1 } } ] } } }
我们来看下原始数据:
来看下我们的统计结果,找个
2016-11
统计正确。
相关文章推荐
- 白话Elasticsearch48-深入聚合数据分析之 Percentiles Aggregation-percentiles百分比算法以及网站访问时延统计及Percentiles优化
- 47_ElasticSearch cardinality去重算法以及每月销售品牌数量统计
- 白话Elasticsearch50-深入聚合数据分析之doc values机制
- 白话Elasticsearch51-深入聚合数据分析之text field聚合以及fielddata原理
- 白话Elasticsearch59-数据建模实战_ Nested Aggregation/ Reverse nested Aggregation对嵌套的博客评论数据进行聚合分析
- 网站用户行为数据统计与分析之九:elasticsearch与mongodb集成
- 使用聚合数据平台对电商网站进行流量以及访问统计
- Elasticsearch学习之深入聚合分析二---案例实战
- Elasticsearch学习之深入聚合分析五---案例实战
- 大数据统计分析平台之二、ElasticSearch 6.2.1的安装与使用
- 关于Android大数据收集,埋点统计的详细讲解以及案例代码分析附github代码
- 数据统计分析中Treemap 应用实战(排序以及查找离指定key最近的key)
- elasticsearch的基础语句介绍 聚合功能很强大 可以分析数据
- 销售行业ERP数据统计分析都有哪些维度?
- 40_ElasticSearch 搜索+聚合:统计指定品牌下每个颜色的销量
- 销售行业ERP数据统计分析都有哪些维度?
- 网站用户行为数据统计与分析之六:elasticsearch的配置和使用
- 卖家网eBay数据分析工具-专业免费的eBay开店数据统计-eBay销售分析-eBay卖家分析工具软件
- 利用spm提供的MoAEpilot听觉数据学习预处理以及单被试glm分析与统计推断
- elasticsearch笔记整理-基础入门、深入搜索、集群优化、聚合、数据建模等章节-选摘自《elasticsearch权威指南》