diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java
index 7b1e3f1c24580..a0b83cb36ee5d 100644
--- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java
@@ -49,6 +49,7 @@
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import org.elasticsearch.client.indices.DeleteAliasRequest;
+import org.elasticsearch.client.indices.DeleteIndexTemplateV2Request;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
@@ -56,10 +57,14 @@
import org.elasticsearch.client.indices.GetIndexResponse;
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
+import org.elasticsearch.client.indices.GetIndexTemplateV2Request;
+import org.elasticsearch.client.indices.GetIndexTemplatesV2Response;
import org.elasticsearch.client.indices.GetMappingsRequest;
import org.elasticsearch.client.indices.GetMappingsResponse;
+import org.elasticsearch.client.indices.IndexTemplateV2ExistRequest;
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
+import org.elasticsearch.client.indices.PutIndexTemplateV2Request;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.ReloadAnalyzersRequest;
import org.elasticsearch.client.indices.ReloadAnalyzersResponse;
@@ -1289,6 +1294,36 @@ public Cancellable putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequ
AcknowledgedResponse::fromXContent, listener, emptySet());
}
+ /**
+ * Puts an index template using the Index Templates API.
+ * See Index Templates API
+ * on elastic.co
+ * @param putIndexTemplateRequest the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @return the response
+ * @throws IOException in case there is a problem sending the request or parsing back the response
+ */
+ public AcknowledgedResponse putIndexTemplate(PutIndexTemplateV2Request putIndexTemplateRequest, RequestOptions options)
+ throws IOException {
+ return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putIndexTemplate,
+ options, AcknowledgedResponse::fromXContent, emptySet());
+ }
+
+ /**
+ * Asynchronously puts an index template using the Index Templates API.
+ * See Index Templates API
+ * on elastic.co
+ * @param putIndexTemplateRequest the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @param listener the listener to be notified upon request completion
+ * @return cancellable that may be used to cancel the request
+ */
+ public Cancellable putIndexTemplateAsync(PutIndexTemplateV2Request putIndexTemplateRequest,
+ RequestOptions options, ActionListener listener) {
+ return restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putIndexTemplate,
+ options, AcknowledgedResponse::fromXContent, listener, emptySet());
+ }
+
/**
* Validate a potentially expensive query without executing it.
*
@@ -1344,6 +1379,36 @@ public org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResp
org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, emptySet());
}
+ /**
+ * Gets index templates using the Index Templates API
+ * See Index Templates API
+ * on elastic.co
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @param getIndexTemplatesRequest the request
+ * @return the response
+ * @throws IOException in case there is a problem sending the request or parsing back the response
+ */
+ public GetIndexTemplatesV2Response getIndexTemplate(GetIndexTemplateV2Request getIndexTemplatesRequest,
+ RequestOptions options) throws IOException {
+ return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getIndexTemplates,
+ options, GetIndexTemplatesV2Response::fromXContent, emptySet());
+ }
+
+ /**
+ * Asynchronously gets index templates using the Index Templates API
+ * See Index Templates API
+ * on elastic.co
+ * @param getIndexTemplatesRequest the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @param listener the listener to be notified upon request completion
+ * @return cancellable that may be used to cancel the request
+ */
+ public Cancellable getIndexTemplateAsync(GetIndexTemplateV2Request getIndexTemplatesRequest, RequestOptions options,
+ ActionListener listener) {
+ return restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
+ IndicesRequestConverters::getIndexTemplates, options, GetIndexTemplatesV2Response::fromXContent, listener, emptySet());
+ }
+
/**
* Gets index templates using the Index Templates API
* See Index Templates API
@@ -1354,7 +1419,7 @@ public org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResp
* @throws IOException in case there is a problem sending the request or parsing back the response
*/
public GetIndexTemplatesResponse getIndexTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest,
- RequestOptions options) throws IOException {
+ RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
IndicesRequestConverters::getTemplates,
options, GetIndexTemplatesResponse::fromXContent, emptySet());
@@ -1429,6 +1494,37 @@ public Cancellable existsTemplateAsync(IndexTemplatesExistRequest indexTemplates
RestHighLevelClient::convertExistsResponse, listener, emptySet());
}
+ /**
+ * Uses the Index Templates API to determine if index templates exist
+ *
+ * @param indexTemplatesRequest the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @return true if any index templates in the request exist, false otherwise
+ * @throws IOException in case there is a problem sending the request or parsing back the response
+ */
+ public boolean existsIndexTemplate(IndexTemplateV2ExistRequest indexTemplatesRequest,
+ RequestOptions options) throws IOException {
+ return restHighLevelClient.performRequest(indexTemplatesRequest,
+ IndicesRequestConverters::templatesExist, options,
+ RestHighLevelClient::convertExistsResponse, emptySet());
+ }
+
+ /**
+ * Uses the Index Templates API to determine if index templates exist
+ * @param indexTemplatesExistRequest the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @param listener the listener to be notified upon request completion. The listener will be called with the value {@code true}
+ * @return cancellable that may be used to cancel the request
+ */
+ public Cancellable existsIndexTemplateAsync(IndexTemplateV2ExistRequest indexTemplatesExistRequest,
+ RequestOptions options,
+ ActionListener listener) {
+
+ return restHighLevelClient.performRequestAsync(indexTemplatesExistRequest,
+ IndicesRequestConverters::templatesExist, options,
+ RestHighLevelClient::convertExistsResponse, listener, emptySet());
+ }
+
/**
* Calls the analyze API
*
@@ -1535,6 +1631,35 @@ public Cancellable deleteTemplateAsync(DeleteIndexTemplateRequest request, Reque
options, AcknowledgedResponse::fromXContent, listener, emptySet());
}
+ /**
+ * Delete an index template using the Index Templates API
+ * See Index Templates API
+ * on elastic.co
+ *
+ * @param request the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @throws IOException in case there is a problem sending the request or parsing back the response
+ */
+ public AcknowledgedResponse deleteIndexTemplate(DeleteIndexTemplateV2Request request, RequestOptions options) throws IOException {
+ return restHighLevelClient.performRequestAndParseEntity(request, IndicesRequestConverters::deleteIndexTemplate,
+ options, AcknowledgedResponse::fromXContent, emptySet());
+ }
+
+ /**
+ * Asynchronously delete an index template using the Index Templates API
+ * See Index Templates API
+ * on elastic.co
+ * @param request the request
+ * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
+ * @param listener the listener to be notified upon request completion
+ * @return cancellable that may be used to cancel the request
+ */
+ public Cancellable deleteIndexTemplateAsync(DeleteIndexTemplateV2Request request, RequestOptions options,
+ ActionListener listener) {
+ return restHighLevelClient.performRequestAsyncAndParseEntity(request, IndicesRequestConverters::deleteIndexTemplate,
+ options, AcknowledgedResponse::fromXContent, listener, emptySet());
+ }
+
/**
* Synchronously calls the _reload_search_analyzers API
*
diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java
index 4e6c5b5b1f015..4fa4332e07266 100644
--- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java
@@ -42,13 +42,17 @@
import org.elasticsearch.client.indices.CloseIndexRequest;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.DeleteAliasRequest;
+import org.elasticsearch.client.indices.DeleteIndexTemplateV2Request;
import org.elasticsearch.client.indices.FreezeIndexRequest;
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
import org.elasticsearch.client.indices.GetIndexRequest;
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
+import org.elasticsearch.client.indices.GetIndexTemplateV2Request;
import org.elasticsearch.client.indices.GetMappingsRequest;
+import org.elasticsearch.client.indices.IndexTemplateV2ExistRequest;
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
+import org.elasticsearch.client.indices.PutIndexTemplateV2Request;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.ReloadAnalyzersRequest;
import org.elasticsearch.client.indices.ResizeRequest;
@@ -580,6 +584,23 @@ static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) thro
return request;
}
+ static Request putIndexTemplate(PutIndexTemplateV2Request putIndexTemplateRequest) throws IOException {
+ String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_index_template")
+ .addPathPart(putIndexTemplateRequest.name()).build();
+ Request request = new Request(HttpPut.METHOD_NAME, endpoint);
+ RequestConverters.Params params = new RequestConverters.Params();
+ params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
+ if (putIndexTemplateRequest.create()) {
+ params.putParam("create", Boolean.TRUE.toString());
+ }
+ if (Strings.hasText(putIndexTemplateRequest.cause())) {
+ params.putParam("cause", putIndexTemplateRequest.cause());
+ }
+ request.addParameters(params.asMap());
+ request.setEntity(RequestConverters.createEntity(putIndexTemplateRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
+ return request;
+ }
+
static Request validateQuery(ValidateQueryRequest validateQueryRequest) throws IOException {
String[] indices = validateQueryRequest.indices() == null ? Strings.EMPTY_ARRAY : validateQueryRequest.indices();
String[] types = validateQueryRequest.types() == null || indices.length <= 0 ? Strings.EMPTY_ARRAY : validateQueryRequest.types();
@@ -632,6 +653,19 @@ private static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRe
return request;
}
+ static Request getIndexTemplates(GetIndexTemplateV2Request getIndexTemplatesRequest) {
+ final String endpoint = new RequestConverters.EndpointBuilder()
+ .addPathPartAsIs("_index_template")
+ .addPathPart(getIndexTemplatesRequest.name())
+ .build();
+ final Request request = new Request(HttpGet.METHOD_NAME, endpoint);
+ final RequestConverters.Params params = new RequestConverters.Params();
+ params.withLocal(getIndexTemplatesRequest.isLocal());
+ params.withMasterTimeout(getIndexTemplatesRequest.getMasterNodeTimeout());
+ request.addParameters(params.asMap());
+ return request;
+ }
+
static Request templatesExist(IndexTemplatesExistRequest indexTemplatesExistRequest) {
final String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_template")
@@ -645,6 +679,19 @@ static Request templatesExist(IndexTemplatesExistRequest indexTemplatesExistRequ
return request;
}
+ static Request templatesExist(IndexTemplateV2ExistRequest indexTemplatesExistRequest) {
+ final String endpoint = new RequestConverters.EndpointBuilder()
+ .addPathPartAsIs("_index_template")
+ .addPathPart(indexTemplatesExistRequest.name())
+ .build();
+ final Request request = new Request(HttpHead.METHOD_NAME, endpoint);
+ final RequestConverters.Params params = new RequestConverters.Params();
+ params.withLocal(indexTemplatesExistRequest.isLocal());
+ params.withMasterTimeout(indexTemplatesExistRequest.getMasterNodeTimeout());
+ request.addParameters(params.asMap());
+ return request;
+ }
+
static Request analyze(AnalyzeRequest request) throws IOException {
RequestConverters.EndpointBuilder builder = new RequestConverters.EndpointBuilder();
String index = request.index();
@@ -691,6 +738,16 @@ static Request deleteTemplate(DeleteIndexTemplateRequest deleteIndexTemplateRequ
return request;
}
+ static Request deleteIndexTemplate(DeleteIndexTemplateV2Request deleteIndexTemplateRequest) {
+ String name = deleteIndexTemplateRequest.getName();
+ String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_index_template").addPathPart(name).build();
+ Request request = new Request(HttpDelete.METHOD_NAME, endpoint);
+ RequestConverters.Params params = new RequestConverters.Params();
+ params.withMasterTimeout(deleteIndexTemplateRequest.masterNodeTimeout());
+ request.addParameters(params.asMap());
+ return request;
+ }
+
static Request reloadAnalyzers(ReloadAnalyzersRequest reloadAnalyzersRequest) {
String endpoint = RequestConverters.endpoint(reloadAnalyzersRequest.getIndices(), "_reload_search_analyzers");
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/DeleteIndexTemplateV2Request.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/DeleteIndexTemplateV2Request.java
new file mode 100644
index 0000000000000..cb757e0e58433
--- /dev/null
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/DeleteIndexTemplateV2Request.java
@@ -0,0 +1,35 @@
+/*
+ * 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.client.indices;
+
+import org.elasticsearch.client.TimedRequest;
+
+public class DeleteIndexTemplateV2Request extends TimedRequest {
+
+ private final String name;
+
+ public DeleteIndexTemplateV2Request(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexTemplateV2Request.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexTemplateV2Request.java
new file mode 100644
index 0000000000000..0cc8e2af3a7e0
--- /dev/null
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexTemplateV2Request.java
@@ -0,0 +1,80 @@
+/*
+ * 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.client.indices;
+
+import org.elasticsearch.client.TimedRequest;
+import org.elasticsearch.client.Validatable;
+import org.elasticsearch.common.Nullable;
+import org.elasticsearch.common.unit.TimeValue;
+
+/**
+ * A request to read the content of index templates
+ */
+public class GetIndexTemplateV2Request implements Validatable {
+
+ private final String name;
+
+ private TimeValue masterNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
+ private boolean local = false;
+
+ /**
+ * Create a request to read the content of index template. If no template name is provided, all templates will
+ * be read
+ *
+ * @param name the name of template to read
+ */
+ public GetIndexTemplateV2Request(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the name of index template this request is requesting
+ */
+ public String name() {
+ return name;
+ }
+
+ /**
+ * @return the timeout for waiting for the master node to respond
+ */
+ public TimeValue getMasterNodeTimeout() {
+ return masterNodeTimeout;
+ }
+
+ public void setMasterNodeTimeout(@Nullable TimeValue masterNodeTimeout) {
+ this.masterNodeTimeout = masterNodeTimeout;
+ }
+
+ public void setMasterNodeTimeout(String masterNodeTimeout) {
+ final TimeValue timeValue = TimeValue.parseTimeValue(masterNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
+ setMasterNodeTimeout(timeValue);
+ }
+
+ /**
+ * @return true if this request is to read from the local cluster state, rather than the master node - false otherwise
+ */
+ public boolean isLocal() {
+ return local;
+ }
+
+ public void setLocal(boolean local) {
+ this.local = local;
+ }
+}
diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexTemplatesV2Response.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexTemplatesV2Response.java
new file mode 100644
index 0000000000000..c96f874087ffe
--- /dev/null
+++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indices/GetIndexTemplatesV2Response.java
@@ -0,0 +1,108 @@
+/*
+ * 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.client.indices;
+
+import org.elasticsearch.cluster.metadata.IndexTemplateV2;
+import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.xcontent.ConstructingObjectParser;
+import org.elasticsearch.common.xcontent.XContentParser;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+
+public class GetIndexTemplatesV2Response {
+
+ public static final ParseField NAME = new ParseField("name");
+ public static final ParseField INDEX_TEMPLATES = new ParseField("index_templates");
+ public static final ParseField INDEX_TEMPLATE = new ParseField("index_template");
+
+ @SuppressWarnings("unchecked")
+ private static final ConstructingObjectParser