Splunk Search

need to update values of a lookup search by count

pkharbanda1021
Engager

Splunk Query
index="abc" source=def
[| inputlookup ABC.csv | table text_strings count | rename text_strings as search]

Problem: 
I need to count the text_string values but when I run the above search which searches the text_strings but I dont find a field called search with which I can count 

So need help
@somesoni2 if you can help please

Labels (1)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

It looks like it is your filtering search - try it this way

index="abc" source=def
[| inputlookup ABC.csv | table text_strings | rename text_strings as query]
| append
  [| inputlookup ABC.csv
  | stats values(text_strings) as text_strings]
| table _raw text_strings
| eventstats values(text_strings) as text_strings
| where isnotnull(_raw)
| eval text_strings=mvmap(text_strings,if(match(_raw,text_strings),text_strings,null())
| eval count=mvcount(text_strings)

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Does index="abc" source=def already contain fields called search and count?

0 Karma

pkharbanda1021
Engager

NO the field comes via lookup column which I am converting to search so that it can search keywords in splunk but I wanted to use that field and i dont see in the data but search works.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

If the fields don't exist in the events found in the index, perhaps that is why the search can't find them?

0 Karma

pkharbanda1021
Engager

I am not sure if you are following what I am saying 
let me explain
I have a lookup which has 2 columns 
Col1=xyz col2=count
xyz has values which I want to search in my data and that works fine and searches the keywords via lookup without the field existing in the data by converting into search ...goal is I need to count those results by search keywords which is what I am trying to solve.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

If I am understanding you correctly, your search is finding all the events which have at least one match to the keywords (Col1 from your lookup)? Now you want to find the count (Col2 from your lookup) associated with the first keyword that each event matched to? Or do you want to find all the possible matches of keywords with their associated counts? Or, do you want to count the number of matches from the lookup that each event matches?

0 Karma

pkharbanda1021
Engager

last one 
count the number of matches from the lookup that each event matches

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

This has the potential for memory explosion and you may need to do this multiple times with different subsets of your lookup depending on the size of the lookup. Essentially, for every event, you add (using eventstats) a multivalue field with the full (or partial) contents of your lookup file, then you filter the field based on whether _raw (or whatever field you are look to compare with) matches each of the values in the mvfield, and finally count the number of matching strings that are left. This even has the bonus of identifying what the matches were.

index="abc" source=def
[| inputlookup ABC.csv | table text_strings | rename text_strings as search]
| append
  [| inputlookup ABC.csv
  | stats values(text_strings) as text_strings]
| table _raw text_strings
| eventstats values(text_strings) as text_strings
| where isnotnull(_raw)
| eval text_strings=mvmap(text_strings,if(match(_raw,text_strings),text_strings,null())
| eval count=mvcount(text_strings)

 

0 Karma

pkharbanda1021
Engager

this solves for one value only but when you have multiple values in your table like 

text_string 

value1
value2 
value3 

this will always pick the top value and shows the count where as the goal is to count all values/counts then overwrite the table with outputlookup ...I tried with 2 values and it only picks the first one and removes the otherone.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

This is the count you asked for

last one 
count the number of matches from the lookup that each event matches

0 Karma

pkharbanda1021
Engager

I agree but the whole point of lookup is to have multiple values and when you run the above query with even 2 values in the lookup table this wont give you the right result.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

It looks like it is your filtering search - try it this way

index="abc" source=def
[| inputlookup ABC.csv | table text_strings | rename text_strings as query]
| append
  [| inputlookup ABC.csv
  | stats values(text_strings) as text_strings]
| table _raw text_strings
| eventstats values(text_strings) as text_strings
| where isnotnull(_raw)
| eval text_strings=mvmap(text_strings,if(match(_raw,text_strings),text_strings,null())
| eval count=mvcount(text_strings)
0 Karma

pkharbanda1021
Engager

I found a small issue after changing the search to query its not returning any results for keywords which has special characters and regex in that like 

"* not found"
and similar 
I believe query is unformatted search in terms of splunk please let confirm if I am wrong. @ITWhisperer  

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Well you could try not having the filter on the search and instead filter later based on the mvcounts being non-zero

0 Karma

pkharbanda1021
Engager

Apologies for reaching out again ...couple of things 
I verified by running individual searches for the strings with regex like "* not found" and I found results so I tweaked the query but it seems like match function doesnt like the keyword and not returning any result. 

Please let me know if there is way to get it to work..thank you for your help !!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

"* not found" is not a wildcard search in regex. You don't need the *. Match will find the remaining string anywhere in the field. Actually, so would search. Can you remove the * from your list of strings?

0 Karma

pkharbanda1021
Engager

that works ..thank you so much !!

 

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!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...