elasticsearch - Grafana 条形图 : visualize sum of entries per product type for each month

标签 elasticsearch nosql lucene bar-chart grafana

我正在尝试使用 Grafana 中的条形图可视化以下数据。我的数据源是 ElasticSearch,它获取如下日志消息: enter image description here

我知道想要按产品类型对这些条目进行分组,并获取每月每种产品类型的所有条目的总和。结果应该如下所示:

enter image description here

我已经设法获得每种产品类型的所有条目的总和: enter image description here但我不知道如何获取每个月每种产品类型的总和。关于如何实现这一目标有什么想法吗?

最佳答案

因此,您需要在此处按数据的日期直方图字段进行分组,然后对产品类型进行聚合或分桶。

Grafana Sample Example

正如您在上图中看到的,您需要做的是首先按“日期直方图”与字段进行分组(看起来字段名称是“时间戳” ”,就你的情况而言)是你想要继续进行的。您可以根据需要指定间隔,例如每小时、每天、每月,也可以将其保留为“自动”。

一旦完成,您接下来需要像上面提到的那样对产品类型进行分类。

一旦你做到了这一点,我想你就可以开始了。

要交叉检查幕后到底发生了什么,您可以单击面板右上角的“查询检查器”并以 JSON 形式查看查询。

在我展示的示例中,生成了以下内容:

{
  "type": "table",
  "title": "Panel Title",
  "gridPos": {
    "x": 0,
    "y": 0,
    "w": 12,
    "h": 8
  },
  "id": 23763571993,
  "targets": [
    {
      "refId": "A",
      "query": "",
      "alias": "",
      "metrics": [
        {
          "type": "count",
          "id": "1"
        }
      ],
      "bucketAggs": [
        {
          "id": "3",
          "type": "date_histogram",
          "settings": {
            "interval": "auto",
            "min_doc_count": "0",
            "trimEdges": "0"
          }
        },
        {
          "id": "4",
          "type": "terms",
          "settings": {
            "min_doc_count": "0",
            "size": "10",
            "order": "desc",
            "orderBy": "_term"
          },
          "field": "coordinates.longitude"
        }
      ],
      "timeField": "@timestamp"
    }
  ],
  "options": {
    "showHeader": true
  },
  "datasource": "ES Logs",
  "fieldConfig": {
    "defaults": {
      "custom": {
        "align": null,
        "filterable": false
      },
      "thresholds": {
        "mode": "absolute",
        "steps": [
          {
            "value": null,
            "color": "green"
          },
          {
            "value": 80,
            "color": "red"
          }
        ]
      },
      "mappings": [],
      "color": {
        "mode": "thresholds"
      }
    },
    "overrides": []
  },
  "pluginVersion": "7.5.4"
}

您可以忽略周围的信息,因为这毕竟是虚拟数据。

您还可以引用以下链接:Date Histogram Community Question


对于其他可能有类似查询但与 Kibana 相关的人来说,它甚至更简单。在可视化选项卡中,选择您的索引。

第1步:首先选择“日期直方图”字段,然后选择要使用的索引字段。

enter image description here

第 2 步:然后选择“术语”并选择您要使用的索引字段。

enter image description here

第 3 步:可视化已准备就绪。

enter image description here

关于elasticsearch - Grafana 条形图 : visualize sum of entries per product type for each month,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67108716/

相关文章:

django - Django-Haystack:如何将搜索限制为用户拥有的对象?

azure - 不支持使用 TableBatchOperation 检索多行?

json - 存储传感器数据的数据库(JSON)

elasticsearch - Logstash jdbc插件:如何对列使用日期过滤器?

sql-server - 无法通过Logstash将数据从MS Sql Server传输到ElasticSearch

Hadoop 与 NoSQL 数据库

Lucene 4 - 从目录中获取所有使用的字段

Lucene 搜索和下划线

algorithm - Lucene的算法

elasticsearch - elasticsearch 2.1.1-无法建立集群