Splunk Search

How to count by mvexpand field result

cowmanchiang
Engager

Now I have a table about id and ip, like this.

ID      IP

AA    1.1.1.1

AA    1.1.1.1

AA    1.1.1.2

AA    1.1.1.3

AA    1.1.1.3

AA    1.1.1.3

BB    1.1.2.1

BB    1.1.2.1

BB    1.1.2.1

Because I want to get the result, it will be sorted by totalcount first, like this

ID     IP             count     totalcount

AA   1.1.1.3       3           6

AA   1.1.1.1       2           6

AA   1.1.1.2       1           6

BB   1.1.2.1       3           3

I use "sourcetype="mail" [search sourcetype="mail" | top id | table id] | stats count, values(ip) by id | sort - count | rename count as totalcount | mvexpand ip | table id, ip, totalcount"

It will get

ID     IP             totalcount

AA   1.1.1.3       6

AA   1.1.1.1       6

AA   1.1.1.2       6

BB   1.1.2.1       3

How to get the count by each id, ip?
Thanks.

Tags (1)
0 Karma
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

Probably easier to do:

sourcetype="mail" [search sourcetype="mail" | top id | table id] | stats count by id,ip | eventstats count as totalcount by id

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee

Probably easier to do:

sourcetype="mail" [search sourcetype="mail" | top id | table id] | stats count by id,ip | eventstats count as totalcount by id

cowmanchiang
Engager

Thanks, it's useful to me.
I also edit it to
sourcetype="mail" [search sourcetype="mail" | top id | table id] | stats count by id,ip | eventstats sum(count) as totalcount by id

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...