主要知识点
- cartinality的用法
es去重用的是cartinality metric算法,对每个bucket中的指定的field进行去重,然后获取去重后的count,类似于count(distcint)
cartinality的用法
GET /tvs/sales/_search
{
"size": 0,
"aggs": {"mouth": {
"date_histogram": {"field": "sold_date","interval": "month"},
"aggs": {"distict_color": {"cardinality": {"field": "brand"}}}
}
}
}
执行结果如下:
"aggregations": {
"mouth": {
"buckets": [
{
"key_as_string": "2016-05-01T00:00:00.000Z",
"key": 1462060800000,
"doc_count": 1,
"distict_color": {
"value": 1
}
},
{
"key_as_string": "2016-06-01T00:00:00.000Z",
"key": 1464739200000,
"doc_count": 0,
"distict_color": {
"value": 0
}
},