【问题标题】:Outputting document metadata from ElasticSearch using Logstash output csv plugin使用 Logstash 输出 csv 插件从 ElasticSearch 输出文档元数据
【发布时间】:2018-10-02 13:37:48
【问题描述】:

我正在尝试使用 Logstash 将 _id 元数据字段从 ES 输出到 CSV 文件中。

{
  "_index": "data",
  "_type": "default",
  "_id": "vANfNGYB9XD0VZRJUFfy",
  "_version": 1,
  "_score": null,
  "_source": {
    "vulnid": "CVE-2018-1000060",
    "product": [],
    "year": "2018",
    "month": "02",
    "day": "09",
    "hour": "23",
    "minute": "29",
    "published": "2018-02-09T18:29:02.213-05:00",
  },
  "sort": [
    1538424651203
  ]
}

我的 logstash 输出过滤器是:

output { csv {  fields => [ "_id", "vulnid", "published"]  path =>
"/tmp/export.%{+YYYY-MM-dd-hh-mm}.csv" } }

我得到输出:

,CVE-2018-1000060,2018-02-09T18:29:02.213-05:00

但我想得到:

vANfNGYB9XD0VZRJUFfy,CVE-2018-1000060,2018-02-09T18:29:02.213-05:00

如何将元数据_id输出到csv文件中? 如果我指定像“_id”或“@_id”或“@id”这样的字段并不重要。

【问题讨论】:

    标签: elasticsearch logstash


    【解决方案1】:

    当我们查询 ES 时,我们必须启用 docinfo => true。默认为假。

    input {
     elasticsearch {
      hosts => [ your hosts ]
      index => "ti"
      query => '{your query}'
      size => 1000
      scroll => "1s"
      docinfo => true
      schedule => "14 * * * *"
     }
    }
    

    【讨论】:

    • 以防将来有人发现。将 docinfo 设置为 true 后,字段中的 _id 对我不起作用,我不得不使用 [@metadata][_id]
    【解决方案2】:

    logstash 无法从您的输入中获取“_id”字段,因为您一定没有将选项 docinfo 设置为 true。

    docinfo 有助于包含 elasticsearch 文档信息,例如索引、类型 _id 等。请在此处查看更多信息https://www.elastic.co/guide/en/logstash/current/plugins-inputs-elasticsearch.html#plugins-inputs-elasticsearch-docinfo

    使用你的输入插件作为

    input {
      elasticsearch {
        hosts => "hostname"
        index => "yourIndex"
        query => '{ "query": { "query_string": { "query": "*" } } }' //optional
        size => 500 //optional
        scroll => "5m" //optional
        docinfo => true
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-27
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多