docs.splunk.com/Documentation/Splunk/7.2.0/SearchReference/SQLtoSplunk
Splunk SPL for SQL users - Splunk Documentation
Download topic as PDF Splunk SPL for SQL users This is not a perfect mapping between SQL and Splunk Search Processing Language (SPL), but if you are familiar with SQL, this quick comparison might be helpful as a jump-start into using the search commands. C
docs.splunk.com
SQL command |
SQL Example |
Splunk SPL example |
SELECT * |
SELECT * FROM mytable |
source=mytable |
WHERE |
SELECT * |
source=mytable mycolumn=5 |
SELECT |
SELECT mycolumn1, mycolumn2 |
source=mytable |
AND/OR |
SELECT * |
source=mytable Note: The AND operator is implied in SPL and does not need to be specified. For this example you could also use:
|
AS (alias) |
SELECT mycolumn AS column_alias |
source=mytable |
BETWEEN |
SELECT * |
source=mytable |
GROUP BY |
SELECT mycolumn, avg(mycolumn) |
source=mytable mycolumn=value Several commands use a by-clause to group information, including chart, rare, sort, stats, and timechart. |
HAVING |
SELECT mycolumn, avg(mycolumn) |
source=mytable mycolumn=value |
LIKE |
SELECT * |
source=mytable Note: The most common search in Splunk SPL is nearly impossible in SQL - to search all fields for a substring. The following SPL search returns all rows that contain "some text" anywhere: |
ORDER BY |
SELECT * |
source=mytable In SPL you use a negative sign ( - ) in front of a field name to sort in descending order. |
SELECT DISTINCT |
SELECT DISTINCT |
source=mytable |
SELECT TOP |
SELECT TOP(5) |
Source=mytable1 mycolum3="bar" |
INNER JOIN |
SELECT * |
index=myIndex1 OR index=myIndex2 Note: There are two other methods to join tables:
... | LOOKUP myvaluelookup
source=mytable1 If the columns that you want to join on have different names, use the rename command to rename one of the columns. For example, to rename the column in mytable2:
To rename the column in myindex1:
You can rename a column regardless of whether you use the search command, a lookup, or a subsearch. |
LEFT (OUTER) JOIN |
SELECT * |
source=mytable1 |
SELECT INTO |
SELECT * |
source=old_mytable Note: COLLECT is typically used to store expensively calculated fields back into your Splunk deployment so that future access is much faster. This current example is atypical but shown for comparison to the SQL command. The source will be renamed orig_source |
TRUNCATE TABLE |
TRUNCATE TABLE mytable |
source=mytable |
INSERT INTO |
INSERT INTO mytable |
Note: see SELECT INTO. Individual records are not added via the search language, but can be added via the API if need be. |
UNION |
SELECT mycolumn |
source=mytable1 |
UNION ALL |
|
source=mytable1 |
DELETE |
DELETE FROM mytable |
source=mytable1 mycolumn=5 |
UPDATE |
UPDATE mytable |
Note: There are a few things to think about when updating records in Splunk Enterprise. First, you can just add the new values to your Splunk deployment (see INSERT INTO) and not worry about deleting the old values, because Splunk software always returns the most recent results first. Second, on retrieval, you can always de-duplicate the results to ensure only the latest values are used (see SELECT DISTINCT). Finally, you can actually delete the old records (see DELETE). |
'통합로그 SIEM > Splunk' 카테고리의 다른 글
[Splunk] free trial (0) | 2021.12.16 |
---|