无法在elasticsearch中放弃

kxe2p93d  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(345)

我在elasticsearch有一个日志服务。我想获得使用过我的服务的用户。我的请求返回了详细的日志行,但我想得到一个唯一的“kubernetes.pod\u name”:

{
    "size": 10000,
    "_source": ["kubernetes.pod_name"],
    "query": {"bool": {"filter": [
        {"match": {"kubernetes.labels.app" : "jupyterhub"}},
        {"match_phrase": {"log": "200 GET"}}
    ]}},
    "aggs": {"pods": {"terms": {"field": "kubernetes.pod_name"}}}
}

为什么日志行不分组在“aggs”部分?如何获得唯一用户?
upd:我的查询返回:

{'took': 614,
 'timed_out': False,
 '_shards': {'total': 5, 'successful': 5, 'skipped': 0, 'failed': 0},
 'hits': {'total': 17703,
  'max_score': 0.0,
  'hits': [{'_index': 'dwh-dev-2020-10-14',
    '_type': 'container_log',
    '_id': 'vQ6vJHUBU_u817onY-cZ',
    '_score': 0.0,
    '_source': {'kubernetes': {'pod_name': 'jupyter-lyisova-2evg'}}},
   {'_index': 'dwh-dev-2020-10-14',
    '_type': 'container_log',
    '_id': 'xA6vJHUBU_u817onY-cZ',
    '_score': 0.0,
    '_source': {'kubernetes': {'pod_name': 'jupyter-lyisova-2evg'}}},
   {'_index': 'dwh-dev-2020-10-14',
    '_type': 'container_log',
    '_id': '6g6vJHUBU_u817onY-cZ',
    '_score': 0.0,
    '_source': {'kubernetes': {'pod_name': 'jupyter-bogdanov'}}},
  ...

我想得到20行,而不是17703行,每行对应一个唯一的“kubernetes.pod\u name”

e4eetjau

e4eetjau1#

可以在术语聚合和过滤器聚合之间进行合并

{
      "aggs": {
        "labels_filter": {
          "filter": [
            {
              "match": {
                "kubernetes.labels.app": "jupyterhub"
              }
            },
            {
              "match_phrase": {
                "log": "200 GET"
              }
            }
          ],
          "aggs": {
            "pods": {
              "terms": {
                "field": "kubernetes.pod_name"
              }
            }
          }
        }
      }
    }

相关问题