天高云淡的博客

Good Luck To You!

Hive Elasticsearch 去重分组求和

按天分组去重求和_pkey
hive:

select count(DISTINCT(`_pkey`)),rq FROM table where `_pkey` <> '' GROUP BY partion_dt ORDER by rq;

es:

{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "request_time": {
              "gte": "2020-04-01T00:00",
              "lt": "2020-11-26T23:59"
            }
          }
        },
        {
          "exists": {
            "field": "_pkey"
          }
        }
      ]
    }
  },
  "aggs": {
    "request_timelist": {
      "date_histogram": {
        "field": "request_time",
        "interval": "1d",
        "min_doc_count": 0
      },
      "aggs": {
        "pkcount": {
          "cardinality": {
            "field": "_pkey"
          }
        }
      }
    }
  },
  "size": 0
}

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

«   2021年3月   »
1234567
891011121314
15161718192021
22232425262728
293031
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
搜索
最新留言
    文章归档
    网站收藏
    友情链接
    • Z-BlogPHP
    • 订阅本站的 RSS 2.0 新闻聚合

    Powered By Z-BlogPHP 1.6.5 Valyria

    Copyright Your WebSite.Some Rights Reserved.