Splunk Search

Mismatch with values in Join

tlunruh
New Member

When I run this query:
index=edi-2 | join type=inner TRACKINGNUMBER [search index=edi | rename TRCK AS TRACKINGNUMBER] | stats count(TRACKINGNUMBER) BY STYPE

I get these results:

STYPE count(TRACKINGNUMBER) 01 2140
08 38
10 284
13 1122
22 539
25 349
29 4
32 236

However, if I add this where clause:
index=edi-2 | join type=inner TRACKINGNUMBER [search index=edi | rename TRCK AS TRACKINGNUMBER | where STYPE=08 OR STYPE=29] | stats count(TRACKINGNUMBER) BY STYPE

I get this:

STYPE count(TRACKINGNUMBER)
08 166
29 4572

WTH?? How is that possible? Shouldn't 08 and 29 match up with the first set of results?? What am I missing with this?

Thanks!

Tags (1)
0 Karma

youngc_splunk
Splunk Employee
Splunk Employee

@tlunruh , it looks like your processing EDI data.  We now have solution accelerator for EDI transactions, I would love to share what we have.  Let me know if you're interested.

0 Karma

somesoni2
Revered Legend

With type=inner in join command, you'd see matching records from both the sources (main search and subsearch), hence the result is limited to only the STYPE=08 OR STYPE=29. The joins are very expensive, and you should look for alternative implementation for it.

If you have to use join, use type=left so that all rows from left (main search) will be returned, along with matched ones.

Alternatively, you can use following:

index=edi-2 OR index=edi | eval TRACKINGNUMBER=coalesce(TRACKINGNUMBER, TRCK)
| stats count(TRACKINGNUMBER)  values(index) as indexes BY STYPE

This should give count by STYPE for records in both indexes.
To get records same as | join type=inner, add | where mvcount(indexes)=2 | fields - indexes.
To get records same as | join type=left, add | where NOT mvcount(indexes)=1 AND indexes="edi" | fields - indexes.

tlunruh
New Member

Thanks @somesoni2. I ran your new search and it gave me different data, but I am still not sure it is right. I am sure I am trying to use Splunk JOINs like SQL (which I am very familiar with) and not understanding the overhead/results. What I am really trying to get (for the first pass), is the STYPE from index=edi for each matching TRACKINGNUMBER in index=edi-2.

index=edi has TRCK and STYPE fields; index=edi-2 has TRACKINGNUMBER and DATE fields. I want to JOIN (or use an alternative) the two indexex on TRACKINGNUMBER/TRCK and return the count of STYPE. Does that make sense?

0 Karma
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...