mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-05 20:48:22 +00:00
36a3b84fc9
* Default include_type_name to false for get and put mappings. * Default include_type_name to false for get field mappings. * Add a constant for the default include_type_name value. * Default include_type_name to false for get and put index templates. * Default include_type_name to false for create index. * Update create index calls in REST documentation to use include_type_name=true. * Some minor clean-ups around the get index API. * In REST tests, use include_type_name=true by default for index creation. * Make sure to use 'expression == false'. * Clarify the different IndexTemplateMetaData toXContent methods. * Fix FullClusterRestartIT#testSnapshotRestore. * Fix the ml_anomalies_default_mappings test. * Fix GetFieldMappingsResponseTests and GetIndexTemplateResponseTests. We make sure to specify include_type_name=true during xContent parsing, so we continue to test the legacy typed responses. XContent generation for the typeless responses is currently only covered by REST tests, but we will be adding unit test coverage for these as we implement each typeless API in the Java HLRC. This commit also refactors GetMappingsResponse to follow the same appraoch as the other mappings-related responses, where we read include_type_name out of the xContent params, instead of creating a second toXContent method. This gives better consistency in the response parsing code. * Fix more REST tests. * Improve some wording in the create index documentation. * Add a note about types removal in the create index docs. * Fix SmokeTestMonitoringWithSecurityIT#testHTTPExporterWithSSL. * Make sure to mention include_type_name in the REST docs for affected APIs. * Make sure to use 'expression == false' in FullClusterRestartIT. * Mention include_type_name in the REST templates docs.
236 lines
6.5 KiB
Plaintext
236 lines
6.5 KiB
Plaintext
[[indices-templates]]
|
|
== Index Templates
|
|
|
|
Index templates allow you to define templates that will automatically be
|
|
applied when new indices are created. The templates include both
|
|
<<index-modules-settings,settings>> and <<mapping,mappings>>
|
|
and a simple pattern template that controls whether the template should be
|
|
applied to the new index.
|
|
|
|
NOTE: Templates are only applied at index creation time. Changing a template
|
|
will have no impact on existing indices. When using the create index API, the
|
|
settings/mappings defined as part of the create index call will take precedence
|
|
over any matching settings/mappings defined in the template.
|
|
|
|
For example:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
PUT _template/template_1
|
|
{
|
|
"index_patterns": ["te*", "bar*"],
|
|
"settings": {
|
|
"number_of_shards": 1
|
|
},
|
|
"mappings": {
|
|
"_source": {
|
|
"enabled": false
|
|
},
|
|
"properties": {
|
|
"host_name": {
|
|
"type": "keyword"
|
|
},
|
|
"created_at": {
|
|
"type": "date",
|
|
"format": "EEE MMM dd HH:mm:ss Z yyyy"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
// TESTSETUP
|
|
|
|
NOTE: Index templates provide C-style /* */ block comments. Comments are allowed
|
|
everywhere in the JSON document except before the initial opening curly bracket.
|
|
|
|
Defines a template named `template_1`, with a template pattern of `te*` or `bar*`.
|
|
The settings and mappings will be applied to any index name that matches
|
|
the `te*` or `bar*` pattern.
|
|
|
|
It is also possible to include aliases in an index template as follows:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
PUT _template/template_1
|
|
{
|
|
"index_patterns" : ["te*"],
|
|
"settings" : {
|
|
"number_of_shards" : 1
|
|
},
|
|
"aliases" : {
|
|
"alias1" : {},
|
|
"alias2" : {
|
|
"filter" : {
|
|
"term" : {"user" : "kimchy" }
|
|
},
|
|
"routing" : "kimchy"
|
|
},
|
|
"{index}-alias" : {} <1>
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
// TEST[s/^/DELETE _template\/template_1\n/]
|
|
|
|
<1> the `{index}` placeholder in the alias name will be replaced with the
|
|
actual index name that the template gets applied to, during index creation.
|
|
|
|
[float]
|
|
[[delete]]
|
|
=== Deleting a Template
|
|
|
|
Index templates are identified by a name (in the above case
|
|
`template_1`) and can be deleted as well:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
DELETE /_template/template_1
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
[float]
|
|
[[getting]]
|
|
=== Getting templates
|
|
|
|
Index templates are identified by a name (in the above case
|
|
`template_1`) and can be retrieved using the following:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_template/template_1
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
You can also match several templates by using wildcards like:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_template/temp*
|
|
GET /_template/template_1,template_2
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
To get list of all index templates you can run:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_template
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
[float]
|
|
[[indices-templates-exists]]
|
|
=== Template exists
|
|
|
|
Used to check if the template exists or not. For example:
|
|
|
|
[source,js]
|
|
-----------------------------------------------
|
|
HEAD _template/template_1
|
|
-----------------------------------------------
|
|
// CONSOLE
|
|
|
|
The HTTP status code indicates if the template with the given name
|
|
exists or not. Status code `200` means it exists and `404` means
|
|
it does not.
|
|
|
|
NOTE: Before 7.0.0, the 'mappings' definition used to include a type name. Although mappings
|
|
no longer contain a type name by default, you can still use the old format by setting
|
|
the parameter include_type_name. For more details, please see <<removal-of-types>>.
|
|
|
|
[float]
|
|
[[multiple-templates]]
|
|
=== Multiple Templates Matching
|
|
|
|
Multiple index templates can potentially match an index, in this case,
|
|
both the settings and mappings are merged into the final configuration
|
|
of the index. The order of the merging can be controlled using the
|
|
`order` parameter, with lower order being applied first, and higher
|
|
orders overriding them. For example:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
PUT /_template/template_1
|
|
{
|
|
"index_patterns" : ["*"],
|
|
"order" : 0,
|
|
"settings" : {
|
|
"number_of_shards" : 1
|
|
},
|
|
"mappings" : {
|
|
"_source" : { "enabled" : false }
|
|
}
|
|
}
|
|
|
|
PUT /_template/template_2
|
|
{
|
|
"index_patterns" : ["te*"],
|
|
"order" : 1,
|
|
"settings" : {
|
|
"number_of_shards" : 1
|
|
},
|
|
"mappings" : {
|
|
"_source" : { "enabled" : true }
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
// TEST[s/^/DELETE _template\/template_1\n/]
|
|
|
|
The above will disable storing the `_source`, but
|
|
for indices that start with `te*`, `_source` will still be enabled.
|
|
Note, for mappings, the merging is "deep", meaning that specific
|
|
object/property based mappings can easily be added/overridden on higher
|
|
order templates, with lower order templates providing the basis.
|
|
|
|
NOTE: Multiple matching templates with the same order value will
|
|
result in a non-deterministic merging order.
|
|
|
|
[float]
|
|
[[versioning-templates]]
|
|
=== Template Versioning
|
|
|
|
Templates can optionally add a `version` number, which can be any integer value,
|
|
in order to simplify template management by external systems. The `version`
|
|
field is completely optional and it is meant solely for external management of
|
|
templates. To unset a `version`, simply replace the template without specifying
|
|
one.
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
PUT /_template/template_1
|
|
{
|
|
"index_patterns" : ["*"],
|
|
"order" : 0,
|
|
"settings" : {
|
|
"number_of_shards" : 1
|
|
},
|
|
"version": 123
|
|
}
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
|
|
To check the `version`, you can
|
|
<<common-options-response-filtering, filter responses>>
|
|
using `filter_path` to limit the response to just the `version`:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
GET /_template/template_1?filter_path=*.version
|
|
--------------------------------------------------
|
|
// CONSOLE
|
|
// TEST[continued]
|
|
|
|
This should give a small response that makes it both easy and inexpensive to parse:
|
|
|
|
[source,js]
|
|
--------------------------------------------------
|
|
{
|
|
"template_1" : {
|
|
"version" : 123
|
|
}
|
|
}
|
|
--------------------------------------------------
|
|
// TESTRESPONSE
|