使用 Logstash 将数据从 Elasticsearch 导出到 CSV

Export data from Elasticsearch to CSV using Logstash

如何使用 Logstash 将数据从 Elasticsearch 导出到 CSV?我只需要包含特定的列。

安装 2 plugins: elasticsearch input plugin and csv output plugin。 然后创建a configuration file. Here is a good example for this particular case.

您现在可以出发了,只是 运行:
bin/logstash -f /path/to/logstash-es-to-csv-example.conf

并检查 export.csvoutput -> csv -> path 中指定的文件。

重要提示: 使用 Logstash 5.x 时,csv 输出插件中存在一个已知错误。该插件生成一个 %{host} %{message}%{host} %{message}%{host} %{message} 的字符串。 有一个未解决的问题:https://github.com/logstash-plugins/logstash-output-csv/issues/10

作为解决方法,您可以:

  • 降级到 Logstash 2.x 直到问题得到解决
  • 改用文件输出

    file {
        codec => line { format => "%{field1},%{field2}"}
        path => "/path/to/data_export.csv"
    }
    
  • 根据github讨论修改插件代码...