MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Splunk Tutorials: Data Models

A Splunk data model is a knowledge object that gives your event data a structure: datasets with defined constraints and fields. Pivot, the tstats command and data model acceleration all depend on that structure. This page builds on the notes below. It shows how to create a data model and its datasets, add fields, use Instant Pivot, query the model with SPL and accelerate it.

Knowedge Objects that provide the data structure that drives pivot by Admin & Power users

Its kind of of Framework.
Setting=>Data Models=App=>Search & reporting

Data Model 
	Data Sets
		Slices of Data

Instance Pivot
---------------
index=* sourcetype=access* status=404

Visualization => Pivot

Datsets
======================
host=homework

& Create it & Add a field

backupduration
backupvolume
date
destip
level
phyaddr
systemidCode language: PHP (php)

What a data model is and why it matters

A data model maps semantic knowledge about your data at search time. It does not change indexed data. Instead it defines datasets, which are named slices of events selected by constraints, and the fields each dataset exposes. Admin and power users normally build data models. Other users can then create reports and charts in Pivot without writing SPL.

Data models also feed tstats, the Common Information Model (CIM) and Splunk Enterprise Security. When a model is accelerated, searches against it read pre-built summaries, which can be much faster than searching raw events.

LevelWhat it isExample
Data modelA container for related datasets, stored per appHomework
Root datasetTop-level dataset defined by a constraint or searchBackup with constraint host=homework
Child datasetInherits the parent's constraints and fields, then adds its own constraintErrors with level=ERROR
FieldAttribute exposed for Pivot and SPLbackupduration, destip
Root dataset typeDefined byCan be accelerated
Root eventA simple constraint search such as index=main host=homeworkYes, together with its child datasets
Root searchA full search stringOnly if the search uses only streaming commands
Root transactionGrouping of events from other datasetsNo

Corrections to the notes above

  • Knowedge Objects should read Knowledge Objects, and Datsets should read Datasets.
  • Instance Pivot is called Instant Pivot. It turns the results of an ad hoc search into a Pivot without first creating a data model.
  • The path Setting=>Data Models=App=>Search & reporting means: go to Settings > Data models, then set the App filter or app context to Search & Reporting. The model is saved in the app you select.
  • index=* sourcetype=access* status=404 works, but index=* searches every index you have access to. Name the index, for example index=web sourcetype=access_combined status=404, so the search is faster and the resulting data model is more precise.
  • Instant Pivot only works on a search that has no transforming commands (no stats, chart, timechart). Run the search, open the Statistics or Visualization tab and click the Pivot button.

Create a data model and a root dataset

The steps below repeat the host=homework example above with the settings you need to choose.

  1. Go to Settings > Data models and click New Data Model.
  2. Enter a Title (for example Homework) and an ID. The ID may contain only letters, numbers, underscores and hyphens, and it cannot be changed later.
  3. Choose the App (for example Search & Reporting), add a description and click Create.
  4. Click Add Dataset > Root Event. Give it a name such as Backup and set the constraint to index=main host=homework. Use the index that actually holds the data.
  5. Click Preview to confirm that the constraint returns the events you expect, then click Save.

Note: Constraints work like the base search of a dataset. Keep them simple and selective, with index, sourcetype and host, so that the dataset can be accelerated later.

Add fields to the dataset

With the Backup dataset selected, click Add Field. The options are Auto-Extracted (fields Splunk already extracts), Eval Expression, Lookup, Regular Expression and Geo IP. For the fields in the example above, choose Auto-Extracted, tick each field and set its type and flag.

FieldSuggested typeReason
backupdurationNumberLets you use avg, sum and max in Pivot
backupvolumeNumberLets you sum volumes
dateStringUse _time for time-based charts; keep this as a label
destipIPV4Allows IP-aware filtering and Geo IP fields
levelStringUsed for split-by and filters
phyaddrStringMAC address, used as a label
systemidStringIdentifier for row splits

Each field also has a flag. Optional is the default. Required drops events that lack the field. Hidden keeps the field out of Pivot while child datasets and calculations can still use it. Inherited fields _time, host, source and sourcetype are added automatically.

To add a child dataset, select Backup, click Add Dataset > Child and set an extra constraint such as level=ERROR. The child inherits all of the fields above.

Query a data model with SPL

Pivot is not the only way to use a data model. The commands below all read the Homework model and its Backup dataset.

