-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use V2 index templates during index creation (#54669)
* Use V2 index templates during index creation This commit changes our index creation code to use (and favor!) V2 index templates during index creation. The creation precedence goes like so, in order of precedence: - Existing source `IndexMetadata` - for example, when recovering from a peer or a shrink/split/clone where index templates should not be applied - A matching V2 index template, if one is found - When a V2 template is found, all component templates (in the `composed_of` field) are applied in the order that they appear, with the index template having the 2nd highest precedence (the create index request always has the top priority when it comes to index settings) - All matching V1 templates (the old style) This also adds index template validation when `PUT`-ing a new v2 index template (because this was required) and ensures that all index and component templates specify *no* top-level mapping type (it is automatically added when the template is added to the cluster state). This does not yet implement fine-grained component template merging of mappings, where we favor merging only a single field's configuration, that will be done in subsequent work. This also keeps the existing hidden index behavior present for v1 templates, where a hidden index will match v2 index templates unless they are global (`*`) templates. Relates to #53101
- Loading branch information
Showing
12 changed files
with
895 additions
and
140 deletions.
There are no files selected for viewing
188 changes: 188 additions & 0 deletions
188
...-spec/src/main/resources/rest-api-spec/test/indices.put_index_template/15_composition.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
--- | ||
"Component and index template composition": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "not yet backported" | ||
|
||
- do: | ||
cluster.put_component_template: | ||
name: ct_low | ||
body: | ||
template: | ||
settings: | ||
number_of_replicas: 1 | ||
mappings: | ||
properties: | ||
field2: | ||
type: text | ||
aliases: | ||
aliasname: | ||
is_write_index: false | ||
|
||
- do: | ||
cluster.put_component_template: | ||
name: ct_high | ||
body: | ||
template: | ||
settings: | ||
index.number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field2: | ||
type: keyword | ||
aliases: | ||
aliasname: | ||
is_write_index: true | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: my-template | ||
body: | ||
index_patterns: ["foo", "bar-*"] | ||
template: | ||
settings: | ||
index.number_of_shards: 2 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
ignore_above: 255 | ||
aliases: | ||
my_alias: {} | ||
aliasname: | ||
filter: | ||
match_all: {} | ||
composed_of: ["ct_low", "ct_high"] | ||
priority: 400 | ||
|
||
- do: | ||
indices.create: | ||
index: bar-baz | ||
body: | ||
settings: | ||
index.priority: 17 | ||
mappings: | ||
properties: | ||
foo: | ||
type: keyword | ||
aliases: | ||
other: {} | ||
|
||
- do: | ||
indices.get: | ||
index: bar-baz | ||
|
||
- match: {bar-baz.settings.index.number_of_shards: "2"} | ||
- match: {bar-baz.settings.index.number_of_replicas: "0"} | ||
- match: {bar-baz.settings.index.priority: "17"} | ||
- match: {bar-baz.mappings.properties.field: {type: keyword, ignore_above: 255}} | ||
- match: {bar-baz.mappings.properties.field2: {type: keyword}} | ||
- match: {bar-baz.mappings.properties.foo: {type: keyword}} | ||
- match: {bar-baz.aliases.aliasname: {filter: {match_all: {}}}} | ||
- match: {bar-baz.aliases.my_alias: {}} | ||
- match: {bar-baz.aliases.other: {}} | ||
|
||
--- | ||
"Index template priority": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "not yet backported" | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: my-template | ||
body: | ||
index_patterns: ["foo", "bar-*"] | ||
template: | ||
settings: | ||
index.number_of_shards: 2 | ||
composed_of: [] | ||
priority: 400 | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: another-template | ||
body: | ||
index_patterns: ["bar-*"] | ||
template: | ||
settings: | ||
index.number_of_shards: 3 | ||
composed_of: [] | ||
priority: 405 | ||
|
||
- do: | ||
indices.create: | ||
index: bar-baz | ||
|
||
- do: | ||
indices.get: | ||
index: bar-baz | ||
|
||
- match: {bar-baz.settings.index.number_of_shards: "3"} | ||
|
||
--- | ||
"Component template only composition": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "not yet backported" | ||
|
||
- do: | ||
cluster.put_component_template: | ||
name: ct_low | ||
body: | ||
template: | ||
aliases: | ||
alias1: {} | ||
|
||
- do: | ||
cluster.put_component_template: | ||
name: ct_high | ||
body: | ||
template: | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: my-template | ||
body: | ||
index_patterns: ["baz*"] | ||
composed_of: ["ct_low", "ct_high"] | ||
|
||
- do: | ||
indices.create: | ||
index: bazfoo | ||
|
||
- do: | ||
indices.get: | ||
index: bazfoo | ||
|
||
- match: {bazfoo.mappings.properties.field: {type: keyword}} | ||
- match: {bazfoo.aliases.alias1: {}} | ||
|
||
--- | ||
"Index template without component templates": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "not yet backported" | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: my-template | ||
body: | ||
index_patterns: ["eggplant"] | ||
template: | ||
settings: | ||
number_of_shards: 3 | ||
|
||
- do: | ||
indices.create: | ||
index: eggplant | ||
|
||
- do: | ||
indices.get: | ||
index: eggplant | ||
|
||
- match: {eggplant.settings.index.number_of_shards: "3"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.