Splunk Search

Filter Events that show value x and y by one that have matching z

cn250039
Loves-to-Learn Lots

I am searching a source that has events that have FieldA and FieldB.

I need to find which events that have specific FieldA values (x or y) AND matching FieldB values (nonspecific).

My current search is:
Index=source  FieldA IN ("x", "y")

I'm not sure how to filter the results to only show the events that have matching FieldB values.

Labels (5)
0 Karma

richgalloway
SplunkTrust
SplunkTrust

I'm not sure what is meant by "matching FieldB values", but maybe this will get you going in the right direction.

index=source  FieldA IN ("x", "y")
| where FieldA = FieldB
---
If this reply helps you, Karma would be appreciated.
0 Karma

cn250039
Loves-to-Learn Lots

i need events that have FieldA(a, b) and FieldB is the same value for the events....

event123456789
field aaababaaaa
field b121233456

 

index= source FieldA("a","b") will return all events

i want to filter it so that only events that have matching values in FieldB and the values in field a differ

so i would expect events 1, 3, 5, and 6 to return from the table above

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I think I understand now.  Here's how I did that.

 

| makeresults | eval _raw="event fieldA fieldB
1     a      1
2     a      2
3     b      1
4     a      2
5     b      3
6     a      3
7     a      4
8     a      5
9     a      6"
| multikv forceheader=1
```Everything above just creates test data```
```Count the number of events and get a list of all the fieldA's for each fieldB
| eventstats count, values(fieldA) as A_fields by fieldB
```Filter out the singletons```
| where count > 1 AND mvcount(A_fields) > 1
| table event fieldA fieldB

 

---
If this reply helps you, Karma would be appreciated.

cn250039
Loves-to-Learn Lots

did i do this wrong?:

cn250039_0-1638273165863.png

 

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Remove the backticks on the end of the first line.

---
If this reply helps you, Karma would be appreciated.
0 Karma

cn250039
Loves-to-Learn Lots

I did that and it resulted in 0 results. However, i know there is at least 2 events that meet the criteria, both have the same FieldB value and one has FieldA (a) and the other has FieldA (b). I am trying to see if there are any more occurrences.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Run the query one pipe at a time until it breaks.  Then you'll know the problem command.  At each step, verify the results are what you expect.

---
If this reply helps you, Karma would be appreciated.
0 Karma

cn250039
Loves-to-Learn Lots

but i don't know the values in FieldB prior to searching

0 Karma

PickleRick
SplunkTrust
SplunkTrust

If I understand you correctly, you want to match - for example - events having FieldA="x" and FieldB="x" as well as FieldA="y" and FieldB="y" but not FieldA="x" and FieldB="y" or vice versa, right?

FieldA IN ("x","y") FieldB IN ("x","y") | where FieldA=FieldB
0 Karma

cn250039
Loves-to-Learn Lots

i need events that have FieldA(a, b) and FieldB is the same value for the events....

event123456789
field aaababaaaa
field b121233456

 

index= source FieldA("a","b") will return all events

i want to filter it so that only events that have matching values in FieldB and the values in field a differ

so i would expect events 1, 3, 5, and 6 to return from the table above

but i do not know the values for FieldB at the time of search.

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...