如何访问/解决 Logstash 上的嵌套字段

How to access / address nested fields on Logstash

我目前正在尝试使用 Logstash 过滤器将包含十六进制字符串的嵌套子字段转换为 int 类型字段

ruby{
    code => 'event.set("[transactions][gasprice_int]", event.get("[transactions][gasPrice]").to_i(16))'
  }

但返回错误

[ERROR][logstash.filters.ruby    ][main][2342d24206691f4db46a60285e910d102a6310e78cf8af43c9a2f1a1d66f58a8] Ruby exception occurred: wrong number of arguments calling `to_i` (given 1, expected 0)

我还尝试使用

遍历交易字段中的 json 个对象
transactions_num = event.get("[transactions]").size
      transactions_num.times do |index|
        event.set("[transactions][#{index}][gasprice_int]", event.get("[transactions][#{index}][gasPrice].to_i(16)"))
      end

但这也返回了

的错误
[ERROR][logstash.filters.ruby    ][main][99b05fdb6022cc15b0f97ba10cabb3e7c1a8fabb8e0c47d6660861badffdb28e] Ruby exception occurred: Invalid FieldReference: `[transactions][0][gasPrice].to_i(16)`

这种使用 ruby 过滤器将十六进制字符串转换为 int 类型的方法在我不处理嵌套字段时有效,所以任何人都可以帮助我如何在这种情况下正确处理嵌套字段?

顺便说一句,

这是仍然有效的代码

ruby {
    code => 'event.set("difficulty_int", event.get("difficulty").to_i(16))'
  }

我想您已经在最后一个示例中自己回答了这个问题 - to_i 不应放在双引号内。所以

...event.get("[transactions][#{index}][gasPrice].to_i(16)"))

应该是

...event.get("[transactions][#{index}][gasPrice]").to_i(16))