Splunk Search

How to filter the search with the following record

zhanweiw
Explorer

Hi there,

Can I know how to get the record from ver 1.1 by case sensitive excluding record from ver 1.2?

 

Currently I have data like this:

records:

============================================

index=a, ver=1.1, a="halo", b="haha", c="nana"

index=a, ver=1.1, a="testing", b="haha", c="nana"

index=a, ver=1.1, a="halo", b="kaka", c="testing"

 

index=a, ver=1.2, a="halo", b="haha", c="nana"

index=a, ver=1.2, a="lala", b="haha", c="nana"

index=a, ver=1.2, a="halo", b="kaka", c="TESTING"

============================================

 

Result expected:

index=a, ver=1.1, a="testing", b="haha", c="nana"

index=a, ver=1.1, a="halo", b="kaka", c="testing"

 

Is that possible to be done?

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

This is a run anywhere example using your data

| makeresults
| eval x="index=a, ver=1.1, a=\"halo\", b=\"haha\", c=\"nana\"##index=a, ver=1.1, a=\"testing\", b=\"haha\", c=\"nana\"##index=a, ver=1.1, a=\"halo\", b=\"kaka\", c=\"testing\"##index=a, ver=1.2, a=\"halo\", b=\"haha\", c=\"nana\"##index=a, ver=1.2, a=\"lala\", b=\"haha\", c=\"nana\"##index=a, ver=1.2, a=\"halo\", b=\"kaka\", c=\"TESTING\""
| makemv delim="##" x
| mvexpand x
| table x
| rename x as _raw
| extract
| fields - _raw
| stats values(ver) as ver by index a b c
| where ver="1.1" AND mvcount(ver)=1

The last two lines are the ones you want - and this is collapsing the versions for each of the  index/a/b/c combinations and then just checking that ver only contains 1.1

Hope this helps

View solution in original post

0 Karma

zhanweiw
Explorer

Hi bowesmana,

thank you for your answer, it works as expected.

However, I have pushed these records to Splunk database.

If I want to get the data from Splunk database and produce the same result, what query should I form?

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

The last two lines in that example were what you need to use in your query, obviously you will have to tweak the variable names according to your data if they are not as you have indicated.

 

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

This is a run anywhere example using your data

| makeresults
| eval x="index=a, ver=1.1, a=\"halo\", b=\"haha\", c=\"nana\"##index=a, ver=1.1, a=\"testing\", b=\"haha\", c=\"nana\"##index=a, ver=1.1, a=\"halo\", b=\"kaka\", c=\"testing\"##index=a, ver=1.2, a=\"halo\", b=\"haha\", c=\"nana\"##index=a, ver=1.2, a=\"lala\", b=\"haha\", c=\"nana\"##index=a, ver=1.2, a=\"halo\", b=\"kaka\", c=\"TESTING\""
| makemv delim="##" x
| mvexpand x
| table x
| rename x as _raw
| extract
| fields - _raw
| stats values(ver) as ver by index a b c
| where ver="1.1" AND mvcount(ver)=1

The last two lines are the ones you want - and this is collapsing the versions for each of the  index/a/b/c combinations and then just checking that ver only contains 1.1

Hope this helps

0 Karma

zhanweiw
Explorer

Hi Bowesmana,

I understood now.

Thank you for your help.

The last two lines are what I needed:

| stats values(ver) as ver by index a b c

| where ver="1.1" AND mvcount(ver) = 1 

0 Karma
Get Updates on the Splunk Community!

See just what you’ve been missing | Observability tracks at Splunk University

Looking to sharpen your observability skills so you can better understand how to collect and analyze data from ...

Weezer at .conf25? Say it ain’t so!

Hello Splunkers, The countdown to .conf25 is on-and we've just turned up the volume! We're thrilled to ...

How SC4S Makes Suricata Logs Ingestion Simple

Network security monitoring has become increasingly critical for organizations of all sizes. Splunk has ...