简体   繁体   English

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

[英]Get unique data from a field using ElasticSearch query DSL in Kibana

I have already various queries that collect data and show it in the Kibana dashboard.我已经有各种查询来收集数据并将其显示在 Kibana 仪表板中。 Now I would like to get unique values from my result data.现在我想从我的结果数据中获取唯一值。 How can I write the query DSL for that.我怎样才能为此编写查询 DSL。

Basically I would like to get unique value for the field contextMap.connectionid.基本上我想获得字段 contextMap.connectionid 的唯一值。 Is there a way do achieve that using something similar to this example?有没有办法使用类似于这个例子的东西来实现这一点?

{
  "query": {
    "bool": {
      "must": [
        {
          "nested": {
            "path": "app",
            "query": {
              "bool": {
                "must": [
                  {
                    "match": {
                      "app.key": "contextMap.connectionid"
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  }
}

You can calculate distinct count with the help of aggregation.您可以在聚合的帮助下计算不同的计数。 So, your search query is:因此,您的搜索查询是:

Search Query:搜索查询:

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

You can refer here for calculating distinct values of a field https://discuss.elastic.co/t/get-distinct-values-from-a-field-in-elasticsearch/99783您可以在此处参考计算字段https://discuss.elastic.co/t/get-distinct-values-from-a-field-in-elasticsearch/99783的不同值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM