KQL

予早 2025-02-21 01:08:21
Categories: Tags:

Kibana Query Language

在 Kibana 中查询数据使用的语法

分词匹配

查询 response 中包含 500 的结果,取决于分词情况

response : 500

命中结果

http status code is 500

未命中结果

the port is 5001

查询 message 字段中包含 hello 或者 world 的字段

message : hello world

命中结果

hello
HEllo
world hello

未命中结果

helloworld

查询 op_record 中包含user_id is 48613554的结果,user_id is 48613554作为整体查询

ops_record: "user_id is 48613554"

命中结果

user_id is 48613554, user create a article which id is 666
user_id is 48613554, user publish a article which id is 666

未命中结果

user_id 48613554, user delete a article which id is 666

逻辑表达式

优先级,not > and > or ,使用括号指定优先级

name:jane or addr:beijing
name:jane and addr:beijing or job:teacher
name:jane and (addr:beijing or job:teacher)
response:(200 or 404)

会查询出response字段中不包含200的记录。

not response:200

会查询response包含200,并且整条记录不包含yes的数据记录

response:200 and not yes

会查询response包含200,且response不包含yes的记录

response:(200 and not yes)

通配符

会返回所有包含response字段的文档对象

response:*

会查询machine1字段,machine2字段...machinexyzabc字段包含hello的数据记录,这里只是想表达,对于搜索的字段列,也是可以使用通配符

machine*:hello

转义字符

KQL 中使用\():<>"*作为语法的一部分,若要匹配的内容中包含这些字符,在不使用双引号""的情况下,会导致语法错误,需要进行转义。

查询http.request.referrer中包含https://example.com的数据,:需要转义。

http.request.referrer: https\://example.com

可以使用双引号""指明作为一般字符串处理。

http.request.referrer: "https://example.com"

其他资料

https://www.elastic.co/guide/en/kibana/current/kuery-query.html

https://blog.csdn.net/UbuntuTouch/article/details/119174887