Skip to content

Commit 9f3b3b4

Browse files
markharwoodjtibshirani
authored andcommitted
Backport of types removal for Put/Get index templates (elastic#38465)
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 elastic#35190
1 parent 7b743a0 commit 9f3b3b4

File tree

17 files changed

+1630
-117
lines changed

17 files changed

+1630
-117
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
@@ -44,8 +44,6 @@
4444
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
4545
import org.elasticsearch.action.admin.indices.shrink.ResizeResponse;
4646
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
47-
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
48-
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
4947
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
5048
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
5149
import org.elasticsearch.action.support.master.AcknowledgedResponse;
@@ -60,7 +58,9 @@
6058
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
6159
import org.elasticsearch.client.indices.GetMappingsRequest;
6260
import org.elasticsearch.client.indices.GetMappingsResponse;
61+
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
6362
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
63+
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
6464
import org.elasticsearch.client.indices.PutMappingRequest;
6565
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
6666
import org.elasticsearch.client.indices.rollover.RolloverRequest;
@@ -1471,6 +1471,7 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Reques
14711471
AcknowledgedResponse::fromXContent, listener, emptySet());
14721472
}
14731473

1474+
14741475
/**
14751476
* Asynchronously updates specific index level settings using the Update Indices Settings API.
14761477
* <p>
@@ -1493,9 +1494,13 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Action
14931494
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
14941495
* @return the response
14951496
* @throws IOException in case there is a problem sending the request or parsing back the response
1497+
* @deprecated This old form of request allows types in mappings. Use {@link #putTemplate(PutIndexTemplateRequest, RequestOptions)}
1498+
* instead which introduces a new request object without types.
14961499
*/
1497-
public AcknowledgedResponse putTemplate(PutIndexTemplateRequest putIndexTemplateRequest,
1498-
RequestOptions options) throws IOException {
1500+
@Deprecated
1501+
public AcknowledgedResponse putTemplate(
1502+
org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
1503+
RequestOptions options) throws IOException {
14991504
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
15001505
AcknowledgedResponse::fromXContent, emptySet());
15011506
}
@@ -1507,9 +1512,44 @@ public AcknowledgedResponse putTemplate(PutIndexTemplateRequest putIndexTemplate
15071512
* @param putIndexTemplateRequest the request
15081513
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
15091514
* @param listener the listener to be notified upon request completion
1515+
* @deprecated This old form of request allows types in mappings.
1516+
* Use {@link #putTemplateAsync(PutIndexTemplateRequest, RequestOptions, ActionListener)}
1517+
* instead which introduces a new request object without types.
15101518
*/
1511-
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest, RequestOptions options,
1512-
ActionListener<AcknowledgedResponse> listener) {
1519+
@Deprecated
1520+
public void putTemplateAsync(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
1521+
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
1522+
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
1523+
AcknowledgedResponse::fromXContent, listener, emptySet());
1524+
}
1525+
1526+
1527+
/**
1528+
* Puts an index template using the Index Templates API.
1529+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1530+
* on elastic.co</a>
1531+
* @param putIndexTemplateRequest the request
1532+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1533+
* @return the response
1534+
* @throws IOException in case there is a problem sending the request or parsing back the response
1535+
*/
1536+
public AcknowledgedResponse putTemplate(
1537+
PutIndexTemplateRequest putIndexTemplateRequest,
1538+
RequestOptions options) throws IOException {
1539+
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
1540+
AcknowledgedResponse::fromXContent, emptySet());
1541+
}
1542+
1543+
/**
1544+
* Asynchronously puts an index template using the Index Templates API.
1545+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1546+
* on elastic.co</a>
1547+
* @param putIndexTemplateRequest the request
1548+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1549+
* @param listener the listener to be notified upon request completion
1550+
*/
1551+
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest,
1552+
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
15131553
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
15141554
AcknowledgedResponse::fromXContent, listener, emptySet());
15151555
}
@@ -1545,33 +1585,74 @@ public void validateQueryAsync(ValidateQueryRequest validateQueryRequest, Reques
15451585
}
15461586

15471587
/**
1548-
* Gets index templates using the Index Templates API
1588+
* Gets index templates using the Index Templates API. The mappings will be returned in a legacy deprecated format, where the
1589+
* mapping definition is nested under the type name.
15491590
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
15501591
* on elastic.co</a>
15511592
* @param getIndexTemplatesRequest the request
15521593
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
15531594
* @return the response
15541595
* @throws IOException in case there is a problem sending the request or parsing back the response
1596+
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
1597+
* {@link #getIndexTemplate(GetIndexTemplatesRequest, RequestOptions)} instead which returns a new response object
15551598
*/
1556-
public GetIndexTemplatesResponse getTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest,
1557-
RequestOptions options) throws IOException {
1558-
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getTemplates,
1559-
options, GetIndexTemplatesResponse::fromXContent, emptySet());
1599+
@Deprecated
1600+
public org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse getTemplate(
1601+
GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options) throws IOException {
1602+
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
1603+
IndicesRequestConverters::getTemplatesWithDocumentTypes,
1604+
options, org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, emptySet());
15601605
}
1606+
1607+
/**
1608+
* Gets index templates using the Index Templates API
1609+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1610+
* on elastic.co</a>
1611+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1612+
* @param getIndexTemplatesRequest the request
1613+
* @return the response
1614+
* @throws IOException in case there is a problem sending the request or parsing back the response
1615+
*/
1616+
public GetIndexTemplatesResponse getIndexTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options)
1617+
throws IOException {
1618+
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
1619+
IndicesRequestConverters::getTemplates,
1620+
options, GetIndexTemplatesResponse::fromXContent, emptySet());
1621+
}
15611622

15621623
/**
1563-
* Asynchronously gets index templates using the Index Templates API
1624+
* Asynchronously gets index templates using the Index Templates API. The mappings will be returned in a legacy deprecated format,
1625+
* where the mapping definition is nested under the type name.
15641626
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
15651627
* on elastic.co</a>
15661628
* @param getIndexTemplatesRequest the request
15671629
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
15681630
* @param listener the listener to be notified upon request completion
1631+
* @deprecated This method uses an old response object which still refers to types, a deprecated feature. Use
1632+
* {@link #getIndexTemplateAsync(GetIndexTemplatesRequest, RequestOptions, ActionListener)} instead which returns a new response object
15691633
*/
1634+
@Deprecated
15701635
public void getTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
1636+
ActionListener<org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse> listener) {
1637+
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
1638+
IndicesRequestConverters::getTemplatesWithDocumentTypes,
1639+
options, org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse::fromXContent, listener, emptySet());
1640+
}
1641+
1642+
/**
1643+
* Asynchronously gets index templates using the Index Templates API
1644+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1645+
* on elastic.co</a>
1646+
* @param getIndexTemplatesRequest the request
1647+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1648+
* @param listener the listener to be notified upon request completion
1649+
*/
1650+
public void getIndexTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
15711651
ActionListener<GetIndexTemplatesResponse> listener) {
1572-
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getTemplates,
1652+
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
1653+
IndicesRequestConverters::getTemplates,
15731654
options, GetIndexTemplatesResponse::fromXContent, listener, emptySet());
1574-
}
1655+
}
15751656

15761657
/**
15771658
* 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: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.elasticsearch.action.admin.indices.shrink.ResizeRequest;
4141
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
4242
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
43-
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
4443
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
4544
import org.elasticsearch.action.support.ActiveShardCount;
4645
import org.elasticsearch.client.indices.CreateIndexRequest;
@@ -50,10 +49,12 @@
5049
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
5150
import org.elasticsearch.client.indices.GetMappingsRequest;
5251
import org.elasticsearch.client.indices.IndexTemplatesExistRequest;
52+
import org.elasticsearch.client.indices.PutIndexTemplateRequest;
5353
import org.elasticsearch.client.indices.PutMappingRequest;
5454
import org.elasticsearch.client.indices.UnfreezeIndexRequest;
5555
import org.elasticsearch.client.indices.rollover.RolloverRequest;
5656
import org.elasticsearch.common.Strings;
57+
import org.elasticsearch.rest.BaseRestHandler;
5758

5859
import java.io.IOException;
5960
import java.util.Locale;
@@ -492,12 +493,38 @@ static Request indexPutSettings(UpdateSettingsRequest updateSettingsRequest) thr
492493
return request;
493494
}
494495

496+
/**
497+
* @deprecated This uses the old form of PutIndexTemplateRequest which uses types.
498+
* Use (@link {@link #putTemplate(PutIndexTemplateRequest)} instead
499+
*/
500+
@Deprecated
501+
static Request putTemplate(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest)
502+
throws IOException {
503+
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_template")
504+
.addPathPart(putIndexTemplateRequest.name()).build();
505+
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
506+
RequestConverters.Params params = new RequestConverters.Params(request);
507+
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
508+
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.TRUE.toString());
509+
if (putIndexTemplateRequest.create()) {
510+
params.putParam("create", Boolean.TRUE.toString());
511+
}
512+
if (Strings.hasText(putIndexTemplateRequest.cause())) {
513+
params.putParam("cause", putIndexTemplateRequest.cause());
514+
}
515+
request.setEntity(RequestConverters.createEntity(putIndexTemplateRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
516+
return request;
517+
}
518+
495519
static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) throws IOException {
496520
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_template")
497521
.addPathPart(putIndexTemplateRequest.name()).build();
498522
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
499523
RequestConverters.Params params = new RequestConverters.Params(request);
500524
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
525+
if (putIndexTemplateRequest.mappings() != null) {
526+
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.FALSE.toString());
527+
}
501528
if (putIndexTemplateRequest.create()) {
502529
params.putParam("create", Boolean.TRUE.toString());
503530
}
@@ -533,7 +560,16 @@ static Request getAlias(GetAliasesRequest getAliasesRequest) {
533560
return request;
534561
}
535562

563+
@Deprecated
564+
static Request getTemplatesWithDocumentTypes(GetIndexTemplatesRequest getIndexTemplatesRequest) {
565+
return getTemplates(getIndexTemplatesRequest, true);
566+
}
567+
536568
static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
569+
return getTemplates(getIndexTemplatesRequest, false);
570+
}
571+
572+
private static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest, boolean includeTypeName) {
537573
final String endpoint = new RequestConverters.EndpointBuilder()
538574
.addPathPartAsIs("_template")
539575
.addCommaSeparatedPathParts(getIndexTemplatesRequest.names())
@@ -542,8 +578,9 @@ static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
542578
final RequestConverters.Params params = new RequestConverters.Params(request);
543579
params.withLocal(getIndexTemplatesRequest.isLocal());
544580
params.withMasterTimeout(getIndexTemplatesRequest.getMasterNodeTimeout());
581+
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.toString(includeTypeName));
545582
return request;
546-
}
583+
}
547584

548585
static Request templatesExist(IndexTemplatesExistRequest indexTemplatesExistRequest) {
549586
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;
@@ -959,14 +958,6 @@ Params withIncludeDefaults(boolean includeDefaults) {
959958
return this;
960959
}
961960

962-
Params withIncludeTypeName(boolean includeTypeName) {
963-
if (includeTypeName) {
964-
return putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER,
965-
Boolean.toString(BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY));
966-
}
967-
return this;
968-
}
969-
970961
Params withPreserveExisting(boolean preserveExisting) {
971962
if (preserveExisting) {
972963
return putParam("preserve_existing", Boolean.TRUE.toString());

0 commit comments

Comments
 (0)