在 ELK(Elasticsearch + Logstash + Kibana)中“快速查询日志”,关键在于合理的索引设计 + 高效的查询方式 + Kibana/API 的正确使用。下面按使用场景给你一套实用方法。
适合:日常排障、临时查日志
logstash-*)Last 15 minutes)示例:
level: ERROR and service: order-service
status: 500 and url: "/api/pay"
✅ 比 Lucene 更直观,推荐默认使用 KQL
适合:复杂条件、自动化脚本
GET logstash-*/_search
{
"size": 50,
"query": {
"bool": {
"must": [
{ "match": { "level": "ERROR" } }
],
"filter": [
{ "range": { "@timestamp": { "gte": "now-1h" } } }
]
}
},
"sort": [{ "@timestamp": "desc" }]
}
✅ 使用 filter 不走评分,速度更快
logstash-2026.01.21
logstash-2026.01.22
"_source": ["@timestamp", "level", "message"]
service.keywordstatus(数值)message 做聚合curl -XGET "localhost:9200/logstash-*/_search?q=level:ERROR"
适合运维脚本
search thread pooluser_id: "12345" and level: ERROR
response_time > 1000
host: "node-07"
如果你愿意,可以告诉我:
我可以直接帮你写 最优索引结构 + 查询模板。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。