进阶-第46__深入聚合数据分析_cardinality去重算法以及每月销售品牌数量统计

 

es,去重,cartinality metric,对每个bucket中的指定的field进行去重,取去重后的count,类似于count(distcint)

搜索测试

GET /tvs/sales/_search

{

 "size": 0,

 "aggs": {

   "months": {

     "date_histogram": {

       "field": "sold_date",

       "interval": "month"

     },

     "aggs": {

       "distinct_colors": {

         "cardinality": {

           "field": "brand"

         }

       }

     }

   }

 }

}

 

搜索结果

{

  "took": 16,

  "timed_out": false,

  "_shards": {

    "total": 5,

    "successful": 5,

    "failed": 0

  },

  "hits": {

    "total": 8,

    "max_score": 0,

    "hits": []

  },

  "aggregations": {

    "months": {

      "buckets": [

        {

          "key_as_string": "2016-05-01T00:00:00.000Z",

          "key": 1462060800000,

          "doc_count": 1,

          "distinct_colors": {

            "value": 1

          }

        },

        {

          "key_as_string": "2016-06-01T00:00:00.000Z",

          "key": 1464739200000,

          "doc_count": 0,

          "distinct_colors": {

            "value": 0

          }

        },

        {

          "key_as_string": "2016-07-01T00:00:00.000Z",

          "key": 1467331200000,

          "doc_count": 1,

          "distinct_colors": {

            "value": 1

          }

        },

        {

          "key_as_string": "2016-08-01T00:00:00.000Z",

          "key": 1470009600000,

          "doc_count": 1,

          "distinct_colors": {

            "value": 1

          }

        },

        {

          "key_as_string": "2016-09-01T00:00:00.000Z",

          "key": 1472688000000,

          "doc_count": 0,

          "distinct_colors": {

            "value": 0

          }

        },

        {

          "key_as_string": "2016-10-01T00:00:00.000Z",

          "key": 1475280000000,

          "doc_count": 1,

          "distinct_colors": {

            "value": 1

          }

        },

        {

          "key_as_string": "2016-11-01T00:00:00.000Z",

          "key": 1477958400000,

          "doc_count": 2,

          "distinct_colors": {

            "value": 1

          }

        },

        {

          "key_as_string": "2016-12-01T00:00:00.000Z",

          "key": 1480550400000,

          "doc_count": 0,

          "distinct_colors": {

            "value": 0

          }

        },

        {

          "key_as_string": "2017-01-01T00:00:00.000Z",

          "key": 1483228800000,

          "doc_count": 1,

          "distinct_colors": {

            "value": 1

          }

        },

        {

          "key_as_string": "2017-02-01T00:00:00.000Z",

          "key": 1485907200000,

          "doc_count": 1,

          "distinct_colors": {

            "value": 1

          }

        }

      ]

    }

  }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值