Splunk Search
Highlighted

Group By optional fields in splunk

I am trying the following search. EXECUTED, TRANSLATIONUID, DOCUMENTTYPE are present in the logs but MAPTYPE and MAPNAME are not yet added. They will be added later. The search should work without them and MAPTYPE, MAPNAME should get added to the group by list once they are in the logs.

...| stats  sum(EXECUTED) as Total_Time, count as Num_of_Executions, avg(EXECUTED) as Avg_exectime, perc80(EXECUTED) as 80th_percentile BY TRANSLATION_UID,DOCUMENT_TYPE, MAP_TYPE*,MAP_NAME* 

I tried the above seeing the following search for adding optional fields as follows:

table Total_Time,Num_of_Executions,MAP_TYPE* MAP_NAME* TRANSLATION_UID DOCUMENT_TYPE

It works. But when I added '*' to fields in group by list it does not work. Thanks for your help in advance!!

Tags (2)
0 Karma
Highlighted

Re: Group By optional fields in splunk

Motivator

In general, the wildcard represents all the fields that are present. If the field is not present, as in your example, then the wildcard cannot represent it.

That said, I want to understand your question further. When you say you "added '*' to fields in group by list" do you mean your search now ends in the following:

...BY TRANSLATIONUID,DOCUMENTTYPE,MAPTYPE,MAPNAME,*

or did you replace the entire list of field names with just the wildcard?

0 Karma
Highlighted

Re: Group By optional fields in splunk

The following worked for me:

stats values(MAPTYPE) as MAPTYPE, values(MAPNAME) as MAPNAME, sum(EXECUTED) as TotalTime, count as NumofExecutions, avg(EXECUTED) as Avgexectime, perc80(EXECUTED) as 80thpercentile BY TRANSLATIONUID,DOCUMENT_TYPE.

This worked for me only because there is a one to one mapping between the other Group by fields and MAPTYPE,MAPNAME. Due to this the values() converted the duplicates to a single value. Else this solution would not have worked.

0 Karma
Highlighted

Re: Group By optional fields in splunk

Legend

In the table command, if you list fields that do not exist, the existing fields are still listed.

In the stats command, if you try to group by fields that do not exist, you will get no results.

You need to change your search

...| stats  sum(EXECUTED) as Total_Time, count as Num_of_Executions, avg(EXECUTED) as Avg_exectime, perc80(EXECUTED) as 80th_percentile BY TRANSLATION_UID,DOCUMENT_TYPE