简体   繁体   English

logstash 将 json 输入的顺序更改为弹性搜索

[英]logstash changing ordering of json input to elastic search

I have a logstash process running which is consuming data from a kafka topic.我有一个正在运行的 logstash 进程正在使用来自 kafka 主题的数据。 Messages in kafka topic are already in json format. kafka 主题中的消息已经是 json 格式。 logstash is simply pushing them in elastic search. logstash 只是在弹性搜索中推动它们。 But while doing so logstash changes ordering of the fields.但是这样做时,logstash 会更改字段的顺序。 There is a team which is consuming csv format of the data, so the changed ordering gives them trouble.有一个团队正在使用 csv 格式的数据,因此更改的顺序给他们带来了麻烦。 What could be the reason?可能是什么原因?

for eg input json {"foo1":"bar1","foo2":"bar2"}.例如输入 json {"foo1":"bar1","foo2":"bar2"}。 logstash pushes it in elastic then in elastic it looks like {"foo2":"bar2","foo1":"bar1"} logstash 将它推入弹性然后在弹性中它看起来像 {"foo2":"bar2","foo1":"bar1"}

logstash config日志存储配置

input{
    kafka{
        codec=>'json' bootstrap_servers => [localhost:9092] topics =>  'sample-logs' auto_offset_reset => 'earliest' => group_id => 'logstash-consumer'
    }
}
output {
     elasticsearch { 
         hosts => "localhost:9200", codec => json index=> "sample-logs-es" } 
stdout { 
    codec => rubydebug 
}

Two good reason to have it in the same order or sorted:以相同的顺序或排序的两个很好的理由:

  1. the _source fields better compress if you have a lot of similar data如果你有很多相似的数据,_source 字段会更好地压缩
  2. Easier for humans looking at the data in Kibana人类在 Kibana 中查看数据更容易

I have a logstash Ruby scripts that corrects for version updates in the code processing and some past mistakes.我有一个 logstash Ruby 脚本,可以纠正代码处理中的版本更新和一些过去的错误。 Sadly I also get random order JSON out of it.可悲的是,我也从中得到了随机顺序的 JSON。 And also have no idea yet on how to get it sorted again for ingestion into Elastic.并且还不知道如何再次对其进行排序以摄取到 Elastic 中。 Crude aproach would be dumping all to file, use JQ and then ingest directly.粗略的方法是将所有内容转储到文件中,使用 JQ 然后直接摄取。

将 pipeline.worker 设置为 1,否则多个 worker 将执行过滤器 + 并行输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM