Quick Reference for SPL2 commands

The following commands are supported in SPL2. Use the links in the table to see more details about a command and to access additional examples.

Command Description Example
addinfoAdds fields to each event. These fields contain global, common information about the search.

Example: Adds information about the search to each event in the search results.

appendcolsAppends all of the fields of the subsearch results with the incoming main search results. The subsearch is run first.

Example: Search for "404" events and append the fields in each event to the list of host values returned from the incoming search results.

from main 
| fields host 
| appendcols [search 404]
appendAppends the results of a subsearch to the current results. This command runs only over historical data and does not produce correct results if used in a real-time search.

Example: Looks for events that are purchase actions and appends the results of the top IP addresses by category ID to the current results.

The top command is not supported in SPL2. The subsearch in the append command uses embedded SPL to include top command in the search.

Embedded SPL is a shortcut associated with the spl1 command.

appendpipeAppends the result of the subpipe to the search results. Unlike a subsearch, the subpipe is not run first. The subpipe is run when the search reaches the appendpipe command.

Example: The following example append subtotals for each action across all users.

bin

Example: Return the average for a field for a specific time span. Bin the search results using a 5 minute time span on the _time field. Return the average thruput of each host for each 5 minute time span.

branchProcesses one set of events or search results, in parallel, in two or more branches. Each branch must end with the into command. Example: Read the events in the main index dataset into memory one time. Process the events in two branches using subsearches to determine the most popular hosts and sources.
convertConverts field values in your search results into numerical values.

Example: The following example changes the duration values to seconds for the specified fields.

... | convert dur2sec(xdelay), dur2sec(delay)
decryptUsed in Edge Processor or Ingest Processor pipelines to decrypt encrypted data fields before the data reaches its destination.

For the Edge Processor solution, see Use the decrypt command to decrypt data in the Edge Processor solution in the Use Edge Processors manual.

For the Ingest Processor solution, see Use the decrypt command to decrypt data in the Ingest Processor solution in the Use Ingest Processors manual.

dedupRemoves the events that contain an identical combination of values for the fields that you specify. Example: Remove duplicates of results with the same host value.
evalCalculates an expression and puts the resulting value into a search results field. Example: Create a new field that contains the result of a calculation. Create a new field called velocity in each event. Calculate the velocity by dividing the values in the distance field by the values in the time field.

Example: Use the if function to analyze field values. Create a new field called error in each event. Using the if function, set the value in the error field to OK if the status value is 200. Otherwise set the error field value to Problem.

eventstatsGenerates summary statistics from fields in your events and saves those statistics into a new field. Example: Calculate an average for each distinct value of the date_minute field. The new field avgdur is added to each event with the average value based on its particular value of date_minute.
expandProduces a separate result row for each object in an array that is in a field. Example: Expand the array in the bridges field. Here is the event before the field is expanded:
_timebridges
5 May 2021 2:29:02 PM[{"name":"Tower Bridge","length":801},{"name":"Millennium Bridge","length":1066}]

Here are the results after the expand command is run:

_timebridges
5 May 2021 2:29:02 PM{"name":"Tower Bridge","length":801}
5 May 2021 2:29:02 PM{"name":"Millennium Bridge","length":1066}
fieldsKeeps or removes fields from search results based on the list of fields that you specify. Example: Specify a list of fields to include in the search results. Return only the host and src fields from the search results.
fieldsummaryCalculates summary statistics for one or more fields in your events, displayed as a results table.

Example: Return the summary statistics for all incoming fields.

Example: Return the summary statistics for a specific field.

fillnullReplaces null values with a specified string value. Null values are field values that are missing in some results but present in other results.

Example: The following example fills all empty field values in the host and kbps fields with the string unknown:

