Splunk Search

Convert single row with list of ids to a table and join it with another table

elad
Engager

I have this query:

 

my search

| rex field=line ".*customerId\":(?<customer_id>[0-9]+)"

| dedup customer_id

| table customer_id 

 

That returns multiple rows and generate a table:

 

customer_id
-----------
1
2
3
4
5

 

I also have another query  that returns a single row with an array  of ids:

 

Synced accounts: [ 1, 3, 5 ]

 

My questions are :

1) How can I convert the row from query 2 into a table with the ids 

2) how can I do left join between the results ( that I will see on the table only the ids from query 2)?

 

customer_id
----------
1
3
5

 

Thanks in advance 

Elad

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

You would have to do two rex

| rex "Synced accounts: \[(?<customer_ids>[^\]]+)\]"
| rex field=customer_ids max_match=0 "(?<customer_id>\d+)"

View solution in original post

0 Karma

elad
Engager

@PickleRick please see the example I provided:  

Synced accounts: [ 1, 3, 5 ]
0 Karma

PickleRick
SplunkTrust
SplunkTrust

But is it a single string value, a multivalued field, something else?

0 Karma

elad
Engager

Please see @ITWhisperer answer - it does a group regex for the row and then convert it to multiple events with mvexpand

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
my search
| rex field=line ".*customerId\":(?<customer_id>[0-9]+)"
| dedup customer_id
| table customer_id 
| join type=left customer_id [ your other search
  | rex max_match=0 "(?<customer_id>\d+)"
  | mvexpand customer_id
  | table customer_id]
0 Karma

elad
Engager

@ITWhisperer thanks this was exactly what I was looking for.  But I have another issue now - the full row actually is something like : 

 

 

Synced accounts: [1,3,5], Deleted accounts: [2,4]

 

 

 

How can I make the regex ignore the groups on the deleted accounts list?

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You would have to do two rex

| rex "Synced accounts: \[(?<customer_ids>[^\]]+)\]"
| rex field=customer_ids max_match=0 "(?<customer_id>\d+)"
0 Karma

elad
Engager

Amazing thanks!

0 Karma

PickleRick
SplunkTrust
SplunkTrust

What do you mean by "array"?

And are you sure you want a left join? It looks  more like inner join.

0 Karma
Get Updates on the Splunk Community!

Index This | When is October more than just the tenth month?

October 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What’s New & Next in Splunk SOAR

 Security teams today are dealing with more alerts, more tools, and more pressure than ever.  Join us for an ...