Usage
ElasticSPL allows for dynamic definition of time ranges and token replacements in DSL and Lucene queries.
This is done for both elasticadhoc and elasticquery. To test on how a query is parsed the command elasticparse can be used.
ElasticSPL attempts to extract the queried indexes if provided and adapts the API endpoint to only search the given indexes.
Time Range
To query logs in Elasticsearch in a similar fashion as in Splunk the timerange picker from Splunk searches can be used to add time constraints to DSL queries. This is available for queries regardless of whether the query already contains time constraints.
To enable dynamic time range parsing the query has to be run with timestamp_used set to True and timestamp_field provided.
DSL
- Existing Timestamp
- Existing Match
- Existing Filter
- No Must nor Filter
- Must and Filter
If a DSL query already includes the key defined as timestamp_field the values $earliest$ and $latest$ are replaced with the earliest and latest time of the current Splunk search
| Original | Parsed |
| |
If a DSL query already contains a bool expression an additional filter is added that filters events to the defined timerange
| Original | Parsed |
| |
If a filter expression is found in the query an additional range constraint for the timestamp is added
| Original | Parsed |
| |
If the DSL query does not contain a must nor filter the entire existing query is taken and places within a filter expression. Additionally a range expression for the timestamp is added.
| Original | Parsed |
| |
In case of both must and filter a range expression is added to filter
| Original | Parsed |
| |
Lucene
- Existing Timestamp
- No Existing Timestamp
If a Lucene query already includes the key defined as timestamp_field the values $earliest$ and $latest$ are replaced with the earliest and latest time of the current Splunk search
| Original | Parsed |
| |
If a Lucene query does not contain $earliest$ and $latest$ a statement is added to the query
| Original | Parsed |
| |
ES|QL
- Existing Timestamp
If an ES|QL query already includes the key defined as timestamp_field the values $earliest$ and $latest$ are replaced with the earliest and latest time of the current Splunk search
| Original | Parsed |
| |
Replacements
Replacements can be used to utilise a single query for different cases. As example is it possible to replace a filter for a username dynamically.
Values that are replaced in a DSL query have to be marked as such in surrounding the value with $. The replacements are provided in a key value format. For the given query the replacements are defined as following:
$ip$=120.49.143.213,$response$=503
DSL
| Original | Parsed |
| |
Lucene
| Original | Parsed |
| |
ES|QL
| Original | Parsed |
| |