Run federated searches over Amazon S3 datasets
Use SPL2 to write and run federated searches over your Amazon S3 datasets.
Getting started with SPL2
Use SPL2 to write and run federated searches over your Amazon S3 datasets.
SPL2 searches can use SPL-like or SQL-like syntax.
- If you prefer SPL-like syntax, then use the
searchcommand. - If you prefer SQL-like syntax, then use the
fromcommand. This command supports a flexible syntax, so you can choose to start your search using the FROM clause or the SELECT clause.
SPL2 federated searches that use the from command are often more efficient than SPL2 federated searches that use the search command.
If you are new to SPL2, see the SPL2 Overview.
For an introduction to the SPL2 user interfaces, see Searching data using SPL2 in the SPL2 Search Manual.
For detailed information about any of the SPL2 command syntax shown in these examples, refer to the SPL2 Search Reference.
Search and filter data
You can specify field-value pairs in the search or from command to filter for events that contain those combinations of fields and values. You can also specify a time range to filter for events that occurred during that time range.
For information about the supported time range syntax, see Time modifiers in the SPL2 Search Manual.
For example, the following searches return events from an Amazon S3 dataset named my_s3_bucket that pass all of the following filtering conditions:
- The value in the
statusfield is200. - The value in the
hostfield iswww4. - The value in the
actionfield ispurchase. - The timestamp of the event is stored in the
_timefield and indicates that the event happened within the past hour.
| Syntax | Example |
|---|---|
Using the search command |
search index=my_s3_bucket status=200 host=www4 action=purchase earliest=-1h |
Using the from command, starting with the FROM clause |
FROM my_s3_bucket WHERE status=200 AND host="www4" AND action="purchase" AND earliest=-1h |
Using the from command, starting with the SELECT clause |
SELECT * FROM my_s3_bucket WHERE status=200 AND host="www4" AND action="purchase" AND earliest=-1h |
Join two Amazon S3 datasets
You can use the JOIN clause supported in the from command to join two Amazon S3 datasets.
For example, the following searches create an inner join between the customer_id field from the s3_bucket_1 dataset and the cust_id field from the s3_bucket_2 dataset.
| Syntax | Example |
|---|---|
Using the from command, starting with the FROM clause |
FROM s3_bucket_1 AS t1 JOIN s3_bucket_2 AS t2 ON t1.customer_id=t2.cust_id |
Using the from command, starting with the SELECT clause |
SELECT * FROM s3_bucket_1 AS t1 JOIN s3_bucket_2 AS t2 ON t1.customer_id=t2.cust_id |
Aggregate data and update event fields
You can use the stats command or the SELECT and GROUP BY clauses supported in the from command to calculate aggregation statistics. Then you can use the eval command to add a new field to your events.
| Syntax | Example |
|---|---|
Using the search command |
CODE
|
Using the from command, starting with the FROM clause |
CODE
|
Using the from command, starting with the SELECT clause |
CODE
|
from command clause names are shown in uppercase for readability and alignment with SQL syntax. You can specify clause names in uppercase or lowercase. However, you cannot specify clause names in mixed case, such as Group By.