如何从具有特定_type的elasticsearch logstash

How to logstash from elasticsearch with specific _type

我有一个这样的 logstash (6.8.1) 配置文件:

input {
  elasticsearch {
    hosts => [ "127.0.0.1:9200" ]
    index => "myindex"
    codec => "json"
    docinfo => true
  }
}

filter {
  mutate {
    remove_field => ["@timestamp", "@version"]
  }
}

output {
  elasticsearch {
    hosts => [ "127.0.0.1:9300" ]
    index => "%{[@metadata][_index]}"
    document_type => "%{[@metadata][_type]}"
    document_id => "%{[@metadata][_id]}"
  }
}

但是9200端口的es是5.x,9300端口的es是6.x。 而且9200端口的es有多个"types".

因为es6.x只有一个"type",所以我需要这样的东西:

input {
  elasticsearch {
    hosts => [ "127.0.0.1:9200" ]
    user => ""
    password => ""
    index => "myindex"
    document_type => "mytype"  <--- like this
    codec => "json"
    docinfo => true
  }
}

我怎样才能意识到这一点? 非常感谢您的帮助。

我正在为您提供一个 jenkins logstash 配置示例。

你是不是这个意思:

input {
  file {
     path => "/var/log/jenkins/*"
     type => "jenkins-server"
     start_position => "beginning"
 } 
}
  filter 
 {
      if [type] == "jenkins-server" {
          mutate {
              add_field => ["@message_type", "jenkins"]
              add_field => ["@message", "%{message}"]
          }
      }
   }

最后我用elasticsearch-dump实现了这个操作:

docker run --net=host --rm -it docker.io/taskrabbit/elasticsearch-dump \
    --input=http://user:password@input-es:9200 \
    --input-index=my-user-index/my-user-type \
    --output=http://user:password@output-es:9200 \
    --output-index=my-user-index \
    --type=mapping

PS:迁移数据,使用选项--type=data