forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add REST APIs for IndexTemplateV2Metadata CRUD (elastic#54039)
* Add REST APIs for IndexTemplateV2Metadata CRUD This commit adds the get/put/delete APIs for interacting with the now v2 versions of index templates. These APIs are behind the existing `es.itv2_feature_flag_registered` system property feature flag. Relates to elastic#53101 * Add exceptions for HLRC tests * Add skips for 7.x versions * Use index_template instead of template_v2 in action names * Add test for MetaDataIndexTemplateService.addIndexTemplateV2 * Move removal to static method and add test * Add unit tests for request classes (implement hashCode & equals) Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
2eb079b
commit a81ee6f
Showing
24 changed files
with
1,597 additions
and
4 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.delete_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.delete_index_template":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html", | ||
"description":"Deletes an index template." | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_index_template/{name}", | ||
"methods":[ | ||
"DELETE" | ||
], | ||
"parts":{ | ||
"name":{ | ||
"type":"string", | ||
"description":"The name of the template" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"params":{ | ||
"timeout":{ | ||
"type":"time", | ||
"description":"Explicit operation timeout" | ||
}, | ||
"master_timeout":{ | ||
"type":"time", | ||
"description":"Specify timeout for connection to master" | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
rest-api-spec/src/main/resources/rest-api-spec/api/indices.get_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,45 @@ | ||
{ | ||
"indices.get_index_template":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html", | ||
"description":"Returns an index template." | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_index_template", | ||
"methods":[ | ||
"GET" | ||
] | ||
}, | ||
{ | ||
"path":"/_index_template/{name}", | ||
"methods":[ | ||
"GET" | ||
], | ||
"parts":{ | ||
"name":{ | ||
"type":"list", | ||
"description":"The comma separated names of the index templates" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"params":{ | ||
"flat_settings":{ | ||
"type":"boolean", | ||
"description":"Return settings in flat format (default: false)" | ||
}, | ||
"master_timeout":{ | ||
"type":"time", | ||
"description":"Explicit operation timeout for connection to master node" | ||
}, | ||
"local":{ | ||
"type":"boolean", | ||
"description":"Return local information, do not retrieve the state from master node (default: false)" | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
rest-api-spec/src/main/resources/rest-api-spec/api/indices.put_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,45 @@ | ||
{ | ||
"indices.put_index_template":{ | ||
"documentation":{ | ||
"url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html", | ||
"description":"Creates or updates an index template." | ||
}, | ||
"stability":"stable", | ||
"url":{ | ||
"paths":[ | ||
{ | ||
"path":"/_index_template/{name}", | ||
"methods":[ | ||
"PUT", | ||
"POST" | ||
], | ||
"parts":{ | ||
"name":{ | ||
"type":"string", | ||
"description":"The name of the template" | ||
} | ||
} | ||
} | ||
] | ||
}, | ||
"params":{ | ||
"order":{ | ||
"type":"number", | ||
"description":"The order for this template when merging multiple matching ones (higher numbers are merged later, overriding the lower numbers)" | ||
}, | ||
"create":{ | ||
"type":"boolean", | ||
"description":"Whether the index template should only be added if new or can also replace an existing one", | ||
"default":false | ||
}, | ||
"master_timeout":{ | ||
"type":"time", | ||
"description":"Specify timeout for connection to master" | ||
} | ||
}, | ||
"body":{ | ||
"description":"The template definition", | ||
"required":true | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_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,66 @@ | ||
setup: | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: test | ||
body: | ||
index_patterns: test-* | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
|
||
--- | ||
"Get index template": | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
indices.get_index_template: | ||
name: test | ||
|
||
- match: {index_templates.0.name: test} | ||
- match: {index_templates.0.index_template.index_patterns: ["test-*"]} | ||
- match: {index_templates.0.index_template.template.settings: {index: {number_of_shards: '1', number_of_replicas: '0'}}} | ||
- match: {index_templates.0.index_template.template.mappings: {properties: {field: {type: keyword}}}} | ||
|
||
--- | ||
"Get all tindex emplates": | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: test2 | ||
body: | ||
index_patterns: test2-* | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
|
||
- do: | ||
indices.get_index_template: {} | ||
|
||
- length: {index_templates: 2} | ||
|
||
--- | ||
"Get index template with local flag": | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
indices.get_index_template: | ||
name: test | ||
local: true | ||
|
||
- match: {index_templates.0.name: test} |
20 changes: 20 additions & 0 deletions
20
...-spec/src/main/resources/rest-api-spec/test/indices.get_index_template/20_get_missing.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,20 @@ | ||
setup: | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
indices.delete_index_template: | ||
name: '*' | ||
ignore: 404 | ||
--- | ||
"Get missing template": | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
catch: missing | ||
indices.get_index_template: | ||
name: test | ||
|
112 changes: 112 additions & 0 deletions
112
rest-api-spec/src/main/resources/rest-api-spec/test/indices.put_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,112 @@ | ||
--- | ||
"Put index template": | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: test | ||
body: | ||
index_patterns: test-* | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
|
||
- do: | ||
indices.get_index_template: | ||
name: test | ||
|
||
- match: {index_templates.0.name: "test"} | ||
- match: {index_templates.0.index_template.index_patterns: ["test-*"]} | ||
- match: {index_templates.0.index_template.template.settings.index: {number_of_shards: '1', number_of_replicas: '0'}} | ||
- match: {index_templates.0.index_template.template.mappings: {properties: {field: {type: keyword}}}} | ||
|
||
--- | ||
"Put multiple index templates": | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: test | ||
body: | ||
index_patterns: [test-*, test2-*] | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
mappings: | ||
properties: | ||
field: | ||
type: text | ||
aliases: | ||
test_alias: {} | ||
test_blias: { routing: b } | ||
test_clias: { filter: { term: { user: kimchy }}} | ||
|
||
- do: | ||
indices.get_index_template: | ||
name: test | ||
|
||
- match: {index_templates.0.index_template.index_patterns: ["test-*", "test2-*"]} | ||
- match: {index_templates.0.index_template.template.settings.index: {number_of_shards: '1', number_of_replicas: '0'}} | ||
- match: {index_templates.0.index_template.template.mappings: {properties: {field: {type: text}}}} | ||
- length: {index_templates.0.index_template.template.aliases: 3} | ||
- is_true: index_templates.0.index_template.template.aliases.test_alias | ||
- match: {index_templates.0.index_template.template.aliases.test_blias.index_routing: "b" } | ||
- match: {index_templates.0.index_template.template.aliases.test_blias.search_routing: "b" } | ||
- match: {index_templates.0.index_template.template.aliases.test_clias.filter.term.user: "kimchy" } | ||
|
||
--- | ||
"Put index template with 'create' flag": | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
indices.put_index_template: | ||
name: test2 | ||
body: | ||
index_patterns: test-* | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
|
||
- do: | ||
indices.get_index_template: | ||
name: test2 | ||
|
||
- match: {index_templates.0.index_template.index_patterns: ["test-*"]} | ||
- match: {index_templates.0.index_template.template.settings.index: {number_of_shards: '1', number_of_replicas: '0'}} | ||
|
||
- do: | ||
catch: bad_request | ||
indices.put_index_template: | ||
name: test2 | ||
create: true | ||
body: | ||
index_patterns: test-* | ||
template: | ||
settings: | ||
number_of_shards: 1 | ||
number_of_replicas: 0 | ||
|
||
--- | ||
"Put index template without index_patterns": | ||
- skip: | ||
version: " - 7.7.99" | ||
reason: "index template v2 API unavailable before 7.8" | ||
|
||
- do: | ||
catch: bad_request | ||
indices.put_index_template: | ||
name: test | ||
body: {} |
Oops, something went wrong.