Splunk Search

Clarification regarding search command and stats command

Justin1224
Communicator

Hey everyone,

I'm confused about what the second command in my search does. Here is the whole search:

| useraccounts_tracker | search user_category=default | stats max(lastTime) as _time, values(user_category) as user_category, dc(dest) as dc(dest) by user | sort 100 - _time | fields _time,user,user_category,dc(dest)

Specifically what I'm unsure about:
-What does the search user_category=default command do?
-What does the stats max(lastTime) as _time, values(user_category) as user_category, dc(dest) as dc(dest) by user command do? I know when it says "as" it's renaming fields. So other than that, what is it doing?

Any help would be appreciated!

0 Karma
1 Solution

somesoni2
Revered Legend
| `useraccounts_tracker` --->  generating/fetching data. Need to know the macro definition to know source of the data
| search user_category=default ---> From the fetched data, filtering result which satisfy the filter condition (value of user_category is default
| stats max(lastTime) as _time, values(user_category) as user_category, dc(dest) as dc(dest) by user ----> From the filtered results, generate statistics, group by field user, to get max of field lastTime and rename as field _time, list all uniue values of the field user_category as itself, get distinct count of field dest as field "dc(dest)".
| sort 100 - _time  ---> sort the results from stats command in descending order of field _time and select first 100 records
| fields _time,user,user_category,dc(dest) ---> selecting only the required fields and setting the order of the display.

View solution in original post

somesoni2
Revered Legend
| `useraccounts_tracker` --->  generating/fetching data. Need to know the macro definition to know source of the data
| search user_category=default ---> From the fetched data, filtering result which satisfy the filter condition (value of user_category is default
| stats max(lastTime) as _time, values(user_category) as user_category, dc(dest) as dc(dest) by user ----> From the filtered results, generate statistics, group by field user, to get max of field lastTime and rename as field _time, list all uniue values of the field user_category as itself, get distinct count of field dest as field "dc(dest)".
| sort 100 - _time  ---> sort the results from stats command in descending order of field _time and select first 100 records
| fields _time,user,user_category,dc(dest) ---> selecting only the required fields and setting the order of the display.

Justin1224
Communicator

That helps a lot, thank you!

0 Karma
Get Updates on the Splunk Community!

Splunk Answers Content Calendar, June Edition

Get ready for this week’s post dedicated to Splunk Dashboards! We're celebrating the power of community by ...

What You Read The Most: Splunk Lantern’s Most Popular Articles!

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

See your relevant APM services, dashboards, and alerts in one place with the updated ...

As a Splunk Observability user, you have a lot of data you have to manage, prioritize, and troubleshoot on a ...