Splunk Search

Multiple Values for One Tag - Only Want to Display One

alylanchester
Explorer

Hi,

I've tagged my data by location, and I am now trying to run stats on it.

Problem is a location can be Manual or Automated and relate to Bank 1 or Bank 2.

The issue I have is when running a stats, I get:

Manual Bank 1
Manual Bank 2
Automated Bank 1
Automated Bank 2

Whereas all I want to look at is Manual vs. Automated banks. Is there a way of only displaying certain tags?
If I put tag::XX!= then it doesn't run the search as the field values are tagged as both.

Thanks 🙂

0 Karma
1 Solution

woodcock
Esteemed Legend

You must be very, VERY careful when counting by tags. If an event has more than 1 tag (and that is almost always the case in every splunk deployment at least some of the time), that event will be counted more than once (once for each tag value). In any case, I would do it the way that you are and then sum it up at the end by adding this to the bottom:

... | rex field=mytag "^(?<mode>\S+)"
| stats sum(count) BY mode

That being said, I would to back and redo your tags to have 2: one for mode (which is either Automatic or Manual and one for Bank which is a number).

View solution in original post

woodcock
Esteemed Legend

You must be very, VERY careful when counting by tags. If an event has more than 1 tag (and that is almost always the case in every splunk deployment at least some of the time), that event will be counted more than once (once for each tag value). In any case, I would do it the way that you are and then sum it up at the end by adding this to the bottom:

... | rex field=mytag "^(?<mode>\S+)"
| stats sum(count) BY mode

That being said, I would to back and redo your tags to have 2: one for mode (which is either Automatic or Manual and one for Bank which is a number).

alylanchester
Explorer

Thanks! Yes, didn't know if there was a way of filtering tags out so only some remained active in the field set.

woodcock
Esteemed Legend

Yes, there is, you can use mvfilter for this.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi alylanchester,
create an eval field with your condition to use in your stats, e.g.

your_search
| eval type=if(location="Manual*", "Manual","Automatic")
| stats count by type

Bye.
Giuseppe

0 Karma

alylanchester
Explorer

There are 9999+ locations, we have tagged them all which is why I ask, instead of doing an Eval.

0 Karma
Get Updates on the Splunk Community!

Observability Unlocked: Kubernetes Monitoring with Splunk Observability Cloud

 Ready to master Kubernetes and cloud monitoring like the pros? Join Splunk’s Growth Engineering team for an ...

Update Your SOAR Apps for Python 3.13: What Community Developers Need to Know

To Community SOAR App Developers - we're reaching out with an important update regarding Python 3.9's ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...