Specific differences between SPL and SPL2
There are general search and language changes, as well as command and function differences between SPL and SPL2.
Search and language differences
There are differences between SPL and SPL2 in the way you write and use searches. There are also differences that apply to most SPL2 commands.
There are some differences between SPL an SPL2 in the way you write and use searches. There are also differences that apply to most SPL2 commands. Some of these differences are as a result of being able to specify multiple searches in the SPL2 module editor. Other differences are to ensure consistency between the SPL2 commands.
Searches have names
When you use the SPL2 module editor UI to create and run your searches, you must assign a name to each search.
| Feature | Description |
|---|---|
| Branch searches | Create a series of chained searches that branch off of a base search, or create multiple branched searches, in parallel, off of a single base search. For more information, see Branching SPL2 searches in the SPL2 Search Manual. |
| SPL2 views | Use SPL2 views, which are virtual views over physical indexes. For more information, see SPL2 views in the SPL2 Search Manual. |
The search name must follow these guidelines:
-
Start with the dollar sign ( $ ).
-
Use a lowercase letter as the first character after the dollar sign.
-
Be comprised of lowercase letters, numbers, or the underscore character ( _ ). No spaces or special characters are allowed in search names.
-
Be unique within the module.
Searches can be branched to create chained searches
In the SPL2 module editor, a search name is like a variable, which you can refer to in subsequent searches. For example, the name of the following search is $prod_lookup:
$prod_lookup = from main
where sourcetype LIKE "access_%" AND status=200
| lookup products_lookup productID AS productId OUTPUTNEW product_name
| fields productId, product_name
You can use the results of the $prod_lookup search as the dataset for another search. In the other search, you specify the $prod_lookup search name where you would specify the dataset name. For example:
$prod_stats = from $prod_lookup
| stats count() by product_name
For more information and examples, see Branching SPL2 searches in the SPL2 Search Manual.
Lists must be comma-separated
If an SPL2 command needs a list of fields or values, then the list must be comma-separated. In SPL, some commands accept space-separated lists, while other commands require comma-separated lists.
| Version | Example |
|---|---|
| SPL |
|
| SPL2 |
|
Specify command options before command arguments
In SPL, commands were inconsistent about where options were expected in the search syntax. For all SPL2 commands, the command options must be specified before command arguments.
In the following example, bins is the option and the field name, size, is the argument.
| Version | Example |
|---|---|
| SPL |
|
| SPL2 |
|
Here's another example. In this example, the SPL2 dedup command option keepempty must be specified before the list of fields clientip, productId.
$options = search index=main | dedup keepempty=true clientip, productId
Specifying field names might require double quotes
This difference applies to the where and eval commands and the WHERE clause in the from command. It does not apply to the search command in SPL2.
In SPL2, field names that contain anything other than a-z, A-Z, 0-9, or the underscore ( _ ) character must be enclosed in single quotation marks. This includes the wildcard ( * ) and dash ( - ) characters.
| Version | Example |
|---|---|
| SPL |
|
| SPL2 search command |
|
| SPL2 eval and where commands, and the WHERE clause in the from command |
Note: You can perform the same search by moving the eval expression into the SELECT clause in the
from command using either of these formats: |
Specifying string values might require double quotes
This difference applies to the where and eval commands and the WHERE clause in the from command. It does not apply to the search command in SPL2.
String values that contain anything other than a-z, A-Z, 0-9, or the underscore ( _ ) character must be enclosed in double quotation marks. This quotation requirement includes strings that contain the wildcard ( * ) and dash ( - ) characters.
| Version | Example |
|---|---|
| SPL |
|
| SPL2 search command | String values in the SPL2 search command do not need double quotation marks with the SPL2 search command:
|
| SPL2 eval and where commands, and the WHERE clause in the from command |
|
Use eval expressions directly in stats functions
In SPL, you can embed eval expressions and functions in any of the statistical functions. However, in SPL2 eval expressions are supported directly in statistical functions.
| Version | Example |
|---|---|
| SPL |
|
| SPL2 |
|
Concatenation operator is different
In SPL, the concatenation operator is the period ( . ) character. In SPL2, the concatenation operator is the plus ( + ) symbol.
Here's an example:
| Version | Example |
|---|---|
| SPL |
|
| SPL2 |
|
Command differences
There are important differences between the search and from commands in SPL and SPL2.
-
Several of the SPL commands are enhanced in SPL2, such as stats, from, and join.
-
New commands are introduced in SPL2, primarily to support curating and managing data. These include branch, into, ocsf, and thru. These new commands are described in the SPL2 Search Reference.
-
A few SPL commands have been converted to functions in SPL2, such as cluster and tojson. The SPL spath command is supported as a command and as an eval function in SPL2.
Differences using the search command
The search command in SPL2 is similar to the search command in SPL. However, in some situations, the command is not implied at the beginning of a search.
For example, when you use SPL-like syntax in the Search bar, if the first expression in your SPL2 search is anything other than index=<index_name>, you must include the search command at the beginning of the search, such as in searches like search 404 or host=www3.
In the SPL2 module editor, you must always specify the search command after you specify the search name.
The following table illustrates the differences between using the search command in SPL and SPL2:
| Version | Examples |
|---|---|
| SPL |
|
| SPL2 in the Search bar |
|
| SPL2 in the SPL2 module editor |
|
For more information, see search command: Overview and syntax in the SPL2 Search Reference.
Differences using the from command
-
The way you specify a dataset.
-
Support for SQL-like syntax.
With SPL you must qualify the dataset you use with the from command. In SPL2, since the search names in a module must be unique, you don't have to qualify the dataset name that you are using.
The following table shows this difference between SPL and SPL2:
| Version | Example |
|---|---|
| SPL |
|
| SPL2 |
|
The SPL2 from command is like the SQL SELECT command. The SPL2 from command has a flexible syntax, so you can start a search with either the FROM clause or the SELECT clause.
| Start with the FROM clause | Start with the SELECT clause |
|---|---|
|
|
The following SPL2 searches produce the same results. One starts with the SELECT clause and the other starts with the FROM clause:
| Starts with | Example |
|---|---|
| SELECT |
|
| FROM |
|
With the SPL2 from command syntax, you can filter, sort, and select fields without piping to other commands. For example:
| Version | Example |
|---|---|
| SPL |
|
| SPL2 |
|
For more information, see from command: Overview in the SPL2 Search Reference.
Stats command includes a span option
With SPL2, you can specify a time span in the stats command. The field you use in the <by-clause> must be either the _time field, or another field in UNIX time.
| Version | Example |
|---|---|
| SPL | SPL does not support the span option in the stats command. You can use the bin command to specify a span. The SPL equivalent is |
| SPL2 | ...| stats count(error) BY _time span=5min
|
For more information, see stats command: Overview, syntax, and usage in the SPL2 Search Reference.
Case-sensitive searches
In SPL2, there is a case-sensitivity difference between the search and from commands with the values that are returned from a field-value search.
The search command in SPL and SPL2 is not case-sensitive when you use a field=value keyword in your search. This means that when you search for a value like webaccess, field values that are any combination of upper and lower case are returned, such as webAccess, WebAccess, and WEBACCESS.
With the from in SPL2, you use the WHERE clause to specify the field=value keyword, which is case-sensitive. If you search for webaccess, only the field values that are an exact match are returned.
If the field values are not an exact match, the number of search results returned with the from search will be different than the number of results returned by a search command search.
There a workaround for this difference in the from command behavior, see Case-sensitive searches with field-value keywords in the SPL2 Search Reference.
SPL commands converted to SPL2 functions
The following SPL commands are converted to functions in SPL2.
- cluster
- The SPL cluster command is converted to an eval function in SPL2, in the informational functions category.
The SPL2
clusterfunction generates a cluster label, in the form of a number, for each event based on how similar the events are to each other. For more information, see cluster in the SPL2 Search Reference. - spath
- The SPL spath command is available as a command and also as an eval function in SPL2. The
spathfunction is included in the Text functions category.The SPL2
spathfunction extracts information from the structured data formats XML and JSON. For more information, see spath in the SPL2 Search Reference. - tojson
- The SPL tojson command is converted to an eval function in SPL2, in the Conversion functions category.
The SPL2
tojsonfunction returns a JSON object representation of events or search results. For more information, see tojson in the SPL2 Search Reference.
Function differences
SPL2 supports all of the stats and eval functions in SPL. However, a few of the functions have changed and some SPL functions have become literals.
SPL2 supports all of the statistical and evaluation functions in SPL. However, a few of the functions have changed, and some SPL functions have become literals.
Count function
You must include parentheses when using the count function in SPL2, even when no value is specified.
The following table shows examples of using the count function in both SPL and SPL2:
| Version | Example |
|---|---|
| SPL |
|
| SPL2 |
Note: You can perform the same search using the GROUP BY and SELECT clauses in the
from command: |
True function
The true() function is replaced with a literal. Use true instead.
The following table shows examples of using the true function in both SPL and SPL2:
| Version | Example |
|---|---|
| SPL |
|
| SPL2 |
|
False function
The false() function is replaced with a literal. Use false instead.
The following search uses the true, false, and null literals.
$null1 = from prices_lookup
| lookup products_lookup productID AS productId OUTPUTNEW supplierID
| eval onsale = if(case(supplierID="PMG-KOR", true, supplierID="BG-IRE", true, true, false) ,"yes", "no")
| eval show_price = if(onsale="yes", sale_price, null)
Null function
The null() function is replaced with a literal. Use null instead.
The following search uses the true, false, and null literals. In this example, the null literal hides values from certain suppliers.
$null1 = from prices_lookup
| lookup products_lookup productID AS productId OUTPUTNEW supplierID
| eval onsale = if(case(supplierID="PMG-KOR", true, supplierID="BG-IRE", true, true, false) ,"yes", "no")
| eval show_price = if(onsale="yes", sale_price, null)