| datamodel Homework Backup search

| from datamodel:"Homework.Backup"
| stats avg(backupduration) by systemid

| tstats count avg(Backup.backupduration) AS avg_duration
    from datamodel=Homework.Backup
    by Backup.systemid

| pivot Homework Backup count(Backup) AS "Backups" SPLITROW systemid AS "System"Code language: PHP (php)
  • datamodel ... search returns the dataset's events, with field names prefixed by the dataset name (for example Backup.systemid).
  • from datamodel: returns the dataset's events so that you can pipe them into normal SPL.
  • tstats is the fastest option. In tstats, dataset fields must be written with the dataset prefix, such as Backup.backupduration. Add summariesonly=true to read only accelerated summaries.
  • pivot is the SPL that the Pivot editor generates. You can paste it into dashboards.

Accelerate the data model

Acceleration builds summaries in the background so that Pivot and tstats searches return quickly over long time ranges. Before you can enable it, change the model's permissions from Private to App or All apps, because private data models cannot be accelerated. Then use Edit > Edit Acceleration, tick Accelerate and choose a Summary Range such as 7 days or 1 month.

The setting is written to datamodels.conf in the app. The model definition itself is stored as JSON under data/models/ in the same app.

# $SPLUNK_HOME/etc/apps/search/local/datamodels.conf
[Homework]
acceleration = true
acceleration.earliest_time = -7dCode language: PHP (php)

Note: Summaries use disk space on the indexers and take CPU time to build. Choose the shortest summary range that covers your reports, and check build status under Settings > Data models by expanding the model's row.

Common problems and fixes

SymptomLikely causeFix
Dataset preview shows no eventsWrong index, or the time range is too narrowAdd the correct index= to the constraint and widen the time picker
Field missing in Add Field > Auto-ExtractedThe field is not extracted at search time for the sample eventsCreate a field extraction first, or add it as a Regular Expression field
Accelerate option is greyed outModel is private, or the dataset is a transaction or non-streaming search datasetShare the model at App level or wider, and use root event datasets
tstats returns nothing for a fieldField name used without the dataset prefixUse Backup.fieldname in tstats
Pivot button missing after a searchThe search contains a transforming commandRemove stats, chart or timechart and run it again

Frequently asked questions

What is the difference between a data model and a dataset in Splunk?

A data model is the container. Datasets are the hierarchical slices of data inside it, each defined by constraints and fields. Pivot and tstats always target a specific dataset within a model.

Do I need to accelerate a data model to use it?

No. Pivot, datamodel, from and tstats all work on unaccelerated models by searching raw events. Acceleration only makes those searches faster, at the cost of disk space and background processing.

What is Instant Pivot in Splunk?

Instant Pivot opens the Pivot editor directly from a non-transforming search, using a temporary data model. If you save the pivot as a report or dashboard panel, Splunk asks you to save that data model.

Why can't I enable acceleration on my data model?

Private data models cannot be accelerated, so share the model at App or global level first. Transaction datasets, and root search datasets that use non-streaming commands, also cannot be accelerated.

How do I reference data model fields in tstats?

Prefix each field with its dataset name, for example tstats count from datamodel=Homework.Backup by Backup.systemid.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals

Related Posts

Splunk Tutorial: Lookup

A Splunk lookup adds fields to your search results by matching a field in each event against a column in an external table, usually a CSV file….

Read More

5-Day Program: Splunk for Email Security, SIEM & Endpoint Security

Program Title Splunk Security Operations Masterclass: Email Security, SIEM & Endpoint Detection Duration 5 DaysRecommended format: 6โ€“7 hours per dayMode: Instructor-led + hands-on labs + final SOC…

Read More

Splunk Tutorials: Splunk Commands Reference

Here’s an updated table with example queries that utilize the respective Splunk commands: Splunk Command Description Example Query (Apache Log) search Retrieves events that match specific search…

Read More

Splunk Tutorials: Windows Query

Rajesh Kumar I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have…

Read More

What is Splunk and How it works? An Overview and Its Use Cases

History & Origin of Splunk Rob Das and Eric Swan co-founded this technology in the year 2003 as a solution to all the questions raised while investigating…

Read More

What is Splunk SIEM and How it works? An Overview and Its Use Cases

History & Origin of Splunk SIEM The Splunk platform removes the barriers between data and action, empowering observability, IT and security teams to ensure their organizations are…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x