Smooth operator | Searching for multiple field values | Splunk (2024)

Searching for different values in the same field has been made easier. Thank you Splunk!

For example, suppose in the "error_code" field that you want to locate only the codes 400, 402, 404, and 406.

It is really tedious to have to type field-value pair after field-value pair just to search for a list of values in the same field. But that's exactly what you had to do before version 6.6.0. You had to specify each field-value pair as a separate OR condition.

 ...error_code=400 OR error_code=402 OR error_code=404 OR error_code=406...


Using IN with the search command

One of the best improvements made to the search command is the IN operator. With the IN operator, you can specify the field and a list of values. For example:

 ... error_code IN (400, 402, 404, 406) | ...


Because the search command is implied at the beginning of a search string, all you need to specify is the field name and a list of values. The syntax is simple:

 field IN (value1, value2, ...)

Note: The IN operator must be in uppercase.You can also use a wildcard in the value list to search for similar values. For example:

 ... error_code IN (40*) | ...


This search looks at the error_code field in your events and returns any event with a code that begins with 40.

How cool is that !

With the search command this capability is referred to as the "IN operator". With the eval and where commands, it is implemented as the "IN function".

Using IN with the eval and where commands

To use IN with the eval and where commands, you must use IN as an eval function. The Splunk documentation calls it the "in function".

And the syntax and usage are slightly different than with the search command.

  • The IN function returns TRUE if one of the values in the list matches a value in the field you specify.
  • String values must be enclosed in quotation marks.
  • You cannot specify wildcard characters to search for similar values, such as HTTP error codes or CIDR IP address ranges.


Here are the supported syntax options:

 ...| eval new_field=if(IN(field,"value1","value2", ...), "value_if_true","value_if_false")
...| where field IN("value1","value2", ...)
...| where IN(field,"value1","value2", ...)


Note: The IN function, unlike the IN operator, can be specified in upper or lowercase. The IN function is shown in this blog in uppercase in the syntax and examples for clarity.

Let's start with the where command because it is fairly straight-forward.

The following example uses the where command to return IN=TRUE if one of the values in the status field matches one of the values in the list. The values in the status field are HTTP status codes. Because the codes are string values (not numeric values), you must enclose each value in quotation marks.

 ... | where status IN("400", "401", "403", "404", "406")


You could also specify this example as:

 ... | where IN(status,"400", "401", "403", "404", "406")


Using the IN function with the eval command is different than using IN with the where command. The eval command cannot accept Boolean values, you must use the IN function inside another function that can process the Boolean values returned by the IN function.

Let's go through an example where you can use the IN function as the first parameter for the IF function. We'll use the access.log file that is included with the Search Tutorial data.

In the following example, the IN function is used with the IF function to evaluate the action field. Then the stats command performs a calculation.

 sourcetype=access_combined_wcookie
| eval activity=if(IN(action, "addtocart","purchase"),"Purchase Related","Other")
| stats count by activity


Here is what this search is doing:

  • The eval command creates a new field called activity.
  • If the action field in an event contains the value addtocart or purchase, the value Purchase Related is placed in the activity field.
  • If the action field in an event contains any other value, the value Other is placed in the activity field.
  • The stats command counts the Purchase Related and Other values in the activity field.


The results appear on the Statistics tab and show the counts for how many events have Purchase Related activity and how many have Other types of activity.

Smooth operator | Searching for multiple field values | Splunk (1)This results table is great. You can also show the results in a chart. Switch to the Visualization tab and change the chart type to Pie Chart.

Smooth operator | Searching for multiple field values | Splunk (2)

You can save this search as a dashboard panel or a report.

Resources

See the following Splunk documentation for more information:

Smooth operator | Searching for multiple field values | Splunk (3)

Splunk

The world’s leading organizations trustSplunkto help keep their digital systems secure and reliable. Our software solutions and services help to prevent major issues, absorb shocks and accelerate transformation. Learnwhat Splunk doesandwhy customers choose Splunk.

Smooth operator | Searching for multiple field values | Splunk (2024)
Top Articles
The Bloody (and Haunted) History of the Missouri State Penitentiary
Prison Tours | Missouri State Penitentiary
Swissport Timecard
Words With Friends Cheat Board Layout 11X11
Yale College Confidential 2027
Is Whitney Williams Wgem Married
Royal Bazaar Farmers Market Tuckernuck Drive Richmond Va
Best Taq 56 Loadout Mw2 Ranked
Nazir Afzal on the BBC: ‘Powerful predators were allowed to behave terribly on an industrial level’
Mileage To Walmart
What is international trade and explain its types?
Poochies Liquor Store
Top Scorers Transfermarkt
Lesson 10 Homework 5.3
Apple Store Location
Bailu Game8
2023 GMC Yukon Price, Cost-to-Own, Reviews & More | Kelley Blue Book
Mobile Maher Terminal
Violent Night Showtimes Near The Riviera Cinema
North Colonie Continuing Education
Creigs List Maine
Ghostbusters Afterlife 123Movies
Restaurants Near Defy Trampoline Park
Disney Cruise Line
Springfield Ma Craigslist
Snow Rider Unblocked 67
Community Q&A with Red Flight and the Combat Box server
Toonily.cim
Littleton U Pull Inventory
Quattrocento, Italienische Kunst des 15. Jahrhunderts
South Park Old Fashioned Gif
Kathy Carrack
Craigslist Labor Gigs Albuquerque
Stellaris Resolution
Black Adam Showtimes Near Cinergy Amarillo
Snowy Hydro Truck Jobs in All Sydney NSW - Sep 2024 | SEEK
Horseheads Schooltool
Mudae Disable Tags
Colonial Interceptor
Sayuri Pilkey
Game On Classroom 6X
Jcp Meevo Com
Connie Mason - Book Series In Order
Download Diablo 2 From Blizzard
Katopunk Pegging
Souvenir Shopping and Local Markets in Belgium
Ucla Outlook Web Access
How To Get Genji Cute Spray
8 Internet Celebrities who fell prey to Leaked Video Scandals
Cargurus Button Girl
Latest Posts
Article information

Author: Geoffrey Lueilwitz

Last Updated:

Views: 5490

Rating: 5 / 5 (60 voted)

Reviews: 91% of readers found this page helpful

Author information

Name: Geoffrey Lueilwitz

Birthday: 1997-03-23

Address: 74183 Thomas Course, Port Micheal, OK 55446-1529

Phone: +13408645881558

Job: Global Representative

Hobby: Sailing, Vehicle restoration, Rowing, Ghost hunting, Scrapbooking, Rugby, Board sports

Introduction: My name is Geoffrey Lueilwitz, I am a zealous, encouraging, sparkling, enchanting, graceful, faithful, nice person who loves writing and wants to share my knowledge and understanding with you.