forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simulate template composition API _index_template/_simulate_index…
…/{name} (elastic#55686) This adds a new api to simulate matching the given index name against the index templates in the system. The syntax for the new API takes the following form: POST _index_template/_simulate_index/{index_name} { "index_patterns": ["logs-*"], "priority": 15, "template": { "settings": { "number_of_shards": 3 } ... } } Where the body is optional, but we support the entire body used by the PUT _index_template/{name} api. When the body is specified we'll simulate matching the given index against a system that'd have the given index template together with the index templates that exist in the system. The response, in both cases, will return the matching template's resolved settings, mappings and aliases, together with a special field that'll print any overlapping templates and their corresponding index patterns. (cherry picked from commit 1a5845e) Signed-off-by: Andrei Dan <andrei.dan@elastic.co>
- Loading branch information
Showing
14 changed files
with
849 additions
and
23 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
35 changes: 35 additions & 0 deletions
35
rest-api-spec/src/main/resources/rest-api-spec/api/indices.simulate_index_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,35 @@ | ||
{ | ||
"indices.simulate_index_template":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html", | ||
"description": "Simulate matching the given index name against the index templates in the system" | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_index_template/_simulate_index/{name}", | ||
"methods":[ | ||
"POST" | ||
], | ||
"parts":{ | ||
"name":{ | ||
"type":"string", | ||
"description":"The name of the index (it must be a concrete index name)" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"params":{ | ||
"master_timeout":{ | ||
"type":"time", | ||
"description":"Specify timeout for connection to master" | ||
} | ||
}, | ||
"body":{ | ||
"description":"New index template definition, which will be included in the simulation, as if it already exists in the system", | ||
"required":false | ||
} | ||
} | ||
} |
181 changes: 181 additions & 0 deletions
181
...i-spec/src/main/resources/rest-api-spec/test/indices.simulate_index_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,181 @@ | ||
--- | ||
"Simulate index template without new template in the body": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "simulate index template API has not been backported" | ||
features: allowed_warnings | ||
|
||
- do: | ||
allowed_warnings: | ||
- "index template [test] has index patterns [te*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [test] will take precedence during new index creation" | ||
indices.put_index_template: | ||
name: test | ||
body: | ||
index_patterns: te* | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
|
||
- do: | ||
indices.simulate_index_template: | ||
name: test | ||
|
||
- match: {template.settings.index.number_of_shards: "1"} | ||
- match: {template.settings.index.number_of_replicas: "0"} | ||
- match: {template.mappings._doc.properties.field.type: "keyword"} | ||
- match: {overlapping: []} | ||
|
||
--- | ||
"Simulate index template specifying a new template": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "simulate index template API has not been backported" | ||
features: allowed_warnings | ||
|
||
- do: | ||
allowed_warnings: | ||
- "index template [test] has index patterns [te*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [test] will take precedence during new index creation" | ||
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_index_template: | ||
name: test | ||
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._doc.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 index template with index not matching any template": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "simulate index template API has not been backported" | ||
features: allowed_warnings | ||
|
||
- do: | ||
allowed_warnings: | ||
- "index template [test] has index patterns [te*] matching patterns from existing older templates [global] with patterns (global => [*]); this template [test] will take precedence during new index creation" | ||
indices.put_index_template: | ||
name: test | ||
body: | ||
index_patterns: te* | ||
priority: 10 | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
|
||
- do: | ||
indices.simulate_index_template: | ||
name: will_not_match | ||
|
||
- match: {body: null} | ||
|
||
--- | ||
"Simulate index matches overlapping V1 and V2 templates": | ||
- skip: | ||
version: " - 7.99.99" | ||
reason: "simulate index template API has not been backported" | ||
features: allowed_warnings | ||
|
||
- 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_index_template: | ||
name: test | ||
|
||
- match: {template.settings.index.number_of_shards: "1"} | ||
- match: {template.settings.index.number_of_replicas: "0"} | ||
- match: {template.mappings._doc.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*"]} |
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
33 changes: 33 additions & 0 deletions
33
...ava/org/elasticsearch/action/admin/indices/template/post/SimulateIndexTemplateAction.java
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,33 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.indices.template.post; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
public class SimulateIndexTemplateAction extends ActionType<SimulateIndexTemplateResponse> { | ||
|
||
public static final SimulateIndexTemplateAction INSTANCE = new SimulateIndexTemplateAction(); | ||
public static final String NAME = "indices:admin/index_template/simulate_index"; | ||
|
||
private SimulateIndexTemplateAction() { | ||
super(NAME, SimulateIndexTemplateResponse::new); | ||
} | ||
|
||
} |
Oops, something went wrong.