我在使用logstash配置时遇到问题。你可以在下面找到我的logstash配置。Logstash到elasticsearch。带点的键
Ruby过滤器删除每个点 - “。”来自我的领域。看来,每一个工作正常 - 数据过滤的结果是正确的,但elasticsearch神奇地回应:"status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"Field name [/ConsumerAdminWebService/getConsumerTransactions.call] cannot contain '.'"}
其中getConsumerTransactions.call
是我的领域之一。
input {
http_poller {
urls => {
uatBackend1 => {
method => get
url => "http://some-url/"
headers => {
Accept => "application/json"
}
}
}
request_timeout => 60
# Run every 30 seconds
schedule => { cron => "* * * * * UTC"}
codec => "json"
metadata_target => "http_poller_metadata"
}
}
filter {
ruby {
init => "
def remove_dots hash
new = Hash.new
hash.each { |k,v|
if v.is_a? Hash
v = remove_dots(v)
end
new[ k.gsub('.','_') ] = v
if v.is_a? Array
v.each { |elem|
if elem.is_a? Hash
elem = remove_dots(elem)
end
new[ k.gsub('.','_') ] = elem
} unless v.nil?
end
} unless hash.nil?
return new
end
"
code => "
event.instance_variable_set(:@data,remove_dots(event.to_hash))
"
}
}
output {
elasticsearch {
hosts => localhost
}
}
恐怕这行代码是不正确的:event.instance_variable_set(:@data,remove_dots(event.to_hash))
- 结果数据以某种方式固定到该事件,但原始数据持续不变,并交付给Elasticsearch API。
我想作一些澄清这里需要:
- 我用ES版> 2.0,以便点不准
- 红宝石滤波应以“_”代替点和它的伟大工程 - 得到的数据是完全但是ES正确回复提到的错误。我怀疑这个过滤器不会取代事件数据,而只是向事件对象添加一个新的字段。 ES然后仍然读取原始数据而不是更新的数据。
说实话Ruby是一个神奇的给我:)
什么是您使用的ES版本? – Kulasangar
我建议你检查异常:begin event.instance_variable_set(:@ data,remove_dots(event.to_hash)) rescue exception => e event ['logstash_ruby_exception'] ='field dot cleanup:'+ e。消息 结束 –
@Kulasangar我使用ES版本2.3.1。 – adgon92