Skip to content

Commit 5e9688b

Browse files
authored
Revert "Backport of types removal for Put/Get index templates (elastic#38022)" (elastic#38427)
This reverts commit ca21cb2.
1 parent 65b0493 commit 5e9688b

File tree

17 files changed

+118
-1630
lines changed

17 files changed

+118
-1630
lines changed

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

Lines changed: 14 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
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;
5355
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
5456
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
5557
import org.elasticsearch.action.support.master.AcknowledgedResponse;
@@ -60,9 +62,7 @@
6062
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
6163
import org.elasticsearch.client.indices.GetMappingsRequest;
6264
import org.elasticsearch.client.indices.GetMappingsResponse;
63-
import org.elasticsearch.client.indices.GetIndexTemplatesResponse;
6465
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,7 +1341,6 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Reques
13411341
AcknowledgedResponse::fromXContent, listener, emptySet());
13421342
}
13431343

1344-
13451344
/**
13461345
* Asynchronously updates specific index level settings using the Update Indices Settings API.
13471346
* <p>
@@ -1364,48 +1363,9 @@ public void putSettingsAsync(UpdateSettingsRequest updateSettingsRequest, Action
13641363
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
13651364
* @return the response
13661365
* @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.
13691366
*/
1370-
@Deprecated
1371-
public AcknowledgedResponse putTemplate(
1372-
org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest putIndexTemplateRequest,
1373-
RequestOptions options) throws IOException {
1374-
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
1375-
AcknowledgedResponse::fromXContent, emptySet());
1376-
}
1377-
1378-
/**
1379-
* Asynchronously puts an index template using the Index Templates API.
1380-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1381-
* on elastic.co</a>
1382-
* @param putIndexTemplateRequest the request
1383-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1384-
* @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.
1388-
*/
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 {
1367+
public AcknowledgedResponse putTemplate(PutIndexTemplateRequest putIndexTemplateRequest,
1368+
RequestOptions options) throws IOException {
14091369
return restHighLevelClient.performRequestAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
14101370
AcknowledgedResponse::fromXContent, emptySet());
14111371
}
@@ -1418,8 +1378,8 @@ public AcknowledgedResponse putTemplate(
14181378
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
14191379
* @param listener the listener to be notified upon request completion
14201380
*/
1421-
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest,
1422-
RequestOptions options, ActionListener<AcknowledgedResponse> listener) {
1381+
public void putTemplateAsync(PutIndexTemplateRequest putIndexTemplateRequest, RequestOptions options,
1382+
ActionListener<AcknowledgedResponse> listener) {
14231383
restHighLevelClient.performRequestAsyncAndParseEntity(putIndexTemplateRequest, IndicesRequestConverters::putTemplate, options,
14241384
AcknowledgedResponse::fromXContent, listener, emptySet());
14251385
}
@@ -1454,61 +1414,21 @@ public void validateQueryAsync(ValidateQueryRequest validateQueryRequest, Reques
14541414
ValidateQueryResponse::fromXContent, listener, emptySet());
14551415
}
14561416

1457-
/**
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.
1460-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1461-
* on elastic.co</a>
1462-
* @param getIndexTemplatesRequest the request
1463-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1464-
* @return the response
1465-
* @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
1468-
*/
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());
1475-
}
1476-
14771417
/**
14781418
* Gets index templates using the Index Templates API
14791419
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
14801420
* on elastic.co</a>
1481-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
14821421
* @param getIndexTemplatesRequest the request
1422+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
14831423
* @return the response
14841424
* @throws IOException in case there is a problem sending the request or parsing back the response
14851425
*/
1486-
public GetIndexTemplatesResponse getIndexTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options)
1487-
throws IOException {
1488-
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest,
1489-
IndicesRequestConverters::getTemplates,
1426+
public GetIndexTemplatesResponse getTemplate(GetIndexTemplatesRequest getIndexTemplatesRequest,
1427+
RequestOptions options) throws IOException {
1428+
return restHighLevelClient.performRequestAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getTemplates,
14901429
options, GetIndexTemplatesResponse::fromXContent, emptySet());
1491-
}
1492-
1493-
/**
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.
1496-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
1497-
* on elastic.co</a>
1498-
* @param getIndexTemplatesRequest the request
1499-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
1500-
* @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
1503-
*/
1504-
@Deprecated
1505-
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());
15101430
}
1511-
1431+
15121432
/**
15131433
* Asynchronously gets index templates using the Index Templates API
15141434
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html"> Index Templates API
@@ -1517,12 +1437,11 @@ public void getTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest,
15171437
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
15181438
* @param listener the listener to be notified upon request completion
15191439
*/
1520-
public void getIndexTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
1440+
public void getTemplateAsync(GetIndexTemplatesRequest getIndexTemplatesRequest, RequestOptions options,
15211441
ActionListener<GetIndexTemplatesResponse> listener) {
1522-
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest,
1523-
IndicesRequestConverters::getTemplates,
1442+
restHighLevelClient.performRequestAsyncAndParseEntity(getIndexTemplatesRequest, IndicesRequestConverters::getTemplates,
15241443
options, GetIndexTemplatesResponse::fromXContent, listener, emptySet());
1525-
}
1444+
}
15261445

