Splunk Search

Need to return a field in a search even if it doesn't exist

anthonycopus
Path Finder

Hi,

I have a problem with a query which runs on an hourly basis as the fields that need to be returned can vary. The simple query is

index="test"  | fields app,action,category | fillnull value="unknown" | stats count by app,action,category

I have one action which contains the category and one without:

{"app": "testapp", "category": "test_cat", "action": "video_view"}
{"app": "testapp2", "action": "social"}

The issue arises as the stats table will not show anything unless the category is present in at least 1 event in the timerange. I.e. if I select a timerange with only the second event here using the query above, I receive no results. I need to receive field, even if only null.

I have also tried the following but it doesn't work:

index="test"  | fields app,action,category  | eval category=if(isnotnull(category),category,NULL)| fillnull value="unknown" | stats count by app,action,category
1 Solution

lukejadamec
Super Champion

Have you tried this?
index="test" app="*" OR action="*" OR category="*" | fillnull value=unknown app action category | stats count by app,action,category

View solution in original post

lukejadamec
Super Champion

Have you tried this?
index="test" app="*" OR action="*" OR category="*" | fillnull value=unknown app action category | stats count by app,action,category

anthonycopus
Path Finder

Thanks, this works perfectly for what I need!

0 Karma

sjscott
Explorer

Worked great. Thanks!

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...