elasticsearch - 使用 Logstash 输出 csv 插件从 ElasticSearch 输出文档元数据
问题描述
我正在尝试使用 Logstash 将 ES 中的 _id 元数据字段输出到 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”这样的字段并不重要。
解决方案
好吧,logstash 无法从您的输入中获取“_id”字段,因为您一定没有将选项docinfo设置为 true。
docinfo 有助于包含 elasticsearch 文档信息,例如索引、类型 _id 等。请在此处查看更多信息https://www.elastic.co/guide/en/logstash/current/plugins-inputs-elasticsearch.html#插件输入-elasticsearch-docinfo
使用您的输入插件作为
input {
elasticsearch {
hosts => "hostname"
index => "yourIndex"
query => '{ "query": { "query_string": { "query": "*" } } }' //optional
size => 500 //optional
scroll => "5m" //optional
docinfo => true
}
}
推荐阅读
- java - 在底部导航抽屉中加载带有标记列表的地图片段
- python - Pandas - 添加交替值的列
- ruby-on-rails - rails 5 API 低级缓存
- java - 如何将小黄瓜步骤定义数据映射到 Cucumber 中的 Java 对象?
- java - 类对象关系如何工作?
- google-apps-script - ScriptProperties 和 UserProperties 已被弃用
- python - 用例如 UTF-8 编码的文本文件中的字典替换单词
- python - AccessToken 匹配查询不存在。使用 Postman 匹配查询不存在
- r - 如何使用 caret 包解释模型输出的准确性
- php - 向 JSON 对象添加多个图像 url