使用Kibana中的ElasticSearch查询DSL从字段中获取唯一数据

问题描述 投票:0回答:1

我已经有各种各样的查询来收集数据并将其显示在Kibana仪表板中。现在,我想从结果数据中获取唯一值。我该如何编写查询DSL。

基本上,我想为contextMap.connectionid字段获取唯一值。有没有办法使用类似于此示例的方法来实现这一目标?

{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "app",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "app.key": "contextMap.connectionid"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}
elasticsearch querydsl
1个回答
0
投票

您可以在汇总的帮助下计算不重复计数。因此,您的搜索查询是:

搜索查询:

{
    "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "app",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "app.key": "contextMap.connectionid"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
    "aggs": {
        "uniqueconnectionId": {
            "terms": {
                "field": "contextMap.connectionid.keyword"
            }
        }
    }
}

您可以在这里参考以计算字段https://discuss.elastic.co/t/get-distinct-values-from-a-field-in-elasticsearch/99783的不同值

© www.soinside.com 2019 - 2024. All rights reserved.