我正在尝试在logstash上使用 Elasticsearch 过滤器以进行一些数据浓缩。
我有两个索引,我的目标是从其中一个获取一些数据,然后将其添加到另一个。
我配置了一个logstash过滤器,该过滤器在我的elasticsearch中进行搜索,如果有匹配项,则输出将进入索引。
但是我的过滤器无法正常工作,因为当我测试过滤器时出现此错误
[WARN ] 2020-10-02 19:23:09.536 [[main]>worker2] elasticsearch - Failed to query elasticsearch for previous event {:index=>"logstash-*", :error=>"Unexpected character ('%' (code 37)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n
我认为模板中的变量和 Elasticsearch 之间存在一些问题我的logtash是7.3.2,而ES是7.4.2
这是我的设置
Logstash.conf
input {
http{ }
}
filter {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "logstash-*"
query_template => "search-by-ip.json"
fields => {
"id" => "[suscriberid]"
}
}
}
output {
stdout { codec => rubydebug }
}
-----------------
search-by-ip.json
{
"size": 1,
"query": { "match":{"IP": %{[ip]} } }
}
-------------------
testcase.sh
curl -XPOST "localhost:8080" -H "Content-Type: application/json" -d '{
"size": 1,
"query": { "match":{"ip": "192.168.1.4" }}
}'
```
Thanks!
最佳答案
如果您处理的事件没有[ip]字段,则不会替换sprintf引用,并且会收到该错误。
请注意,ip和IP是不同的字段。不知道%{[ip]}是否需要在双引号中引起来。
关于elasticsearch - 在Logstash中使用Elasticsearch过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64180931/