Skip to content

Commit

Permalink
Backport of types removal for Put/Get index templates (#38465)
Browse files Browse the repository at this point in the history
Added deprecation warnings for use of include_type_name in put/get index templates.
HLRC changes:
* GetIndexTemplateRequest has a new client-side class which is a copy of server's GetIndexTemplateResponse but modified to be typeless.
* PutIndexTemplateRequest has a new client-side counterpart which doesn't use types in the mappings

Relates to #35190
  • Loading branch information
markharwood authored and jtibshirani committed Feb 6, 2019
1 parent 7b743a0 commit 9f3b3b4
Show file tree
Hide file tree
Showing 17 changed files with 1,630 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
import org.elasticsearch.action.admin.indices.shrink.ResizeResponse;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
Expand All @@ -60,7 +58,9 @@
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
import org.elasticsearch.client.indices.GetMappingsRequest;
import org.elasticsearch.client.indices.GetMappingsResponse;
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
import org.elasticsearch.client.indices.rollover.RolloverRequest;
Expand Down Expand Up @@ -1471,6 +1471,7 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Reques
AcknowledgedResponse::fromXContent, listener, emptySet());
}


/**
* Asynchronously updates specific index level settings using the Update Indices Settings API.
* <p>
Expand All @@ -1493,9 +1494,13 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Action
* @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
* @deprecated This old form of request allows types in mappings. Use {@link #putTemplate(PutIndexTemplateRequest, RequestOptions)}
* instead which introduces a new request object without types.
*/
public AcknowledgedResponse putTemplate(PutIndexTemplateRequest putIndexTemplateRequest,
RequestOptions options) throws IOException {
@Deprecated
public AcknowledgedResponse putTemplate(
org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
AcknowledgedResponse::fromXContent, emptySet());
}
Expand All @@ -1507,9 +1512,44 @@ public AcknowledgedResponse putTemplate(PutIndexTemplateRequest putIndexTemplate
* @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
* @deprecated This old form of request allows types in mappings.
* Use {@link #putTemplateAsync(PutIndexTemplateRequest, RequestOptions, ActionListener)}
* instead which introduces a new request object without types.
*/
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest, RequestOptions options,
ActionListener<AcknowledgedResponse> listener) {
@Deprecated
public void putTemplateAsync(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
AcknowledgedResponse::fromXContent, listener, emptySet());
}


/**
* Puts an index template using the Index Templates API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @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 putTemplate(
PutIndexTemplateRequest putIndexTemplateRequest,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
AcknowledgedResponse::fromXContent, emptySet());
}

/**
* Asynchronously puts an index template using the Index Templates API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @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
*/
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest,
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
AcknowledgedResponse::fromXContent, listener, emptySet());
}
Expand Down Expand Up @@ -1545,33 +1585,74 @@ public void validateQueryAsync(ValidateQueryRequest validateQueryRequest, Reques
}

/**
* Gets index templates using the Index Templates API
* Gets index templates using the Index Templates API. The mappings will be returned in a legacy deprecated format, where the
* mapping definition is nested under the type name.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @param getIndexTemplatesRequest 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
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
* {@link #getIndexTemplate(GetIndexTemplatesRequest, RequestOptions)} instead which returns a new response object
*/
public GetIndexTemplatesResponse getTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest,
RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getTemplates,
options, GetIndexTemplatesResponse::fromXContent, emptySet());
@Deprecated
public org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse getTemplate(
GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options) throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
IndicesRequestConverters::getTemplatesWithDocumentTypes,
options, org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, emptySet());
}

/**
* Gets index templates using the Index Templates API
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @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 GetIndexTemplatesResponse getIndexTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options)
throws IOException {
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
IndicesRequestConverters::getTemplates,
options, GetIndexTemplatesResponse::fromXContent, emptySet());
}

/**
* Asynchronously gets index templates using the Index Templates API
* Asynchronously gets index templates using the Index Templates API. The mappings will be returned in a legacy deprecated format,
* where the mapping definition is nested under the type name.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @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
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
* {@link #getIndexTemplateAsync(GetIndexTemplatesRequest, RequestOptions, ActionListener)} instead which returns a new response object
*/
@Deprecated
public void getTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
ActionListener<org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
IndicesRequestConverters::getTemplatesWithDocumentTypes,
options, org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, listener, emptySet());
}

/**
* Asynchronously gets index templates using the Index Templates API
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
* on elastic.co</a>
* @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
*/
public void getIndexTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
ActionListener<GetIndexTemplatesResponse> listener) {
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getTemplates,
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
IndicesRequestConverters::getTemplates,
options, GetIndexTemplatesResponse::fromXContent, listener, emptySet());
}
}

/**
* Uses the Index Templates API to determine if index templates exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.client.indices.CreateIndexRequest;
Expand All @@ -50,10 +49,12 @@
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
import org.elasticsearch.client.indices.GetMappingsRequest;
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
import org.elasticsearch.client.indices.PutMappingRequest;
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
import org.elasticsearch.client.indices.rollover.RolloverRequest;
import org.elasticsearch.common.Strings;
import org.elasticsearch.rest.BaseRestHandler;

import java.io.IOException;
import java.util.Locale;
Expand Down Expand Up @@ -492,12 +493,38 @@ static Request indexPutSettings(UpdateSettingsRequest updateSettingsRequest) thr
return request;
}

/**
* @deprecated This uses the old form of PutIndexTemplateRequest which uses types.
* Use (@link {@link #putTemplate(PutIndexTemplateRequest)} instead
*/
@Deprecated
static Request putTemplate(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest)
throws IOException {
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_template")
.addPathPart(putIndexTemplateRequest.name()).build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params(request);
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.TRUE.toString());
if (putIndexTemplateRequest.create()) {
params.putParam("create", Boolean.TRUE.toString());
}
if (Strings.hasText(putIndexTemplateRequest.cause())) {
params.putParam("cause", putIndexTemplateRequest.cause());
}
request.setEntity(RequestConverters.createEntity(putIndexTemplateRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
return request;
}

static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) throws IOException {
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_template")
.addPathPart(putIndexTemplateRequest.name()).build();
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
RequestConverters.Params params = new RequestConverters.Params(request);
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
if (putIndexTemplateRequest.mappings() != null) {
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.FALSE.toString());
}
if (putIndexTemplateRequest.create()) {
params.putParam("create", Boolean.TRUE.toString());
}
Expand Down Expand Up @@ -533,7 +560,16 @@ static Request getAlias(GetAliasesRequest getAliasesRequest) {
return request;
}

@Deprecated
static Request getTemplatesWithDocumentTypes(GetIndexTemplatesRequest getIndexTemplatesRequest) {
return getTemplates(getIndexTemplatesRequest, true);
}

static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
return getTemplates(getIndexTemplatesRequest, false);
}

private static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest, boolean includeTypeName) {
final String endpoint = new RequestConverters.EndpointBuilder()
.addPathPartAsIs("_template")
.addCommaSeparatedPathParts(getIndexTemplatesRequest.names())
Expand All @@ -542,8 +578,9 @@ static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
final RequestConverters.Params params = new RequestConverters.Params(request);
params.withLocal(getIndexTemplatesRequest.isLocal());
params.withMasterTimeout(getIndexTemplatesRequest.getMasterNodeTimeout());
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.toString(includeTypeName));
return request;
}
}

static Request templatesExist(IndexTemplatesExistRequest indexTemplatesExistRequest) {
final String endpoint = new RequestConverters.EndpointBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
import org.elasticsearch.index.reindex.ReindexRequest;
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
import org.elasticsearch.index.seqno.SequenceNumbers;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.script.mustache.MultiSearchTemplateRequest;
import org.elasticsearch.script.mustache.SearchTemplateRequest;
Expand Down Expand Up @@ -959,14 +958,6 @@ Params withIncludeDefaults(boolean includeDefaults) {
return this;
}

Params withIncludeTypeName(boolean includeTypeName) {
if (includeTypeName) {
return putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER,
Boolean.toString(BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY));
}
return this;
}

Params withPreserveExisting(boolean preserveExisting) {
if (preserveExisting) {
return putParam("preserve_existing", Boolean.TRUE.toString());
Expand Down
Loading

0 comments on commit 9f3b3b4

Please sign in to comment.