Skip to content

Commit

Permalink
Add REST APIs for IndexTemplateV2Metadata CRUD
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dakrone committed Mar 23, 2020
1 parent ec4c699 commit 1439364
Show file tree
Hide file tree
Showing 19 changed files with 1,337 additions and 3 deletions.
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"
}
}
}
}
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)"
}
}
}
}
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
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
setup:
- 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":

- 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":

- 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":

- do:
indices.get_index_template:
name: test
local: true

- match: {index_templates.0.name: test}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
setup:
- do:
indices.delete_index_template:
name: '*'
ignore: 404
---
"Get missing template":

- do:
catch: missing
indices.get_index_template:
name: test

Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
"Put index template":

- 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":

- 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":

- 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":

- do:
catch: bad_request
indices.put_index_template:
name: test
body: {}
15 changes: 15 additions & 0 deletions server/src/main/java/org/elasticsearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,16 +148,22 @@
import org.elasticsearch.action.admin.indices.stats.TransportIndicesStatsAction;
import org.elasticsearch.action.admin.indices.template.delete.DeleteComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateV2Action;
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteIndexTemplateV2Action;
import org.elasticsearch.action.admin.indices.template.get.GetComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplateV2Action;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesAction;
import org.elasticsearch.action.admin.indices.template.get.TransportGetComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.get.TransportGetIndexTemplateV2Action;
import org.elasticsearch.action.admin.indices.template.get.TransportGetIndexTemplatesAction;
import org.elasticsearch.action.admin.indices.template.put.PutComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateV2Action;
import org.elasticsearch.action.admin.indices.template.put.TransportPutComponentTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction;
import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateV2Action;
import org.elasticsearch.action.admin.indices.upgrade.get.TransportUpgradeStatusAction;
import org.elasticsearch.action.admin.indices.upgrade.get.UpgradeStatusAction;
import org.elasticsearch.action.admin.indices.upgrade.post.TransportUpgradeAction;
Expand Down Expand Up @@ -286,12 +292,14 @@
import org.elasticsearch.rest.action.admin.indices.RestDeleteComponentTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteIndexAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestDeleteIndexTemplateV2Action;
import org.elasticsearch.rest.action.admin.indices.RestFlushAction;
import org.elasticsearch.rest.action.admin.indices.RestForceMergeAction;
import org.elasticsearch.rest.action.admin.indices.RestGetAliasesAction;
import org.elasticsearch.rest.action.admin.indices.RestGetComponentTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestGetFieldMappingAction;
import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateV2Action;
import org.elasticsearch.rest.action.admin.indices.RestGetIndicesAction;
import org.elasticsearch.rest.action.admin.indices.RestGetMappingAction;
import org.elasticsearch.rest.action.admin.indices.RestGetSettingsAction;
Expand All @@ -304,6 +312,7 @@
import org.elasticsearch.rest.action.admin.indices.RestOpenIndexAction;
import org.elasticsearch.rest.action.admin.indices.RestPutComponentTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateV2Action;
import org.elasticsearch.rest.action.admin.indices.RestPutMappingAction;
import org.elasticsearch.rest.action.admin.indices.RestRecoveryAction;
import org.elasticsearch.rest.action.admin.indices.RestRefreshAction;
Expand Down Expand Up @@ -538,6 +547,9 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(PutComponentTemplateAction.INSTANCE, TransportPutComponentTemplateAction.class);
actions.register(GetComponentTemplateAction.INSTANCE, TransportGetComponentTemplateAction.class);
actions.register(DeleteComponentTemplateAction.INSTANCE, TransportDeleteComponentTemplateAction.class);
actions.register(PutIndexTemplateV2Action.INSTANCE, TransportPutIndexTemplateV2Action.class);
actions.register(GetIndexTemplateV2Action.INSTANCE, TransportGetIndexTemplateV2Action.class);
actions.register(DeleteIndexTemplateV2Action.INSTANCE, TransportDeleteIndexTemplateV2Action.class);
}
actions.register(ValidateQueryAction.INSTANCE, TransportValidateQueryAction.class);
actions.register(RefreshAction.INSTANCE, TransportRefreshAction.class);
Expand Down Expand Up @@ -685,6 +697,9 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestPutComponentTemplateAction());
registerHandler.accept(new RestGetComponentTemplateAction());
registerHandler.accept(new RestDeleteComponentTemplateAction());
registerHandler.accept(new RestPutIndexTemplateV2Action());
registerHandler.accept(new RestGetIndexTemplateV2Action());
registerHandler.accept(new RestDeleteIndexTemplateV2Action());
}

registerHandler.accept(new RestPutMappingAction());
Expand Down
Loading

0 comments on commit 1439364

Please sign in to comment.