使用logstash的动态elasticsearch index_type

Ysa*_*sak 0 grok elasticsearch logstash

我正在使用来自rabbitmq服务器的logstash在elasticsearch上存储数据.

我的logstash命令看起来像

logstash -e 'input{
rabbitmq {
    exchange => "redwine_log"
    key => "info.redwine"
    host => "localhost"
    durable => true
    user => "guest"
    password => "guest"
}
}

output {
  elasticsearch {
    host => "localhost"
    index => "redwine"
  }
}
filter {
  json {
    source => "message"
    remove_field => [ "message" ]
  }
}'
Run Code Online (Sandbox Code Playgroud)

但我需要logstash将数据放入elasticsearch集群中的不同类型.我的意思是:

"hits": {
      "total": 3,
      "max_score": 1,
      "hits": [
         {
            "_index": "logstash-2014.11.19",
            "_type": "logs",
            "_id": "ZEea8HBOSs-QwH67q1Kcaw",
            "_score": 1,
            "_source": {
               "context": [],
               "level": 200,
               "level_name": "INFO",
Run Code Online (Sandbox Code Playgroud)

这是搜索结果的一部分,您可以通过defualt看到logstash创建一个名为"logs"的类型(_type:"logs").在我的项目中,我需要类型是动态的,应该根据输入数据创建.例如:我的输入数据看起来像

{
    "data":"some data",
    "type": "type_1"
}
Run Code Online (Sandbox Code Playgroud)

我需要logstash在elasticsearch中创建一个名为"type_1"的新类型.

我尝试使用grok ..但无法得到这个特定的要求.

Ysa*_*sak 5

它以这种方式为我工作

elasticsearch {
    host => "localhost"
    index_type => "%{type}"
  }
Run Code Online (Sandbox Code Playgroud)

  • index_type已在1.5中重命名为document_type(请参阅https://github.com/elastic/logstash/issues/3151).当前文档:https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-document_type (2认同)