flattenConverts the key-value pairs in the object into separate fields in an event. Flattens only the first level of an object. Example: Flattens the values in the bridges object into separate fields.
_timebridgeslengthname
21 Sep 2022 2:34:17 PM[{"name":"Tower Bridge", "length":801}]801Tower Bridge
fromRetrieves data from a dataset, such as an index, metric index, lookup, view, or job.

The from command has a flexible syntax, which enables you to start a search with either the FROM clause or the SELECT clause.

Example: Return data from the main index for the last 5 minutes. Group the results by host. Calculate the sum of the bytes field. Return the sum and the host fields where the sum of the bytes is greater than I MB.
headReturns the first N number of specified results in search order. Example: Stop searching when a null value is encountered. This example returns results while action=purchase or the action field does not exist in the results (null=true). A maximum of 50 results are returned.
intoSends results to a dataset that is writable, a dataset sink. Appends or replaces the dataset sink in the search data pipeline. Example: Append the search results to the mytable dataset, which is a lookup kind of dataset.
iplocationExtracts location information from IP addresses by using 3rd-party databases. Supports IPv4 and IPv6 addresses and subnets that use CIDR notation.

Example: The following example adds information about the IP address to each event:

joinCombines the results from two datasets by using one or more common fields. Example: Join datasets on fields that have the same name. Combine the results from a search with the vendors dataset. The data is joined on the product_id field, which is common to both datasets.
loadlobLoads the results of a previously completed search job, based on the search job ID (sid). The command must be specified at the beginning of a search.

Example: The following example specifies the search ID for the search results that you want to load into a new search.

lookupInvokes field value lookups. Example: Put corresponding information from a lookup dataset into your events.

Append the data returned from your search results with the data in the users lookup dataset using the uid field. For search results that contains a uid field, the value in that field is matched with the uid field in the users lookup dataset. The username and department fields from the users lookup dataset are appended to each search result. If the search results already have the username and department fields, the OUTPUTNEW argument only fills in missing values in those fields.

makemvConverts a single value field into a multivalue field by splitting the values either on a string delimiter or by using a regular expression. You can't use this command on internal fields.

Example: The following example separates values in the senders field using a comma ( , ) as the delimiter:

Example: The following example separates the values in the my_multival field using a regular expression.

makeresultsGenerates the specified number of search results in temporary memory. The results include the _time field. If you don't specify count, one result is generated.

Example: The following example generates 5 events. Using the streamstats and eval commands to create different dates in the _time field:

mstatsAnalyzes metric data by performing statistics on the measurement, metric_name, and dimension fields in metric indexes.

Example: The following example shows how to calculate a single metric grouped by time. This example returns the average value of the aws.ec2.CPUUtilization metric in the mymetricdata metric index. Use the bin command to bucket the results into 30 second time spans.

mvcombineTakes a group of events that are identical except for the specified field, which contains a single value, and combines those events into a single event.

Example: The following example creates a multivalue field from the values in the host field by using the comma as a delimiter:

