Splunk Search

Need where clause query to be implemented on specific value

sahil237888
Path Finder

Hi, If anyone can help.
Below is my table which represents volume (count) Country wise. But I want to apply filter like -
If only country_code - US and count > 10 or country_code - PH and count > 30 or country_code - NR and count > 10 ,
then only these country_codes should be visible and for rest all with same value should be visible.

City_Code Count
US 10
FN 5
IN 50
PH 30
MN 4
KL 8
NR 11

So far I have used this query :

index="countries" | bucket span=10m _time
| stats count by country_code

Tags (1)
0 Karma
1 Solution

FrankVl
Ultra Champion

Like this:

index="countries" | bucket span=10m _time
| stats count by country_code
| search (country_code="US" count > 10) OR (country_code="PH" count > 30) OR (country_code="NR" count > 10) OR NOT country_code IN (US,PH,NR)

Note: the IN operator requires Splunk 6.6 or newer.

View solution in original post

0 Karma

jnudell_2
Builder

Hi @sahil237888 ,

I would use a lookup to do this, setting a threshold list for the countries.

Example lookup CSV:


City_Code,Threshold
US,10
PH,30
NR,10

Then you could do the following search:


... [ you search ] ...
| table City_Code Count
| lookup threshold_lookup City_Code OUTPUT Threshold
| fillnull Threshold
| where Count > Threshold

Here is an example of how it would look using dummy events and data:
alt text

0 Karma

FrankVl
Ultra Champion

Very elegant solution 🙂

0 Karma

FrankVl
Ultra Champion

Like this:

index="countries" | bucket span=10m _time
| stats count by country_code
| search (country_code="US" count > 10) OR (country_code="PH" count > 30) OR (country_code="NR" count > 10) OR NOT country_code IN (US,PH,NR)

Note: the IN operator requires Splunk 6.6 or newer.

0 Karma

sahil237888
Path Finder

How can I use * operator with search command or where command - if the country_code is different?

0 Karma

FrankVl
Ultra Champion

I don't really understand your question, can you clarify a bit what you mean?

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, ...