[英]Outputting document metadata from ElasticSearch using Logstash output csv plugin
I am attempting to output the _id metadata field from ES into a CSV file using Logstash. 我正在尝试使用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
]
}
My logstash output filter is: 我的logstash输出过滤器是:
output { csv { fields => [ "_id", "vulnid", "published"] path =>
"/tmp/export.%{+YYYY-MM-dd-hh-mm}.csv" } }
I get output: 我得到输出:
,CVE-2018-1000060,2018-02-09T18:29:02.213-05:00
But I would like to get: 但我想得到:
vANfNGYB9XD0VZRJUFfy,CVE-2018-1000060,2018-02-09T18:29:02.213-05:00
How to output the metadata _id into the csv file? 如何将元数据_id输出到csv文件中? It does not matter if I specify the field like "_id" or "@_id" or "@id".
是否指定“ _id”或“ @_id”或“ @id”之类的字段都没有关系。
When we query ES we have to enable docinfo => true. 查询ES时,必须启用docinfo => true。 By default it is false.
默认情况下为false。
input {
elasticsearch {
hosts => [ your hosts ]
index => "ti"
query => '{your query}'
size => 1000
scroll => "1s"
docinfo => true
schedule => "14 * * * *"
}
}
Well logstash is not able to get "_id" field from your input, because you must not have set the option docinfo into true. 不错,logstash无法从您的输入中获取“ _id”字段,因为您必须未将docinfo选项设置为true。
docinfo helps to include elasticsearch documents information such as index,type _id etc..Please have a look here for more info https://www.elastic.co/guide/en/logstash/current/plugins-inputs-elasticsearch.html#plugins-inputs-elasticsearch-docinfo docinfo有助于包含Elasticsearch文档信息,例如索引,类型_id等。请在此处查看更多信息https://www.elastic.co/guide/zh-CN/logstash/current/plugins-inputs-elasticsearch.html#插件-输入- elasticsearch-文档信息
use your input plugin as 使用您的输入插件作为
input {
elasticsearch {
hosts => "hostname"
index => "yourIndex"
query => '{ "query": { "query_string": { "query": "*" } } }' //optional
size => 500 //optional
scroll => "5m" //optional
docinfo => true
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.