简体   繁体   中英

In Google Cloud's Logs Explorer, how do you query for a key's existence in the jsonPayload dict?

In Google's Cloud Logging query language, is it possible to query for the existence of a particular key in the jsonPayload dict?

Eg, suppose I know the jsonPayload will either be

{'keyA':'<some string>'}

or

{'keyB':'<some string'}

But I don't know what the <some string> will be. I want all logs that have the keyB key. I suppose I could test that for that key having a regex that includes everything, but is that the best/only way?

I want all logs that have the keyB key. I suppose I could test that for that key having a regex that includes everything, but is that the best/only way?

I could think of using Regex for this use case:

Example:

jsonPayload.message =~"Job status: *"  

In your case keyB

jsonPayload.keyB =~"regex-query"

For my example, when the expression matches, getting output as below:

在此处输入图像描述

Use the "has" operator with a *, like

jsonPayload.keyB:*

See the end of https://cloud.google.com/logging/docs/view/logging-query-language#comparisons

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM