Skip to content

Commit ca21cb2

Browse files
markharwoodjtibshirani
authored andcommitted
Backport of types removal for Put/Get index templates (#38022)
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
1 parent 8ada485 commit ca21cb2

File tree

17 files changed

+1630
-118
lines changed

17 files changed

+1630
-118
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

Lines changed: 95 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
5151
import org.elasticsearch.action.admin.indices.shrink.ResizeResponse;
5252
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
53-
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
54-
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
5553
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
5654
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
5755
import org.elasticsearch.action.support.master.AcknowledgedResponse;
@@ -62,7 +60,9 @@
6260
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
6361
import org.elasticsearch.client.indices.GetMappingsRequest;
6462
import org.elasticsearch.client.indices.GetMappingsResponse;
63+
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
6564
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
65+
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
6666
import org.elasticsearch.client.indices.PutMappingRequest;
6767
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
6868
import org.elasticsearch.rest.RestStatus;
@@ -1341,6 +1341,7 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Reques
13411341
AcknowledgedResponse::fromXContent, listener, emptySet());
13421342
}
13431343

1344+
13441345
/**
13451346
* Asynchronously updates specific index level settings using the Update Indices Settings API.
13461347
* <p>
@@ -1363,9 +1364,13 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Action
13631364
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
13641365
* @return the response
13651366
* @throws IOException in case there is a problem sending the request or parsing back the response
1367+
* @deprecated This old form of request allows types in mappings. Use {@link #putTemplate(PutIndexTemplateRequest, RequestOptions)}
1368+
* instead which introduces a new request object without types.
13661369
*/
1367-
public AcknowledgedResponse putTemplate(PutIndexTemplateRequest putIndexTemplateRequest,
1368-
RequestOptions options) throws IOException {
1370+
@Deprecated
1371+
public AcknowledgedResponse putTemplate(
1372+
org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
1373+
RequestOptions options) throws IOException {
13691374
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
13701375
AcknowledgedResponse::fromXContent, emptySet());
13711376
}
@@ -1377,9 +1382,44 @@ public AcknowledgedResponse putTemplate(PutIndexTemplateRequest putIndexTemplate
13771382
* @param putIndexTemplateRequest the request
13781383
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
13791384
* @param listener the listener to be notified upon request completion
1385+
* @deprecated This old form of request allows types in mappings.
1386+
* Use {@link #putTemplateAsync(PutIndexTemplateRequest, RequestOptions, ActionListener)}
1387+
* instead which introduces a new request object without types.
13801388
*/
1381-
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest, RequestOptions options,
1382-
ActionListener<AcknowledgedResponse> listener) {
1389+
@Deprecated
1390+
public void putTemplateAsync(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
1391+
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
1392+
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
1393+
AcknowledgedResponse::fromXContent, listener, emptySet());
1394+
}
1395+
1396+
1397+
/**
1398+
* Puts an index template using the Index Templates API.
1399+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1400+
* on elastic.co</a>
1401+
* @param putIndexTemplateRequest the request
1402+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1403+
* @return the response
1404+
* @throws IOException in case there is a problem sending the request or parsing back the response
1405+
*/
1406+
public AcknowledgedResponse putTemplate(
1407+
PutIndexTemplateRequest putIndexTemplateRequest,
1408+
RequestOptions options) throws IOException {
1409+
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
1410+
AcknowledgedResponse::fromXContent, emptySet());
1411+
}
1412+
1413+
/**
1414+
* Asynchronously puts an index template using the Index Templates API.
1415+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1416+
* on elastic.co</a>
1417+
* @param putIndexTemplateRequest the request
1418+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1419+
* @param listener the listener to be notified upon request completion
1420+
*/
1421+
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest,
1422+
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
13831423
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
13841424
AcknowledgedResponse::fromXContent, listener, emptySet());
13851425
}
@@ -1415,33 +1455,74 @@ public void validateQueryAsync(ValidateQueryRequest validateQueryRequest, Reques
14151455
}
14161456

14171457
/**
1418-
* Gets index templates using the Index Templates API
1458+
* Gets index templates using the Index Templates API. The mappings will be returned in a legacy deprecated format, where the
1459+
* mapping definition is nested under the type name.
14191460
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
14201461
* on elastic.co</a>
14211462
* @param getIndexTemplatesRequest the request
14221463
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
14231464
* @return the response
14241465
* @throws IOException in case there is a problem sending the request or parsing back the response
1466+
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
1467+
* {@link #getIndexTemplate(GetIndexTemplatesRequest, RequestOptions)} instead which returns a new response object
14251468
*/
1426-
public GetIndexTemplatesResponse getTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest,
1427-
RequestOptions options) throws IOException {
1428-
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getTemplates,
1429-
options, GetIndexTemplatesResponse::fromXContent, emptySet());
1469+
@Deprecated
1470+
public org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse getTemplate(
1471+
GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options) throws IOException {
1472+
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
1473+
IndicesRequestConverters::getTemplatesWithDocumentTypes,
1474+
options, org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, emptySet());
14301475
}
1476+
1477+
/**
1478+
* Gets index templates using the Index Templates API
1479+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1480+
* on elastic.co</a>
1481+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1482+
* @param getIndexTemplatesRequest the request
1483+
* @return the response
1484+
* @throws IOException in case there is a problem sending the request or parsing back the response
1485+
*/
1486+
public GetIndexTemplatesResponse getIndexTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options)
1487+
throws IOException {
1488+
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
1489+
IndicesRequestConverters::getTemplates,
1490+
options, GetIndexTemplatesResponse::fromXContent, emptySet());
1491+
}
14311492

14321493
/**
1433-
* Asynchronously gets index templates using the Index Templates API
1494+
* Asynchronously gets index templates using the Index Templates API. The mappings will be returned in a legacy deprecated format,
1495+
* where the mapping definition is nested under the type name.
14341496
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
14351497
* on elastic.co</a>
14361498
* @param getIndexTemplatesRequest the request
14371499
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
14381500
* @param listener the listener to be notified upon request completion
1501+
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
1502+
* {@link #getIndexTemplateAsync(GetIndexTemplatesRequest, RequestOptions, ActionListener)} instead which returns a new response object
14391503
*/
1504+
@Deprecated
14401505
public void getTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
1506+
ActionListener<org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse> listener) {
1507+
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
1508+
IndicesRequestConverters::getTemplatesWithDocumentTypes,
1509+
options, org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, listener, emptySet());
1510+
}
1511+
1512+
/**
1513+
* Asynchronously gets index templates using the Index Templates API
1514+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1515+
* on elastic.co</a>
1516+
* @param getIndexTemplatesRequest the request
1517+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1518+
* @param listener the listener to be notified upon request completion
1519+
*/
1520+
public void getIndexTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
14411521
ActionListener<GetIndexTemplatesResponse> listener) {
1442-
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getTemplates,
1522+
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
1523+
IndicesRequestConverters::getTemplates,
14431524
options, GetIndexTemplatesResponse::fromXContent, listener, emptySet());
1444-
}
1525+
}
14451526

14461527
/**
14471528
* Uses the Index Templates API to determine if index templates exist

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@
4343
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
4444
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
4545
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
46-
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
4746
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
4847
import org.elasticsearch.action.support.ActiveShardCount;
4948
import org.elasticsearch.client.indices.CreateIndexRequest;
5049
import org.elasticsearch.client.indices.FreezeIndexRequest;
5150
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
5251
import org.elasticsearch.client.indices.GetMappingsRequest;
5352
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
53+
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
5454
import org.elasticsearch.client.indices.PutMappingRequest;
5555
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
5656
import org.elasticsearch.common.Strings;
57+
import org.elasticsearch.rest.BaseRestHandler;
5758

5859
import java.io.IOException;
5960
import java.util.Locale;
@@ -388,7 +389,7 @@ static Request getIndex(GetIndexRequest getIndexRequest) {
388389
params.withHuman(getIndexRequest.humanReadable());
389390
params.withMasterTimeout(getIndexRequest.masterNodeTimeout());
390391
// Force "include_type_name" parameter since responses need to be compatible when coming from 7.0 nodes
391-
params.withIncludeTypeName(true);
392+
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.TRUE.toString());
392393

393394
return request;
394395
}
@@ -423,12 +424,38 @@ static Request indexPutSettings(UpdateSettingsRequest updateSettingsRequest) thr
423424
return request;
424425
}
425426

427+
/**
428+
* @deprecated This uses the old form of PutIndexTemplateRequest which uses types.
429+
* Use (@link {@link #putTemplate(PutIndexTemplateRequest)} instead
430+
*/
431+
@Deprecated
432+
static Request putTemplate(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest)
433+
throws IOException {
434+
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_template")
435+
.addPathPart(putIndexTemplateRequest.name()).build();
436+
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
437+
RequestConverters.Params params = new RequestConverters.Params(request);
438+
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
439+
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.TRUE.toString());
440+
if (putIndexTemplateRequest.create()) {
441+
params.putParam("create", Boolean.TRUE.toString());
442+
}
443+
if (Strings.hasText(putIndexTemplateRequest.cause())) {
444+
params.putParam("cause", putIndexTemplateRequest.cause());
445+
}
446+
request.setEntity(RequestConverters.createEntity(putIndexTemplateRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
447+
return request;
448+
}
449+
426450
static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) throws IOException {
427451
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_template")
428452
.addPathPart(putIndexTemplateRequest.name()).build();
429453
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
430454
RequestConverters.Params params = new RequestConverters.Params(request);
431455
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
456+
if (putIndexTemplateRequest.mappings() != null) {
457+
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.FALSE.toString());
458+
}
432459
if (putIndexTemplateRequest.create()) {
433460
params.putParam("create", Boolean.TRUE.toString());
434461
}
@@ -464,7 +491,16 @@ static Request getAlias(GetAliasesRequest getAliasesRequest) {
464491
return request;
465492
}
466493

494+
@Deprecated
495+
static Request getTemplatesWithDocumentTypes(GetIndexTemplatesRequest getIndexTemplatesRequest) {
496+
return getTemplates(getIndexTemplatesRequest, true);
497+
}
498+
467499
static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
500+
return getTemplates(getIndexTemplatesRequest, false);
501+
}
502+
503+
private static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest, boolean includeTypeName) {
468504
final String endpoint = new RequestConverters.EndpointBuilder()
469505
.addPathPartAsIs("_template")
470506
.addCommaSeparatedPathParts(getIndexTemplatesRequest.names())
@@ -473,8 +509,9 @@ static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
473509
final RequestConverters.Params params = new RequestConverters.Params(request);
474510
params.withLocal(getIndexTemplatesRequest.isLocal());
475511
params.withMasterTimeout(getIndexTemplatesRequest.getMasterNodeTimeout());
512+
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.toString(includeTypeName));
476513
return request;
477-
}
514+
}
478515

479516
static Request templatesExist(IndexTemplatesExistRequest indexTemplatesExistRequest) {
480517
final String endpoint = new RequestConverters.EndpointBuilder()

client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import org.elasticsearch.index.reindex.ReindexRequest;
7777
import org.elasticsearch.index.reindex.UpdateByQueryRequest;
7878
import org.elasticsearch.index.seqno.SequenceNumbers;
79-
import org.elasticsearch.rest.BaseRestHandler;
8079
import org.elasticsearch.rest.action.search.RestSearchAction;
8180
import org.elasticsearch.script.mustache.MultiSearchTemplateRequest;
8281
import org.elasticsearch.script.mustache.SearchTemplateRequest;
@@ -950,14 +949,6 @@ Params withIncludeDefaults(boolean includeDefaults) {
950949
return this;
951950
}
952951

953-
Params withIncludeTypeName(boolean includeTypeName) {
954-
if (includeTypeName) {
955-
return putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER,
956-
Boolean.toString(BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY));
957-
}
958-
return this;
959-
}
960-
961952
Params withPreserveExisting(boolean preserveExisting) {
962953
if (preserveExisting) {
963954
return putParam("preserve_existing", Boolean.TRUE.toString());

0 commit comments

Comments
 (0)