1

I want to write a log insights query to search for multiple string patterns in log groups.

I know that I can use the following query to find a specific string in logs :

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

But, I want to extend this to find multiple string patterns with regular expressions.

Can someone help to understand how to achieve this. I tried looking in internet and reading aws document but could not figure out how to do.

Sushil
  • 8,250
  • 3
  • 39
  • 71

2 Answers2

1

How about using slashes, rather than quotes. That searches a regex pattern:

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

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

Lode
  • 13
  • 3
1

I use the bellow syntax when I search for multiple strings:

  1. Match all messages that have both 'string1' and 'string2':

    fields @timestamp, @message 
    | filter @message like 'string1' and  @message like 'string2'
    | sort @timestamp desc
    | limit 20```
    
    
  2. Match all messages that have either 'string1' or 'string2':

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