Splunk Search

Can you help me with my regex pattern match?

zacksoft
Contributor

Here is my code . I want my field record_type to contain only the events/records that contain either of the keywords

****(index=jar1 sourcetype=toss1  shop AND fruits) OR
   (index=jar2 sourcetype=toss2 shop AND meat) OR
   (index=jar3 sourcetype=toss3 shop AND "green vegetables") 
 | rex "(?<record_type>|fruits|meat|green vegetables)"
 | fields record_type  **<==== It only shows me records of "green vegetables" type****
| eval shopping_time=case(record_type="fruits", _time)  bla bla bla <=== gives me no result because record_type only grabs green vegateble words containing records/events.**

Any suggestion?

I suspect the rex statement needs modification !

0 Karma
1 Solution

sdchakraborty
Contributor

Can you remove the pipe before fruits and try? also use max_match=0 to get all the occurrences.

****(index=jar1 sourcetype=toss1  shop AND fruits) OR
    (index=jar2 sourcetype=toss2 shop AND meat) OR
    (index=jar3 sourcetype=toss3 shop AND "green vegetables") 
  | rex max_match=0 "(?<record_type>fruits|meat|green vegetables)"
  | fields record_type  **<==== It only shows me records of "green vegetables" type****
 | eval shopping_time=case(record_type="fruits", _time)  bla bla bla <=== gives me no result because record_type only grabs green vegateble words containing records/events.**

Sid

View solution in original post

0 Karma

sdchakraborty
Contributor

Can you remove the pipe before fruits and try? also use max_match=0 to get all the occurrences.

****(index=jar1 sourcetype=toss1  shop AND fruits) OR
    (index=jar2 sourcetype=toss2 shop AND meat) OR
    (index=jar3 sourcetype=toss3 shop AND "green vegetables") 
  | rex max_match=0 "(?<record_type>fruits|meat|green vegetables)"
  | fields record_type  **<==== It only shows me records of "green vegetables" type****
 | eval shopping_time=case(record_type="fruits", _time)  bla bla bla <=== gives me no result because record_type only grabs green vegateble words containing records/events.**

Sid

0 Karma

zacksoft
Contributor

Thanks. It helps.

0 Karma

sdchakraborty
Contributor

Cool. Then I will change this as answer. Please accept it.

Sid

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

&#x1f342; Fall into November with a fresh lineup of Community Office Hours, Tech Talks, and Webinars we’ve ...

Transform your security operations with Splunk Enterprise Security

Hi Splunk Community, Splunk Platform has set a great foundation for your security operations. With the ...

Splunk Admins and App Developers | Earn a $35 gift card!

Splunk, in collaboration with ESG (Enterprise Strategy Group) by TechTarget, is excited to announce a ...