This is a Splunk search command that allows you to query an Elasticsearch index and view the results within the Splunk GUI.
- Splunk Enterprise 8.x or later.
- Python 3.7 or later.
- Access to an Elasticsearch cluster.
-
Install Python Dependencies:
This command needs the
elasticsearchandsplunk-sdkPython libraries. You can install them using pip:pip install elasticsearch splunk-sdk
-
Install the Splunk App:
Copy the
search-elasticsearchdirectory to your Splunk apps folder:cp -r search-elasticsearch $SPLUNK_HOME/etc/apps/Alternatively, you can package the
search-elasticsearchdirectory as a.splfile and install it through the Splunk UI. -
Restart Splunk:
After installing the app, you will need to restart your Splunk instance.
You can now use the esearch command in your Splunk search bar.
Basic Example:
| esearch q="some text"
This will search for "some text" in the message field of all indices.
Advanced Example:
| esearch oldest=now-100d earliest=now q="some text" index=nagios* limit=1000 field=message
q: The query string to send to Elasticsearch. (Required)index: The Elasticsearch index to search. (Default:*)limit: The maximum number of records to return. (Default: 100)fields: The field to query in Elasticsearch. (Default:message)oldest: The oldest time for the search range (e.g.,now-1d). (Default:now)earliest: The earliest time for the search range. (Default:now-1d)