ES的agg简单使用

牧云@^-^@ 提交于 2021-01-01 04:54:02

请求数据: 

GET /app-attributeuser-wykyy/_search
{
  "query": {
    "bool": {
      "must": [
          { "term": 
             {"app_name":"wykyy"}
          }
      ]
    }
  },
  "aggs": {
    "advertiser_id": {
      "terms": {
        "field": "advertiser_id"
      }
    }
  }
}

返回统计数据

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 10000,
      "relation" : "gte"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "app-attributeuser-wykyy",
        "_type" : "_doc",
        "_id" : "kWEZqnYBe1Pa8HGhctS_",
        "_score" : 1.0,
        "_source" : {
          "oaid_md5" : "__OAID_MD5__",
          "@timestamp" : "2020-12-28T16:06:02.097Z",
          "os" : "0",
          "market" : "1",
          "campaign_id" : "__CAMPAIGN_ID__",
          "cid" : "__CID__",
          "aid_name" : "__AID_NAME__",
          "android_id_md5" : "__ANDROIDID__",
          "advertiser_id" : "__ADVERTISER_ID__",
          "campaign_name" : "__CAMPAIGN_NAME__",
          "host" : {
            "name" : "VM-16-51-centos",
            "containerized" : false,
            "id" : "735fbcd856b697dbc8d6deb1a11dd712",
            "architecture" : "x86_64",
            "hostname" : "VM-16-51-centos",
            "os" : {
              "name" : "CentOS Linux",
              "family" : "redhat",
              "kernel" : "3.10.0-693.el7.x86_64",
              "codename" : "Core",
              "platform" : "centos",
              "version" : "7 (Core)"
            }
          },
          "channel" : "zhise04",
          "@version" : "1",
          "app_name" : "wykyy",
          "aid" : "__AID__",
          "create_at" : 1609171558,
          "oaid" : "__OAID__",
          "natural" : 0,
          "agent" : {
            "ephemeral_id" : "2826628a-93c9-403e-9ed3-997c40c5d4ed",
            "type" : "filebeat",
            "hostname" : "VM-16-51-centos",
            "id" : "26296627-89d6-4e0a-94f7-dfc11f0851b3",
            "version" : "7.5.1"
          },
          "log" : {
            "offset" : 7931,
            "file" : {
              "path" : "/data/esdata/user-wykyy-2020-12-29.log"
            }
          },
          "imei_md5" : "__IMEI__",
          "ecs" : {
            "version" : "1.1.0"
          },
          "cid_name" : "__CID_NAME__",
          "game_uuid" : "0e2f394723f26b8b95666894f12f40de",
          "tags" : [
            "app-attributeuser",
            "beats_input_raw_event"
          ],
          "callback_url" : "__CALLBACK_URL__",
          "input" : {
            "type" : "log"
          }
        }
      }
    ]
  },
  "aggregations" : {
    "advertiser_id" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 3096,
      "buckets" : [
        {
          "key" : "",
          "doc_count" : 28986
        },
        {
          "key" : "1684505931837453",
          "doc_count" : 7829
        },
        {
          "key" : "1684505840616462",
          "doc_count" : 3755
        },
        {
          "key" : "1686943858054158",
          "doc_count" : 3594
        },
        {
          "key" : "1686943858505735",
          "doc_count" : 1013
        },
        {
          "key" : "__ADVERTISER_ID__",
          "doc_count" : 995
        },
        {
          "key" : "1686032051869703",
          "doc_count" : 957
        },
        {
          "key" : "1686032022027341",
          "doc_count" : 817
        },
        {
          "key" : "1677411843689480",
          "doc_count" : 497
        },
        {
          "key" : "1684404267527176",
          "doc_count" : 496
        }
      ]
    }
  }
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!