mvexpandExpands the values of a multivalue field into separate events, one event for each value in the multivalue field. Example: Expand the values in the myfield field.
nomvconverts the values in a multivalue field into one single value. The values are separated using a new line ( "\n ) delimiter.

Example: The following example combines the values in the senders field, which is a multivalue field, into a single value where each value is separated by a new line delimiter.

renameRenames one or more fields. Example: Rename a field with special characters. Rename the ip-add field to IPAddress. Field names that contain anything other than a-z, A-Z, 0-9, or "_", need single-quotation marks.
replaceReplaces field values in your search results with the values that you specify. This command does not replace values in fields generated by stats or eval functions. If you do not specify a field, the value is replaced in all non-generated fields.

Example: The following example changes a value in two fields in the search results, the start_month and end_month fields.

reverseReverses the order of the search results. Example:
rexUse to either extract fields using regular expression named groups, or replace or substitute characters in a field using sed expressions. Example: Extract values from a field using a regex expression. Extract user, app, and SavedSearchName from a field called savedsearch_id in scheduler.log events.

If the contents of the field is savedsearch_id=bob;search;my_saved_search then this rex command syntax extracts user=bob, app=search, and SavedSearchName=my_saved_search.

searchRetrieve events from indexes or filter the results of a previous search command in the pipeline. Example: Search for a field-value pair for a specific source IP, src.

Example: Search for multiple field-value pairs with boolean and comparison operators. This example searches for events with code values of either 10, 29, or 43 and any host that is not "localhost", and an xqp value that is greater than 5.

select See the from command. The SELECT clause is part of the from command. Example: Calculate the sum of the bytes field. Return the sum and the host fields from the main index for the last 5 minutes. Group the results by host.
sortSorts all of the results by the specified fields. Example: Sort the results first by the surname field in ascending order and then by the firstname field in descending order.
spathExtracts information from the XML and JSON structured data formats.

Example: The following example shows how to specify an output field and path with a wildcard for JSON data:

spl1Embed all or part of an SPL search into an SPL2 search. The spl1 command supports two syntaxes: backtick ( ` ) character syntax and explicit spl1 command syntax. Example: Consider this SPL search:

Embed this search into an SPL2 search using the backtick ( ` ) character syntax:

Example: In this SPL2 search only the portion of the search not supported by SPL2, the addinfo command, uses the backtick ( ` ) character syntax:

statsCalculates aggregate statistics such as average, count, and sum, over the results set. Example: Take the incoming result set and calculate the sum of the bytes field and groups the sums by the values in the host field.
streamstatsAdds a cumulative statistical value to each search result as each result is processed. Example: Use a BY clause to add a running count to search results. This search uses the host field to reset the count. For each search result, a new field is appended with a count of the results based on the host value. The count is cumulative and includes the current result.
tableReturns a table that is formed from the fields that you specify. Columns are displayed in the same order that the fields are specified in.

Example: The following example returns a table with only the host and action fields.

tagsAdds fields to your search results with information about the tags found for those results. To use this command, the tags must already exist.

Example: The following example creates a field called mytags and returns the tags for only the host and clientip fields. The tag information will include the field name associated with the tag. The field list must be specified after the other parameters.

thruWrites data to a writeable dataset and then passes the same data to the next command in the search string. By default, the thru command appends data to the dataset. Example: Append all the incoming search result set to the actions dataset. Those same search results are also passed into the eval command.
timechartCreates a time series chart with corresponding table of statistics. Example: For each minute, calculate the average value of the CPU field for each host.
timewrapCompare data over a specific time period, such as day-over-day or month-over-month, or multiple time periods, such as a 2 week period over another 2 week period. Example: Display a timechart that has a span of 1 day for each count in a week over week comparison table. Each table column, which is the series, is 1 week of time.
tstatsSearches on indexed fields in tsidx files using statistical functions. The indexed fields can be from indexed data or accelerated data models.

Example: The following example specifies only the required parameters. Aggregates must be enclosed in square brackets ( [ ] ). However, because no indexes are specified, the search performs a count of the fields for all of the indexes in the module.

typerCreates an eventtype field for search results that match known event types. The event types must already exist to use this command.

Example: The following example returns only events with the successful purchases event type and limits the number of characters to search each event to 300.

unionMerges the results from two or more datasets into one dataset. One dataset can be piped into the union command and merged with a second dataset. Example: Merge events from the customers, orders, and vendors datasets. You must separate the dataset names with a comma.

Example: Append the current results of the main search with the tabular results of errors from the subsearch.

untableConverts tabular information into individual rows of results. The untable command is useful for preparing your data for a chart.

Example: The following example adds the untable command to the previous example and converts the results from the stats command.

whereFilters search results based on the outcome of a Boolean expression. Example: Use the like comparison operator with the percent symbol ( % ) as a wildcard. This example returns all results where the ipaddress field contains values that start with "192.".

Example: Compare one field to another field.

Example: Filter using a field-value pair.