编解码器Json不会将数据发送到Elasticsearch

时间:2018-10-19 14:21:07

标签: json elasticsearch

输入:json

  <div class="row no-gutters">
        <div class="col">
            <input class="form-control border-secondary border-right-0 rounded-0" type="search" value="search" id="example-search-input4">
        </div>
        <div class="col-auto">
            <button class="btn btn-outline-secondary border-left-0 rounded-0 rounded-right" type="button">
                <i class="fa fa-times"></i>
            </button>
        </div>
  </div>

LOGSTASH CONF FILE:

{"userid": 125,"type": "SELL"}
{"userid": 127,"type": "SELL"}

stdout输出:

input {
kafka {
bootstrap_servers => ""
topics => ["topic1"]
codec => "json"
}
}
output {
amazon_es {
hosts => [""]
region => ""
aws_access_key_id => ''
aws_secret_access_key => ''
index => "indexname"
}

stdout { codec => rubydebug }
}

输出看起来完全像我想要的。但是,这不会成为Elasticsearch主题。 如果我不使用json过滤器,则整个json都会作为“消息”进入ES。

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

您尝试使用json过滤器吗?

input {
    kafka {
        bootstrap_servers => ""
        topics => ["topic1"]
    }
}

filter {
    json {
        source => "message"
    }
}
output {
    amazon_es {
        hosts => [""]
        region => ""
        aws_access_key_id => ''
        aws_secret_access_key => ''
        index => "indexname",
        custom_headers => {'Content-Type': 'application/json'}
    }

    stdout { codec => rubydebug }
}

答案 1 :(得分:0)

我发现了问题。我在造成问题的json文件数据中使用了一个名为type的字段。 logstash将其存储为ES中的_type,这是新版本的elasticsearch不再允许的。这就是为什么如果我的类型是“买入”,它将输入该条目,如果它是“卖出”,它将拒绝该条目。谢谢您的帮助!