【问题标题】:Loading JSON stream from Logstash to Elasticsearch将 JSON 流从 Logstash 加载到 Elasticsearch
【发布时间】:2016-12-10 10:21:21
【问题描述】:

我正在尝试通过logstash 将JSON 流(json 对象文件的行)加载到elasticsearch。我的一些 json 对象字段包含 unicode,如下所示。

{"status_link": "https://www.facebook.com/asia/videos/1118055131588324/", "num_loves": "4", "num_sads": "0", "num_wows": "0", "num_angrys": "0", "num_comments": "6", "num_reactions": "46", "num_hahas": "0", "link_name": "", "num_likes": "42", "timestamp": "2016-07-25 02:07:38", "num_shares": "8", "_id": "156915824368931_1118055131588324", "status_message": "\"\u0411\u0440\u0438\u0433\u0430\u0434\" \u0440\u0435\u0430\u043b\u0438\u0442\u0438 \u0448\u043e\u0443\u043d\u044b \u0448\u0438\u043d\u044d \u0434\u0443\u0433\u0430\u0430\u0440 07-\u0440 \u0441\u0430\u0440\u044b\u043d 28-\u043d\u044b \u043f\u04af\u0440\u044d\u0432 \u0433\u0430\u0440\u0430\u0433\u0438\u0439\u043d \u043e\u0440\u043e\u0439 18:00 \u0446\u0430\u0433\u0430\u0430\u0441", "status_type": "video"}

当我启动logstash时,它给了我一个错误:

"status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"Mixing up field types: class org.elasticsearch.index.mapper.core.StringFieldMapper$StringFieldType != class org.elasticsearch.index.mapper.internal.IdFieldMapper$IdFieldType on field _id"}}}}, :level=>:warn}

我的logstash.conf:

input
{
    file
    {
        path => "test.json"
        start_position => "beginning"
        sincedb_path => "/dev/null"
        exclude => "*.gz"
        type => "posts"
        codec => "json"
    }
}

filter {
  json {
    source => "message"
  }
}

output {
  elasticsearch {
  hosts => ["localhost:9200"]
  index => "fb"
  codec => "json"
   }
}

我尝试在没有 unicode 的情况下加载 json 对象,它成功地在 elasticsearch 中解析和索引。

【问题讨论】:

    标签: json parsing elasticsearch unicode logstash


    【解决方案1】:

    问题是您的文档中有一个_id 字段。 _id 是一个保留字段。所以你需要删除或重命名它。

    【讨论】:

    • 稍后我将加载 cmets 并使其与帖子建立父子关系。那么 _id 字段不就是在帖子和 cmets 之间建立联系的唯一字段吗?
    • 如果你想使用_id作为你的文档id,我的建议是把它重命名为id并在你的elasticsearch输出中使用document_id => "%{[event][id]}"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2019-05-25
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多