我使用的是流利的,我需要在当前记录中添加新标签。此标记的值存在于同一记录中的另一个值中。
示例:
Sample record:
{"xff":null,"host":"0.0.0.1","method":"GET","referer":null,"url_path":"/abcd/attr1=value1&attr2=value2&noOfUsers=123456789&e="}
Expected output is:
{"xff":null,"host":"0.0.0.1","method":"GET","referer":null,"url_path":"/abcd/attr1=value1&attr2=value2&test=123456789&e=","noOfUsers":"123456789"}
如您所见,我将从“url_path”值中获取新标记“noOfUsers”的值。
我搜索了一些信息并得到了详细信息,我应该使用ruby脚本。
我可以知道什么是正确的解决方案以及我应该用什么ruby脚本来实现这个目标?
<filter *.test>
type record_transformer
<record>
?????
</record>
enable_ruby true
</filter>
答案 0 :(得分:0)
试试这个,
require 'cgi'
sample_record = {"xff":nil,"host":"0.0.0.1","method":"GET","referer":nil,"url_path":"/abcd/attr1=value1&attr2=value2&noOfUsers=123456789&e="}
new_noOfUsers = CGI::parse(sample_record[:url_path])["noOfUsers"].first
expected_record = sample_record.merge({ "noOfUsers": new_noOfUsers })
expected_record[:url_path].sub!("noOfUsers", "test")
expected_record