Splunk Search

How can I count the number of field values not present?

crisjnelson
Explorer

I have a set of field values 101,102,103,104,105

Here are sample log events

datetime, val=101
datetime, val=105
datetime, val=103
datetime, val=101
datetime, val=103
datetime, val=105
datetime, val=101

How can I count the number of field values not present?
102 and 104are would not be found from the previous list; 2 field values not found.

0 Karma
1 Solution

niketn
Legend

@crisjnelson, refer to answer by @somesoni2 https://answers.splunk.com/answers/612603/how-to-search-what-values-are-missing-in-my-lookup.html

Add | eval data_source="lookup" to the first search that you have to return all values i.e. 101, 102... 105. Then Add | eval data_source="index" to the second search which may or may not return all the values. Finally perform a stats to keep source as a multi-valued field to perform filter based on whether data is present or not.

Following is run any where search based on data similar to the one in the question. Please replace with your first and second search instead of | makeresult ... | mvexpand

| makeresults
| eval val="101,102,103,104,105"
| makemv val delim=","
| mvexpand val
| eval data_source="lookup"
| append [| makeresults
| eval val="101,102,101,103,102,101,101,101,102,103"
| makemv val delim=","
| mvexpand val
| eval data_source="index"]
| stats count values(data_source) as data_source by val
| search data_source="lookup" AND data_source!="index"
| stats count
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

crisjnelson
Explorer

Wow, that's pretty interesting. Thanks!

0 Karma

niketn
Legend

@crisjnelson, refer to answer by @somesoni2 https://answers.splunk.com/answers/612603/how-to-search-what-values-are-missing-in-my-lookup.html

Add | eval data_source="lookup" to the first search that you have to return all values i.e. 101, 102... 105. Then Add | eval data_source="index" to the second search which may or may not return all the values. Finally perform a stats to keep source as a multi-valued field to perform filter based on whether data is present or not.

Following is run any where search based on data similar to the one in the question. Please replace with your first and second search instead of | makeresult ... | mvexpand

| makeresults
| eval val="101,102,103,104,105"
| makemv val delim=","
| mvexpand val
| eval data_source="lookup"
| append [| makeresults
| eval val="101,102,101,103,102,101,101,101,102,103"
| makemv val delim=","
| mvexpand val
| eval data_source="index"]
| stats count values(data_source) as data_source by val
| search data_source="lookup" AND data_source!="index"
| stats count
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

 Ready to master Kubernetes and cloud monitoring like the pros? Join Splunk’s Growth Engineering team for an ...

Update Your SOAR Apps for Python 3.13: What Community Developers Need to Know

To Community SOAR App Developers - we're reaching out with an important update regarding Python 3.9's ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...