- Elasticsearch Guide: other versions:
- What is Elasticsearch?
- What’s new in 7.9
- Getting started with Elasticsearch
- Set up Elasticsearch
- Installing Elasticsearch
- Configuring Elasticsearch
- Setting JVM options
- Secure settings
- Auditing settings
- Circuit breaker settings
- Cluster-level shard allocation and routing settings
- Cross-cluster replication settings
- Discovery and cluster formation settings
- Field data cache settings
- HTTP
- Index lifecycle management settings
- Index management settings
- Index recovery settings
- Indexing buffer settings
- License settings
- Local gateway settings
- Logging
- Machine learning settings
- Monitoring settings
- Node
- Network settings
- Node query cache settings
- Search settings
- Security settings
- Shard request cache settings
- Snapshot lifecycle management settings
- Transforms settings
- Transport
- Thread pools
- Watcher settings
- Important Elasticsearch configuration
- Important System Configuration
- Bootstrap Checks
- Heap size check
- File descriptor check
- Memory lock check
- Maximum number of threads check
- Max file size check
- Maximum size virtual memory check
- Maximum map count check
- Client JVM check
- Use serial collector check
- System call filter check
- OnError and OnOutOfMemoryError checks
- Early-access check
- G1GC check
- All permission check
- Discovery configuration check
- Bootstrap Checks for X-Pack
- Starting Elasticsearch
- Stopping Elasticsearch
- Discovery and cluster formation
- Add and remove nodes in your cluster
- Full-cluster restart and rolling restart
- Remote clusters
- Set up X-Pack
- Configuring X-Pack Java Clients
- Plugins
- Upgrade Elasticsearch
- Index modules
- Mapping
- Text analysis
- Overview
- Concepts
- Configure text analysis
- Built-in analyzer reference
- Tokenizer reference
- Token filter reference
- Apostrophe
- ASCII folding
- CJK bigram
- CJK width
- Classic
- Common grams
- Conditional
- Decimal digit
- Delimited payload
- Dictionary decompounder
- Edge n-gram
- Elision
- Fingerprint
- Flatten graph
- Hunspell
- Hyphenation decompounder
- Keep types
- Keep words
- Keyword marker
- Keyword repeat
- KStem
- Length
- Limit token count
- Lowercase
- MinHash
- Multiplexer
- N-gram
- Normalization
- Pattern capture
- Pattern replace
- Phonetic
- Porter stem
- Predicate script
- Remove duplicates
- Reverse
- Shingle
- Snowball
- Stemmer
- Stemmer override
- Stop
- Synonym
- Synonym graph
- Trim
- Truncate
- Unique
- Uppercase
- Word delimiter
- Word delimiter graph
- Character filters reference
- Normalizers
- Index templates
- Data streams
- Ingest node
- Search your data
- Query DSL
- Aggregations
- Bucket Aggregations
- Adjacency matrix
- Auto-interval date histogram
- Children
- Composite
- Date histogram
- Date range
- Diversified sampler
- Filter
- Filters
- Geo-distance
- Geohash grid
- Geotile grid
- Global
- Histogram
- IP range
- Missing
- Nested
- Parent
- Range
- Rare terms
- Reverse nested
- Sampler
- Significant terms
- Significant text
- Terms
- Variable width histogram
- Subtleties of bucketing range fields
- Metrics Aggregations
- Pipeline Aggregations
- Bucket Aggregations
- EQL
- SQL access
- Overview
- Getting Started with SQL
- Conventions and Terminology
- Security
- SQL REST API
- SQL Translate API
- SQL CLI
- SQL JDBC
- SQL ODBC
- SQL Client Applications
- SQL Language
- Functions and Operators
- Comparison Operators
- Logical Operators
- Math Operators
- Cast Operators
- LIKE and RLIKE Operators
- Aggregate Functions
- Grouping Functions
- Date/Time and Interval Functions and Operators
- Full-Text Search Functions
- Mathematical Functions
- String Functions
- Type Conversion Functions
- Geo Functions
- Conditional Functions And Expressions
- System Functions
- Reserved keywords
- SQL Limitations
- Scripting
- ILM: Manage the index lifecycle
- Monitor a cluster
- Frozen indices
- Roll up or transform your data
- Set up a cluster for high availability
- Snapshot and restore
- Secure a cluster
- Overview
- Configuring security
- User authentication
- Built-in users
- Internal users
- Token-based authentication services
- Realms
- Realm chains
- Active Directory user authentication
- File-based user authentication
- LDAP user authentication
- Native user authentication
- OpenID Connect authentication
- PKI user authentication
- SAML authentication
- Kerberos authentication
- Integrating with other authentication systems
- Enabling anonymous access
- Controlling the user cache
- Configuring SAML single-sign-on on the Elastic Stack
- Configuring single sign-on to the Elastic Stack using OpenID Connect
- User authorization
- Built-in roles
- Defining roles
- Granting access to Stack Management features
- Security privileges
- Document level security
- Field level security
- Granting privileges for data streams and index aliases
- Mapping users and groups to roles
- Setting up field and document level security
- Submitting requests on behalf of other users
- Configuring authorization delegation
- Customizing roles and authorization
- Enabling audit logging
- Encrypting communications
- Restricting connections with IP filtering
- Cross cluster search, clients, and integrations
- Tutorial: Getting started with security
- Tutorial: Encrypting communications
- Troubleshooting
- Some settings are not returned via the nodes settings API
- Authorization exceptions
- Users command fails due to extra arguments
- Users are frequently locked out of Active Directory
- Certificate verification fails for curl on Mac
- SSLHandshakeException causes connections to fail
- Common SSL/TLS exceptions
- Common Kerberos exceptions
- Common SAML issues
- Internal Server Error in Kibana
- Setup-passwords command fails due to connection failure
- Failures due to relocation of the configuration files
- Limitations
- Alerting on cluster and index events
- Command line tools
- How To
- Glossary of terms
- REST APIs
- API conventions
- cat APIs
- cat aliases
- cat allocation
- cat anomaly detectors
- cat count
- cat data frame analytics
- cat datafeeds
- cat fielddata
- cat health
- cat indices
- cat master
- cat nodeattrs
- cat nodes
- cat pending tasks
- cat plugins
- cat recovery
- cat repositories
- cat shards
- cat segments
- cat snapshots
- cat task management
- cat templates
- cat thread pool
- cat trained model
- cat transforms
- Cluster APIs
- Cluster allocation explain
- Cluster get settings
- Cluster health
- Cluster reroute
- Cluster state
- Cluster stats
- Cluster update settings
- Nodes feature usage
- Nodes hot threads
- Nodes info
- Nodes reload secure settings
- Nodes stats
- Pending cluster tasks
- Remote cluster info
- Task management
- Voting configuration exclusions
- Cross-cluster replication APIs
- Data stream APIs
- Document APIs
- Enrich APIs
- Explore API
- Index APIs
- Add index alias
- Analyze
- Clear cache
- Clone index
- Close index
- Create index
- Delete index
- Delete index alias
- Delete component template
- Delete index template
- Delete index template (legacy)
- Flush
- Force merge
- Freeze index
- Get component template
- Get field mapping
- Get index
- Get index alias
- Get index settings
- Get index template
- Get index template (legacy)
- Get mapping
- Index alias exists
- Index exists
- Index recovery
- Index segments
- Index shard stores
- Index stats
- Index template exists
- Open index
- Put index template
- Put index template (legacy)
- Put component template
- Put mapping
- Refresh
- Rollover index
- Shrink index
- Simulate index
- Simulate template
- Split index
- Synced flush
- Type exists
- Unfreeze index
- Update index alias
- Update index settings
- Resolve index
- List dangling indices
- Import dangling index
- Delete dangling index
- Index lifecycle management API
- Ingest APIs
- Info API
- Licensing APIs
- Machine learning anomaly detection APIs
- Add events to calendar
- Add jobs to calendar
- Close jobs
- Create jobs
- Create calendar
- Create datafeeds
- Create filter
- Delete calendar
- Delete datafeeds
- Delete events from calendar
- Delete filter
- Delete forecast
- Delete jobs
- Delete jobs from calendar
- Delete model snapshots
- Delete expired data
- Estimate model memory
- Find file structure
- Flush jobs
- Forecast jobs
- Get buckets
- Get calendars
- Get categories
- Get datafeeds
- Get datafeed statistics
- Get influencers
- Get jobs
- Get job statistics
- Get machine learning info
- Get model snapshots
- Get overall buckets
- Get scheduled events
- Get filters
- Get records
- Open jobs
- Post data to jobs
- Preview datafeeds
- Revert model snapshots
- Set upgrade mode
- Start datafeeds
- Stop datafeeds
- Update datafeeds
- Update filter
- Update jobs
- Update model snapshots
- Machine learning data frame analytics APIs
- Create data frame analytics jobs
- Create trained model
- Update data frame analytics jobs
- Delete data frame analytics jobs
- Delete trained model
- Evaluate data frame analytics
- Explain data frame analytics API
- Get data frame analytics jobs
- Get data frame analytics jobs stats
- Get trained model
- Get trained model stats
- Start data frame analytics jobs
- Stop data frame analytics jobs
- Migration APIs
- Reload search analyzers
- Rollup APIs
- Search APIs
- Security APIs
- Authenticate
- Change passwords
- Clear cache
- Clear roles cache
- Clear privileges cache
- Create API keys
- Create or update application privileges
- Create or update role mappings
- Create or update roles
- Create or update users
- Delegate PKI authentication
- Delete application privileges
- Delete role mappings
- Delete roles
- Delete users
- Disable users
- Enable users
- Get API key information
- Get application privileges
- Get builtin privileges
- Get role mappings
- Get roles
- Get token
- Get users
- Grant API keys
- Has privileges
- Invalidate API key
- Invalidate token
- OpenID Connect Prepare Authentication API
- OpenID Connect authenticate API
- OpenID Connect logout API
- SAML prepare authentication API
- SAML authenticate API
- SAML logout API
- SAML invalidate API
- SSL certificate
- Snapshot and restore APIs
- Snapshot lifecycle management API
- Transform APIs
- Usage API
- Watcher APIs
- Definitions
- Breaking changes
- Release notes
- Elasticsearch version 7.9.3
- Elasticsearch version 7.9.2
- Elasticsearch version 7.9.1
- Elasticsearch version 7.9.0
- Elasticsearch version 7.8.1
- Elasticsearch version 7.8.0
- Elasticsearch version 7.7.1
- Elasticsearch version 7.7.0
- Elasticsearch version 7.6.2
- Elasticsearch version 7.6.1
- Elasticsearch version 7.6.0
- Elasticsearch version 7.5.2
- Elasticsearch version 7.5.1
- Elasticsearch version 7.5.0
- Elasticsearch version 7.4.2
- Elasticsearch version 7.4.1
- Elasticsearch version 7.4.0
- Elasticsearch version 7.3.2
- Elasticsearch version 7.3.1
- Elasticsearch version 7.3.0
- Elasticsearch version 7.2.1
- Elasticsearch version 7.2.0
- Elasticsearch version 7.1.1
- Elasticsearch version 7.1.0
- Elasticsearch version 7.0.0
- Elasticsearch version 7.0.0-rc2
- Elasticsearch version 7.0.0-rc1
- Elasticsearch version 7.0.0-beta1
- Elasticsearch version 7.0.0-alpha2
- Elasticsearch version 7.0.0-alpha1
Put index template API
editPut index template API
editCreates or updates an index template. Index templates define settings, mappings, and aliases that can be applied automatically to new indices.
PUT /_index_template/template_1 { "index_patterns" : ["te*"], "priority" : 1, "template": { "settings" : { "number_of_shards" : 2 } } }
Request
editPUT /_index_template/<index-template>
Description
editElasticsearch applies templates to new indices based on an wildcard pattern that matches the index name.
Index templates are applied during data stream or index creation. For data streams, these settings and mappings are applied when the stream’s backing indices are created.
Settings and mappings specified in a create index request override any settings or mappings specified in an index template.
Changes to index templates do not affect existing indices, including the existing backing indices of a data stream.
Comments in index templates
editYou can use C-style /* */ block comments in index templates. You can include comments anywhere in the request body, except before the opening curly bracket.
Path parameters
edit-
<index-template>
- (Required, string) Name of the index template to create.
Query parameters
edit-
create
-
(Optional, Boolean)
If
true
, this request cannot replace or update existing index templates. Defaults tofalse
. -
master_timeout
-
(Optional, time units) Specifies the period of time to wait for
a connection to the master node. If no response is received before the timeout
expires, the request fails and returns an error. Defaults to
30s
.
Request body
edit-
index_patterns
-
(Required, array of strings) Array of wildcard (
*
) expressions used to match the names of data streams and indices during creation.Elasticsearch has built-in index templates for the
metrics-*-*
andlogs-*-*
index patterns, each with a priority of100
. Elastic Agent uses these templates to create data streams. If you use Elastic Agent, assign your index templates a priority lower than100
to avoid an overriding the built-in templates.Otherwise, to avoid accidentally applying the built-in templates, use a non-overlapping index pattern or assign templates with an overlapping pattern a
priority
higher than100
.For example, if you don’t use Elastic Agent and want to create a template for the
logs-*
index pattern, assign your template a priority of200
. This ensures your template is applied instead of the built-in template forlogs-*-*
. -
data_stream
-
(Optional, object) Indicates whether the template is used to create data streams and their backing indices. If so, use an empty object as the argument:
data_stream: { }
.Data streams require a matching index template with a
data_stream
object. See Create an index template. -
template
-
(Optional, object) Template to be applied. It may optionally include an
aliases
,mappings
, orsettings
configuration.Properties of
template
-
aliases
-
(Optional, alias object) Index aliases which include the index. See Update index alias.
You cannot add data streams to an index alias.
-
mappings
-
(Optional, mapping object) Mapping for fields in the index. If specified, this mapping can include:
- Field names
- Field data types
- Mapping parameters
See Mapping.
-
settings
- (Optional, index setting object) Configuration options for the index. See Index Settings.
-
-
composed_of
- (Optional, array of strings) An ordered list of component template names. Component templates are merged in the order specified, meaning that the last component template specified has the highest precedence. See Composing multiple component templates for an example.
-
priority
- (Optional, integer) Priority to determine index template precedence when a new data stream or index is created. The index template with the highest priority is chosen. If no priority is specified the template is treated as though it is of priority 0 (lowest priority). This number is not automatically generated by Elasticsearch.
-
version
- (Optional, integer) Version number used to manage index templates externally. This number is not automatically generated by Elasticsearch.
-
_meta
- (Optional, object) Optional user metadata about the index template. May have any contents. This map is not automatically generated by Elasticsearch.
Examples
editIndex template with index aliases
editYou can include index aliases in an index template.
Multiple matching templates
editIf multiple index templates match the name of a new index or data stream, the template with the highest priority is used. For example:
PUT /_index_template/template_1 { "index_patterns" : ["t*"], "priority" : 0, "template": { "settings" : { "number_of_shards" : 1, "number_of_replicas": 0 }, "mappings" : { "_source" : { "enabled" : false } } } } PUT /_index_template/template_2 { "index_patterns" : ["te*"], "priority" : 1, "template": { "settings" : { "number_of_shards" : 2 }, "mappings" : { "_source" : { "enabled" : true } } } }
For indices that start with te*
, _source
will enabled, and the index will have two primary
shards and one replica, because only template_2
will be applied.
Multiple templates with overlapping index patterns at the same priority are not allowed, and an error will be thrown when attempting to create a template matching an existing index template at identical priorities.
Template versioning
editYou can use the version
parameter to add a version number to an index template.
External systems can use these version numbers to simplify template management.
The version
parameter is optional and not automatically generated or used by Elasticsearch.
To unset a version
, replace the template without specifying one.
PUT /_index_template/template_1 { "index_patterns" : ["foo", "bar"], "priority" : 0, "template": { "settings" : { "number_of_shards" : 1 } }, "version": 123 }
To check the version
, you can use the get index template API.
Template metadata
editYou can use the _meta
parameter to add arbitrary metadata to an index template.
This user-defined object is stored in the cluster state,
so keeping it short is preferrable.
The _meta
parameter is optional and not automatically generated or used by Elasticsearch.
To unset _meta
, replace the template without specifying one.
PUT /_index_template/template_1 { "index_patterns": ["foo", "bar"], "template": { "settings" : { "number_of_shards" : 3 } }, "_meta": { "description": "set number of shards to three", "serialization": { "class": "MyIndexTemplate", "id": 17 } } }
To check the _meta
, you can use the get index template API.
Data stream definition
editTo use an index template for a data stream, the template must include an empty data_stream
object.
Data stream templates are only used for a stream’s backing indices,
they are not applied to regular indices.
See Create an index template.
PUT /_index_template/template_1 { "index_patterns": ["logs-*"], "data_stream": { } }
Composing aliases, mappings, and settings
editWhen multiple component templates are specified in the composed_of
field for an index template,
they are merged in the order specified, meaning that later component templates override earlier
component templates. Any mappings, settings, or aliases from the parent index template are merged
in next. Finally, any configuration on the index request itself is merged.
In this example, the order of the two component templates changes the number of shards for an index:
PUT /_component_template/template_with_2_shards { "template": { "settings": { "index.number_of_shards": 2 } } } PUT /_component_template/template_with_3_shards { "template": { "settings": { "index.number_of_shards": 3 } } } PUT /_index_template/template_1 { "index_patterns": ["t*"], "composed_of": ["template_with_2_shards", "template_with_3_shards"] }
In this case, an index matching t*
will have three primary shards. If the order of composed
templates were reversed, the index would have two primary shards.
Mapping definitions are merged recursively, which means that later mapping components can introduce new field mappings and update the mapping configuration. If a field mapping is already contained in an earlier component, its definition will be completely overwritten by the later one.
This recursive merging strategy applies not only to field mappings, but also root options like
dynamic_templates
and meta
. If an earlier component contains a dynamic_templates
block,
then by default new dynamic_templates
entries are appended onto the end. If an entry already
exists with the same key, then it is overwritten by the new definition.
On this page