如何编写针对多个字符串模式的 AWS Log Insights 查询

问题描述 投票:0回答:2

我想编写一个日志洞察查询来搜索日志组中的多个字符串模式。

我知道我可以使用以下查询来查找日志中的特定字符串:

 fields @timestamp, @message
| filter @message like "test string"
| sort @timestamp desc

但是,我想扩展它以使用正则表达式查找多个字符串模式。

有人可以帮助理解如何实现这一目标。我尝试在互联网上查找并阅读 aws 文档,但不知道该怎么做。

amazon-web-services amazon-cloudwatch amazon-cloudwatchlogs
2个回答
1
投票

当我搜索多个字符串时,我使用以下语法:

  1. 匹配所有同时具有“string1”和“string2”的消息:

    fields @timestamp, @message 
    | filter @message like 'string1' and  @message like 'string2'
    | sort @timestamp desc
    | limit 20```
    
    
  2. 匹配所有具有“string1”或“string2”的消息:

    fields @timestamp, @message
    | filter @message like 'string1' or  @message like 'string2'
    | sort @timestamp desc
    | limit 20```
    

1
投票

使用斜杠而不是引号怎么样?搜索正则表达式模式:

fields @timestamp, @message
| filter @message like /test regex1/ or @message like /test regex2/
| sort @timestamp desc

https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html

© www.soinside.com 2019 - 2025. All rights reserved.