json - logstash 提取 json 字段并覆盖索引

标签 json elasticsearch logstash logstash-configuration

我有以下json:

[
{
    "key": "Key-1",
    "field1": "hello",
    "field2": "world"
},
{

    "key": "Key-2",
    "field1": "hello",
    "field2": "world"
}
]

和以下logstash文件:
input {
  http_poller {
    # List of urls to hit
    # URLs can either have a simple format for a get request
    # Or use more complex HTTP features
    urls => {
      myurl => {
        method => "GET"
        url => "http://localhost:8080/helloworld"
      }
    }
    # Decode the results as JSON
    codec => "json"
    # Schedule task
    schedule => { cron => "* * * * * UTC" }
  }

}

output {
  #debugging output

  stdout {
    codec => rubydebug
  }

  # elasticsearch output

  elasticsearch{
   hosts => "localhost"
   index => "helloworld"
  }

}

问题是这个logstash创建了多个具有相同键的文档,我希望logstash替换索引中的现有文档。反正我能做到吗?
提前致谢。

最佳答案

您应该定义文档的 id 是什么,以便您可以根据 key 更新现有的。

elasticsearch {
  document_id => "%{key}"
  hosts => "localhost"
  index => "helloworld"
}

请参阅文档 here了解更多信息。

关于json - logstash 提取 json 字段并覆盖索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49926104/

相关文章:

jquery - blueimp jquery 文件 uploader 中的 IE 6 JSON 响应处理

json - 如何在Logstash中过滤具有相同名称的多个字段?

logstash - 如何在 Logstash 中比较日期

ios - 将 token 发送到服务器 Swift 3

json - 如何修复 CodingKeys 的 "no value associated"错误?

java - 安心服务

python - Elasticsearch Python API删除方法

ruby-on-rails - Elasticsearch嵌套查询聚合

elasticsearch - Elasticsearch索引搜索模板在数组中生成空字符串

logstash - 过滤特定行