Splunk Search

Filter events by length of json field

ShagVT
Path Finder

I'm trying put together a query to find some outlier events with very long values within a complex structure.

 

index=myindex sourcetype=jsonfile
| where len('x.y.z{}.field') > 20
| stats count by x.y.z{}.field

 

This is my first stab at how to do this, but it doesn't return any values, even though I know they are there.

Labels (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

I thought this was the same as my struggle with dereferencing JSON paths but it is not.  This has to do with using len() in where command with multivalue.  Here's a working filter:

|where isnotnull(len('x.y.z{}.field') > 20)
|stats count by x.y.z{}.field

Note, however, that count by an array field is not going to work too well if all you care are the values in the array whose length is greater than 20.  In that case you'll have to apply the filter again after stats, like

|where isnotnull(len('x.y.z{}.field') > 20)
|stats count by x.y.z{}.field
|where isnotnull(len('x.y.z{}.field') > 20)

 

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...