-
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.
Add template simulation API for simulating template composition (#56842)
This adds an API for simulating template composition with or without an index template. It looks like: ``` POST /_index_template/_simulate/my-template ``` To simulate a template named `my-template` that already exists, or, to simulate a template that does not already exist: ``` POST /_index_template/_simulate { "index_patterns": ["my-index"] "composed_of": ["ct1", "ct2"], } ``` This is related to #55686, which adds an API to simulate composition based on an index name (hence the `_simulate_index` vs `_simulate`). This commit also adds reference documentation for both simulation APIs. Relates to #53101 Resolves #56390 Resolves #56255
- Loading branch information
Showing
12 changed files
with
849 additions
and
45 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
rest-api-spec/src/main/resources/rest-api-spec/api/indices.simulate_template.json
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,51 @@ | ||
{ | ||
"indices.simulate_template":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html", | ||
"description": "Simulate resolving the given template name or body" | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_index_template/_simulate", | ||
"methods":[ | ||
"POST" | ||
] | ||
}, | ||
{ | ||
"path":"/_index_template/_simulate/{name}", | ||
"methods":[ | ||
"POST" | ||
], | ||
"parts":{ | ||
"name":{ | ||
"type":"string", | ||
"description":"The name of the index template" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"params":{ | ||
"create":{ | ||
"type":"boolean", | ||
"description":"Whether the index template we optionally defined in the body should only be dry-run added if new or can also replace an existing one", | ||
"default":false | ||
}, | ||
"cause":{ | ||
"type":"string", | ||
"description":"User defined reason for dry-run creating the new template for simulation purposes", | ||
"default":false | ||
}, | ||
"master_timeout":{ | ||
"type":"time", | ||
"description":"Specify timeout for connection to master" | ||
} | ||
}, | ||
"body":{ | ||
"description":"New index template definition to be simulated, if no index template name is specified", | ||
"required":false | ||
} | ||
} | ||
} |
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
146 changes: 146 additions & 0 deletions
146
rest-api-spec/src/main/resources/rest-api-spec/test/indices.simulate_template/10_basic.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,146 @@ | ||
--- | ||
"Simulate template without a template in the body": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "not yet backported" | ||
features: ["default_shards"] | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: my-template | ||
body: | ||
index_patterns: other | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
|
||
- do: | ||
indices.simulate_template: | ||
name: my-template | ||
|
||
- match: {template.settings.index.number_of_shards: "1"} | ||
- match: {template.settings.index.number_of_replicas: "0"} | ||
- match: {template.mappings.properties.field.type: "keyword"} | ||
- match: {overlapping: []} | ||
|
||
--- | ||
"Simulate index template specifying a new template": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "not yet backported" | ||
features: ["default_shards"] | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: existing_test | ||
body: | ||
index_patterns: te* | ||
priority: 10 | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
|
||
- do: | ||
cluster.put_component_template: | ||
name: ct | ||
body: | ||
template: | ||
settings: | ||
index.number_of_replicas: 2 | ||
mappings: | ||
properties: | ||
ct_field: | ||
type: keyword | ||
|
||
- do: | ||
indices.simulate_template: | ||
body: | ||
index_patterns: te* | ||
priority: 15 | ||
template: | ||
settings: | ||
index.blocks.write: true | ||
aliases: | ||
test_alias: {} | ||
composed_of: ["ct"] | ||
|
||
- match: {template.settings.index.blocks.write: "true"} | ||
- match: {template.settings.index.number_of_replicas: "2"} | ||
- match: {template.mappings.properties.ct_field.type: "keyword"} | ||
- match: {overlapping.0.name: existing_test} | ||
- match: {overlapping.0.index_patterns: ["te*"]} | ||
- length: {template.aliases: 1} | ||
- is_true: template.aliases.test_alias | ||
|
||
--- | ||
"Simulate template matches overlapping V1 and V2 templates": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "not yet backported" | ||
features: ["allowed_warnings", "default_shards"] | ||
|
||
- do: | ||
indices.put_template: | ||
name: v1_template | ||
body: | ||
index_patterns: [t*, t1*] | ||
settings: | ||
number_of_shards: 5 | ||
|
||
- do: | ||
allowed_warnings: | ||
- "index template [v2_template] has index patterns [te*] matching patterns from existing older templates [v1_template] with patterns | ||
(v1_template => [t*, t1*]); this template [v2_template] will take precedence during new index creation" | ||
indices.put_index_template: | ||
name: v2_template | ||
body: | ||
index_patterns: te* | ||
priority: 10 | ||
template: | ||
settings: | ||
number_of_shards: 10 | ||
number_of_replicas: 2 | ||
mappings: | ||
properties: | ||
field: | ||
type: text | ||
|
||
- do: | ||
allowed_warnings: | ||
- "index template [winning_v2_template] has index patterns [te*] matching patterns from existing older templates [v1_template] with patterns | ||
(v1_template => [t*, t1*]); this template [winning_v2_template] will take precedence during new index creation" | ||
indices.put_index_template: | ||
name: winning_v2_template | ||
body: | ||
index_patterns: te* | ||
priority: 20 | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
|
||
- do: | ||
indices.simulate_template: | ||
name: winning_v2_template | ||
|
||
- match: {template.settings.index.number_of_shards: "1"} | ||
- match: {template.settings.index.number_of_replicas: "0"} | ||
- match: {template.mappings.properties.field.type: "keyword"} | ||
- match: {overlapping.0.name: v1_template} | ||
- match: {overlapping.0.index_patterns: ["t*", "t1*"]} | ||
- match: {overlapping.1.name: v2_template} | ||
- match: {overlapping.1.index_patterns: ["te*"]} |
Oops, something went wrong.