Create search-based visualizations with ds.search
Ad hoc searches created in the UI are of the data source type ds.search. To use a saved search, see Use reports and saved searches with ds.savedSearch.
You can specify the time range for your data sources using the UI or by directly updating the source code.
When editing a data source with the UI, you can choose to use the following:
- Any time range input on the page
- A static time range, such as the last 7 days, regardless of other input selections.
- Dashboard default time range
When editing the data source in the source code, the ds.search data source is assigned a unique ID when you create a search string in the Configuration panel. You can find the associated source code stanza by locating the unique ID. The stanza contains the data source type and any configured options.
The only option that must return events is the query option, which is an SPL search.
index=_internal | head 500
"dataSources": {
"BCsearch": {
"type": "ds.search",
"options": {
"query": "index=_internal | head 500",
"queryParameters": {
"earliest": "0",
"latest": ""
}
}
}
},
The following is an example of a visualization using BCsearch as the primary dataSource .
"visualizations": {
"viz_Example": {
"type": "splunk.table",
"options": {},
"dataSources": {
"primary": "BCsearch"
}
}
},
The visualization must also appear in the layout. The following is a complete dashboard example using the 2 previous stanzas:
{
"title": "Example",
"description": "",
"inputs": {},
"defaults": {
"visualizations": {
"global": {
"showLastUpdated": true
}
}
},
"visualizations": {
"viz_Example": {
"dataSources": {
"primary": "BCsearch"
},
"options": {},
"type": "splunk.table"
}
},
"dataSources": {
"BCsearch": {
"options": {
"query": "index=_internal | head 500",
"queryParameters": {
"earliest": "0",
"latest": ""
}
},
"type": "ds.search"
}
},
"layout": {
"globalInputs": [],
"layoutDefinitions": {
"layout_1": {
"options": {
"width": 1801
},
"structure": [
{
"item": "viz_Example",
"position": {
"h": 600,
"w": 1270,
"x": 10,
"y": 50
},
"type": "block"
}
],
"type": "absolute"
}
},
"tabs": {
"items": [
{
"label": "New tab",
"layoutId": "layout_1"
}
]
}
}
}
The resulting table visualization looks similar to this:
Modify the time range for a data source
By default, the default global time range picker controls all data sources that power visualizations on a dashboard. You can modify set time ranges for individual data sources and override the global time range picker. Because it's an input, you can also delete or modify the default global time range picker. To learn how to use data source options that affect the time range, for example, queryParameters, see Data source options. To read about the time range pickers, see Time range.
Set the event sampling ratio
By default, a Splunk search retrieves all events. However in some situations you might want to retrieve a sample set of events, instead of retrieving the entire event set, such as to determine the characteristics of a large data set without processing every event. See Event sampling.
The default sample ratio for a data source is 1, meaning that the search retrieves all events with no sampling applied. You can specify a sample ratio using the Event Sampling option. For example, if the sample ratio value is 100, each event has a 1 in 100 chance of being included in the result set.
sampleRatio option. The following shows the source code for a data source where the event sampling ratio is 1:100.
{
"name": "Model usage by team",
"options": {
"query": "index=\"buttercup_enterprises_ai\" | stats count by team model_name | where count > 0 | table model_name team count | sort -value",
"queryParameters": {
"sampleRatio": "100"
}
},
"type": "ds.search"
}
Limitations to search based dashboards
Dashboards with many searches and exceeding 7,000 characters in the Uniform Resource Identifier (URI) do not consistently load and might remain in a "waiting on data" state. A large URI might exceed the limit of various server software used with the Splunk platform, such as NGINX.