15271446
/**
15281447
* 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: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,17 @@
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;
4647
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
4748
import org.elasticsearch.action.support.ActiveShardCount;
4849
import org.elasticsearch.client.indices.CreateIndexRequest;
4950
import org.elasticsearch.client.indices.FreezeIndexRequest;
5051
import org.elasticsearch.client.indices.GetIndexTemplatesRequest;
5152
import org.elasticsearch.client.indices.GetMappingsRequest;
5253
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;
5857

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

394393
return request;
395394
}
@@ -424,38 +423,12 @@ static Request indexPutSettings(UpdateSettingsRequest updateSettingsRequest) thr
424423
return request;
425424
}
426425

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-
450426
static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) throws IOException {
451427
String endpoint = new RequestConverters.EndpointBuilder().addPathPartAsIs("_template")
452428
.addPathPart(putIndexTemplateRequest.name()).build();
453429
Request request = new Request(HttpPut.METHOD_NAME, endpoint);
454430
RequestConverters.Params params = new RequestConverters.Params(request);
455431
params.withMasterTimeout(putIndexTemplateRequest.masterNodeTimeout());
456-
if (putIndexTemplateRequest.mappings() != null) {
457-
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.FALSE.toString());
458-
}
459432
if (putIndexTemplateRequest.create()) {
460433
params.putParam("create", Boolean.TRUE.toString());
461434
}
@@ -491,16 +464,7 @@ static Request getAlias(GetAliasesRequest getAliasesRequest) {
491464
return request;
492465
}
493466

494-
@Deprecated
495-
static Request getTemplatesWithDocumentTypes(GetIndexTemplatesRequest getIndexTemplatesRequest) {
496-
return getTemplates(getIndexTemplatesRequest, true);
497-
}
498-
499467
static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
500-
return getTemplates(getIndexTemplatesRequest, false);
501-
}
502-
503-
private static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest, boolean includeTypeName) {
504468
final String endpoint = new RequestConverters.EndpointBuilder()
505469
.addPathPartAsIs("_template")
506470
.addCommaSeparatedPathParts(getIndexTemplatesRequest.names())
@@ -509,9 +473,8 @@ private static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRe
509473
final RequestConverters.Params params = new RequestConverters.Params(request);
510474
params.withLocal(getIndexTemplatesRequest.isLocal());
511475
params.withMasterTimeout(getIndexTemplatesRequest.getMasterNodeTimeout());
512-
params.putParam(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, Boolean.toString(includeTypeName));
513476
return request;
514-
}
477+
}
515478

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

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
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;
7980
import org.elasticsearch.rest.action.search.RestSearchAction;
8081
import org.elasticsearch.script.mustache.MultiSearchTemplateRequest;
8182
import org.elasticsearch.script.mustache.SearchTemplateRequest;
@@ -949,6 +950,14 @@ Params withIncludeDefaults(boolean includeDefaults) {
949950
return this;
950951
}
951952

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+
952961
Params withPreserveExisting(boolean preserveExisting) {
953962
if (preserveExisting) {
954963
return putParam("preserve_existing", Boolean.TRUE.toString());

0 commit comments

Comments
 (0)