【发布时间】:2017-01-20 04:03:39
【问题描述】:
我使用 logstash 将我的 Web 服务器日志存储到弹性搜索引擎中。在我的 logstash 配置文件中,我还使用“useragent”插件来获取漂亮的用户代理信息。所以像这样记录到 ES 中:
"message": "157.55.XXX.XXX - - [10/Oct/2016:02:24:27 +0200] "GET /handle/boreal:5621?site_name=BOREAL HTTP/1.1" 301 373 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"",
...
"agent": ""Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)""
"useragent": {
"name": "bingbot",
"os": "Other",
"os_name": "Other",
"device": "Spider",
"major": "2",
"minor": "0"
}
如您所见,此请求来自 Microsoft BingBot 机器人。我检查了所有记录,发现很多机器人访问我的网站:bingbot、googlebot、BaiduSpider、Yahoo!啜饮,...
我现在正试图从我的 ES 响应中排除这些请求。但我没有找到一个优雅的解决方案。由于我是 ES 查询的初学者,您能帮我改进我的请求吗?
{
"size": 0,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must_not": [
{
"regexp": {
"useragent.name": ".*bot.*"
}
}
]
}
}
}
},
"aggs": {
"agent": {
"terms": {
"field": "useragent.name.raw"
}
}
}
}
使用此请求,来自 bingbot、googlebot 或任何其他“stuffbot”的所有请求都将被排除,但“Yahoo! Slurp”、“BaiduSpider”、... 我尝试使用更复杂的正则表达式“(.*bot.*|BaiduSpider|Yahoo! Slurp)”,但百度和雅虎的结果仍然出现在 ES 响应中。
【问题讨论】:
标签: elasticsearch logstash bots