Splunk Search

How do I get distinct values for a derived field in a search?

wwhitener
Communicator

Good afternoon all,

I have a datasource that I've used transforms.conf and props.conf to create a "field" derived from a comma-delimited portion of each event. How do I get a list of the distinct values?

For example, if I have three events:

[A, B, C, D]

[D, E, F, G]

[A, G, C, Z]

How do I get a resultset that gives me "A", "B", "C", "D", "E", "F", "G", "Z" and no counts or any other information?

I already have the transforms.conf and props.conf pulling out the values for the "tags", but not a way to say "Here are all of the values for that field". In SQL, I'd use "SELECT DISTINCT TEXT FROM MYTAGS...", but I don't know about the Splunk query values.

1 Solution

Ayn
Legend

http://docs.splunk.com/Documentation/Splunk/4.2.2/SearchReference/CommonStatsFunctions

values(X)   This function returns the list of all distinct values of the field X as a multi-value entry. The order of the values is lexicographical. 

So if the values in your example are extracted as a multi-valued field called, say, "foo", you would do something like:

... | stats values(foo)

View solution in original post

Ayn
Legend

http://docs.splunk.com/Documentation/Splunk/4.2.2/SearchReference/CommonStatsFunctions

values(X)   This function returns the list of all distinct values of the field X as a multi-value entry. The order of the values is lexicographical. 

So if the values in your example are extracted as a multi-valued field called, say, "foo", you would do something like:

... | stats values(foo)

wwhitener
Communicator

I guess I went the wrong way around it then.
source="mysource.log" | stats count by myfield | fields myfield
It was to populate a form dropdown, so ultimately even the "fields" functions is not really needed for what I wanted.
Thanks for the answer! I'll try it your way too.

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...