弹性搜索DSL查询将日志消息与启动和结束文本匹配
日志消息如下所示,
The application node ABC is down
The application node BCD is down
The application node XXX is down
我编写了以下查询,但是它不起作用,
"query": {
"must": {
"match": {
"log_message": {
"query": "The application node /[A-Z]*/ is down"
}
}
}
"filter":{
"term": {
"application": "XYZ"
}
}
}
如何编写DSL查询将这些消息与应用程序名称上的过滤器一起匹配。
The log messages are like below
The application node ABC is down
The application node BCD is down
The application node XXX is down
I have written the following query but it is not working
"query": {
"must": {
"match": {
"log_message": {
"query": "The application node /[A-Z]*/ is down"
}
}
}
"filter":{
"term": {
"application": "XYZ"
}
}
}
How to write a DSL query to match these messages along with filter on application name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一点,因为您尚未给出考虑
log_message
的索引映射,定义为文本
在没有任何分析器的情况下键入字段。因此,它将考虑log_message
字段的默认标准
分析仪。在这里,您的正则模式
/[az]*/
在索引时将所有令牌转换为standard
分析仪将所有令牌转换为plowsect
。您可以阅读有关标准分析仪。您可以替换图案,例如`/[az]*/point,
匹配
查询不支持REGEX模式。您可以使用query_string
Elasticsearch的查询类型,如下所示:最佳解决方案:
如果您的用例与节点名称和应用程序名称的查询匹配,则可以使用node或down等节点的状态,则可以使用 grok pattern with ingest管道并将其存储为单独的值并将其用于查询。
以下是日志消息的示例grok模式(您可以根据各种日志模式进行修改):
上面,grok模式将给出以下结果:
示例摄入管道:
您可以在索引文档时使用以下管道:
输出文档:
您可以使用:您可以使用以下查询以获取有关特定节点的数据,该节点已下降:
The first point, as you have not given index mapping considering
log_message
is defined astext
type field without any analyzer. So it will consider defaultstandard
analyzer forlog_message
field.Here, your regex pattern
/[A-Z]*/
will not work asstandard
analyzer convert all tokens intolowercase
while indexing. You can read about standard analyzer here. You can replace your pattern like `/[a-z]*/Second Point,
match
query not support regex pattern. You can usequery_string
type of query of Elasticsearch as shown below:Best Solution:
If your use case to match the query on node name and application name with status of node like running or down then you can get this information from message field using grok pattern with ingest pipeline and stored as separate value and use it to query.
Below is sample grok pattern for your log message (you can modified based on your various log pattern):
Above, grok pattern will give below result:
Sample Ingest Pipeline:
You can use pipeline like below while indexing document:
Output Document:
You can use below query to get data for specific node which is down: