赞
踩
cardinality 即去重计算,类似sql中 count(distinct),先去重再求和,计算指定field值的种类数。
下面实例,计算有多少个不同的city。
请求:
- POST bank/_doc/_search
- {
- "size": 0,
- "aggs": {
- "cartinality_gender": {
- "cardinality": {
- "field": "city.keyword"
- }
- }
- }
- }
响应:
- {
- "took": 2,
- "timed_out": false,
- "_shards": {
- "total": 5,
- "successful": 5,
- "skipped": 0,
- "failed": 0
- },
- "hits": {
- "total": 15,
- "max_score": 0,
- "hits": []
- },
- "aggregations": {
- "cartinality_gender": {
- "value": 15
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。