我需要从字符串中提取数值并存储在新字段中。我们可以通过脚本字段来完成吗?
Ex:1 hello 3 test
我需要提取1和3。
答案 0 :(得分:0)
如果您使用的是弹性搜索,则可以通过logstash执行此操作。
使用类似
的配置运行logstash进程input {
elasticsearch {
hosts => "your_host"
index => "your_index"
query => "{ "query": { "match_all": {} } }"
}
}
filter {
grok {
match => { "your_string_field" => "%{NUMBER:num1} %{GREEDYDATA:middle_stuff} %{NUMBER:num2} %{GREEDYDATA:other_stuff}" }
}
mutate {
remove_field => ["middle_stuff", "other_stuff"]
}
}
output{
elasticsearch {
host => "yourhost"
index => "your index"
document_id => %{id}
}
}
这实际上会覆盖索引中的每个文档,还有两个字段num1和num2,它们对应于您要查找的数字。这只是一种快速而肮脏的方法,会占用更多内存,但可以让您一次完成所有分解,而不是在可视化时间。
我确信有一种方法可以使用脚本执行此操作,查看groovy正则表达式匹配,返回特定组。
也不能保证我的配置代表是正确的,因为我现在没时间测试它。
祝你有个美好的一天!