fluentd-docs icon indicating copy to clipboard operation
fluentd-docs copied to clipboard

How to delete a key and keep it's value, the value is an hash

Open sanmingzi opened this issue 8 years ago • 2 comments

input: "params": {"key1": "value1"} output: {"key1": "value1"} This is my use case. Thank you.

sanmingzi avatar Dec 05 '16 04:12 sanmingzi

def filter(tag, time, record)
  if record['params']
    value = record['params']
    record.merge!(value)
    record.delete('params')
  end
end

I write a filter plugin, some code like this. It can work. But I think the method is complex. Any simple solution?

sanmingzi avatar Dec 05 '16 10:12 sanmingzi

def filter(tag, time, record)
  if params.key?("params")
    new_record = record["params"]
    new_record
  else
    record
  end
end

The filter method must return the new modified record or original record.

BTW, record_transformer Filter Plugin is suitable for the purpose.

okkez avatar Sep 27 '18 06:09 okkez