【问题标题】:Kibana: How to create a table that shows the count of the top_hits for a fieldKibana:如何创建一个显示字段的 top_hits 计数的表
【发布时间】:2017-11-05 20:26:09
【问题描述】:

我的文档包含字段 account_id(我的关系数据库的主键)和状态。每当账户状态发生变化时,我都会将事件推送到 ElasticSearch。

因此,在一段时间内,一个帐户会有多个不同状态的文档。

我的要求是获取每个 account_id 的最近文档并根据状态进行计数。

SQL 等效“select status, count(*) from account group by status ;”

示例:考虑以下日志

account_id: 1, status:delete, @timestamp: November 4th 2017, 18:42:09.445
account_id: 1, status:save, @timestamp: November 3rd 2017, 18:42:09.445
account_id: 1, status:draft, @timestamp: November 2nd 2017, 19:42:09.445

account_id: 2, status:draft, @timestamp: November 3rd 2017, 19:42:09.445

account_id: 3, status:save, @timestamp: November 4th 2017, 18:42:09.445
account_id: 3, status:draft, @timestamp: November 3rd 2017, 19:42:09.445

输出应该是:

**status** **count**
 delete   1
 save     1
 draft    1

麋鹿:5.6

【问题讨论】:

    标签: elasticsearch logstash kibana elastic-stack kibana-5


    【解决方案1】:

    至少从 2013 年起,Kibana 就要求提供此功能。我们不再等待,而是使用了 graphana,它可以做到。如果您可以关注所有 github 参考资料,看起来弹性可能有办法do it now

    【讨论】:

      【解决方案2】:

      现在作为一种解决方法,我更新了我的 logstash.conf 以便将相同的日志消息推送到两个索引。在第一个索引中,我总是创建一条新记录,在第二个索引中,我创建/更新记录。

      logstash.conf 的片段

      output {
        if [index_name] == "Account" {
        elasticsearch {
        hosts => ["IP:PORT"]
        index => "account"
        }
      }
      stdout { codec => rubydebug }
      }
      output {
       if [index_name] == "Account" {
       elasticsearch {
       hosts => ["IP:PORT"]
       index => "account_latest"
       document_id => "%{field_id}"
       }
      }
      stdout { codec => rubydebug }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-30
        • 1970-01-01
        • 2021-01-23
        相关资源
        最近更新 更多