35

I'm trying to perform a really simple query on the not so new AWS Cloudwatch Log Insights

I'm following their documentation to filter my logs using ispresent function.

The query is the following:

fields @timestamp, status
| filter ispresent(status) != 0

But this give me an error (the super unhelpful We are having trouble understanding the query)

How can I filter my logs by showing only the logs with the status field?

Gustavo Lopes
  • 3,794
  • 4
  • 17
  • 57

2 Answers2

50

The accepted answer doesn't work for me, but you can now negate ispresent():

fields @timestamp, status
| filter !ispresent(status)
NateH06
  • 3,154
  • 7
  • 32
  • 56
22

After a while, I figured out how to do that, in a hackish way.

fields @timestamp, status, ispresent(status) as exist
| filter exist != 0

Not the best way (and it goes against their documentation), but works.

Gustavo Lopes
  • 3,794
  • 4
  • 17
  • 57
  • 11
    ```fields @timestamp, status | filter ispresent(status)``` - this looks better – ILog Jul 12 '19 at 07:50
  • 1
    It does look better. Though, by the time of the question, it wasn't working.I can't test right now as I don't have any json formatted logs, unfortunately. – Gustavo Lopes Jul 12 '19 at 12:34
  • 1
    Also AWS does not have a good way to negate the `ispresent()` function from within the filter, which this makes up for. Thanks! – hvaughan3 Jul 25 '19 at 03:18