elasticsearch 搜索弹性搜索每天第一次发生的事件,elasticsearch,kibana,elasticsearch,Kibana" /> elasticsearch 搜索弹性搜索每天第一次发生的事件,elasticsearch,kibana,elasticsearch,Kibana" />

elasticsearch 搜索弹性搜索每天第一次发生的事件

elasticsearch 搜索弹性搜索每天第一次发生的事件,elasticsearch,kibana,elasticsearch,Kibana,我们使用Logstash接收日志,传递到Elasticsearch,并使用Kibana进行浏览。非常常见的设置 每个条目中的一个字段是@timestamp,示例内容为03/18/2015 18:02:52。我应该使用什么过滤器来只显示每天的第一个条目?我不相信使用过滤器可以做到这一点-查看单个文档并不能确定一天中的第一个条目。但是,您应该能够通过聚合实现这一点:首先,使用with interval day进行聚合,以按天对事件进行分组。然后使用聚合每天提取一个结果(需要elasticsearch

我们使用Logstash接收日志,传递到Elasticsearch,并使用Kibana进行浏览。非常常见的设置


每个条目中的一个字段是@timestamp,示例内容为
03/18/2015 18:02:52
。我应该使用什么过滤器来只显示每天的第一个条目?

我不相信使用过滤器可以做到这一点-查看单个文档并不能确定一天中的第一个条目。但是,您应该能够通过聚合实现这一点:首先,使用with interval day进行聚合,以按天对事件进行分组。然后使用聚合每天提取一个结果(需要elasticsearch 1.3或更高版本)。您的查询应该如下所示

{
  "query": {
    "match_all": {}
  },
  "aggs": {
    "by-day": {
      "date_histogram": {
        "field": "timestamp",
        "interval": "day"
      },
      "aggs": {
        "top_for_day": {
          "top_hits": {
            "size": 1,
            "sort": [
              {
                "timestamp": {
                  "order": "asc"
                }
              }
            ]
          }
        }
      }
    }
  }
}
这将产生如下结果(为简洁起见略微修剪)


我很难在Kibana中实现这一点,我该怎么做呢?对不起,我对Kibana不是很熟悉-我玩得很快,找不到输入任意聚合的方法
{
  "aggregations": {
    "by-day": {
      "buckets": [
        {
          "key_as_string": "2015-02-01T00:00:00.000Z",
          "key": 1422748800000,
          "doc_count": 7635,
          "top_for_day": {
            "hits": {
              "total": 7635,
              "max_score": null,
              "hits": [
                {
                  "_index": "events-2015-02",
                  "_type": "event",
                  "_id": "c64f85ac-a870-441f-bedb-e24db47fd02a",
                  "_score": null,
                  "_source": {
                    "eventTime": "2015-02-01T00:00:26Z"
                  },
                  "sort": [
                    1422748826000
                  ]
                }
              ]
            }
          }
        },
        {
          "key_as_string": "2015-02-02T00:00:00.000Z",
          "key": 1422835200000,
          "doc_count": 8182,
          "top_for_day": {
            "hits": {
              "total": 8182,
              "max_score": null,
              "hits": [
                {
                  "_index": "events-2015-02",
                  "_type": "event",
                  "_id": "c544278d-9f51-41a8-827b-9c70c0a057ca",
                  "_score": null,
                  "_source": {
                    "timestamp": "2015-02-02T00:00:19Z"
                  },
                  "sort": [
                    1422835219000
                  ]
                }
              ]
            }
          }
        }
      ]
    }
  }
}