Logstash error when converting MySQL value to nested elasticsearch property on suggestion field

时光怂恿深爱的人放手 提交于 2019-12-04 12:46:41

I think you need to proceed differently. First, I would rename the suggestions field in your SQL query to something else and then build the suggestions object from the values you get from your SQL query.

    statement => "SELECT id, suggestion, address_count FROM `suggestions` WHERE id <= 100"

Then you could use a ruby filter (and remove your mutate one) in order to build your suggestions field, like this:

Logstash 2.x code:

ruby {
     code => "
         event['suggestions']['input'] = event['suggestion']
         event['suggestions']['payload']['count'] = event['address_count']
     "
     remove_field => [ 'suggestion', 'address_count' ]
}

Logstash 5.x code:

ruby {
     code => "
         event.set('[suggestions][input]', event.get('suggestion'))
         event.set('[suggestions][payload][count]', event.get('address_count'))
     "
     remove_field => [ 'suggestion', 'address_count' ]
}

PS: All this assumes you're using ES 2.x since the payload field has disappeared in ES 5.x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!