Skip to content

Commit 36a3b84

Browse files
authored
Update the default for include_type_name to false. (#37285)
* Default include_type_name to false for get and put mappings. * Default include_type_name to false for get field mappings. * Add a constant for the default include_type_name value. * Default include_type_name to false for get and put index templates. * Default include_type_name to false for create index. * Update create index calls in REST documentation to use include_type_name=true. * Some minor clean-ups around the get index API. * In REST tests, use include_type_name=true by default for index creation. * Make sure to use 'expression == false'. * Clarify the different IndexTemplateMetaData toXContent methods. * Fix FullClusterRestartIT#testSnapshotRestore. * Fix the ml_anomalies_default_mappings test. * Fix GetFieldMappingsResponseTests and GetIndexTemplateResponseTests. We make sure to specify include_type_name=true during xContent parsing, so we continue to test the legacy typed responses. XContent generation for the typeless responses is currently only covered by REST tests, but we will be adding unit test coverage for these as we implement each typeless API in the Java HLRC. This commit also refactors GetMappingsResponse to follow the same appraoch as the other mappings-related responses, where we read include_type_name out of the xContent params, instead of creating a second toXContent method. This gives better consistency in the response parsing code. * Fix more REST tests. * Improve some wording in the create index documentation. * Add a note about types removal in the create index docs. * Fix SmokeTestMonitoringWithSecurityIT#testHTTPExporterWithSSL. * Make sure to mention include_type_name in the REST docs for affected APIs. * Make sure to use 'expression == false' in FullClusterRestartIT. * Mention include_type_name in the REST templates docs.
1 parent f3edbe2 commit 36a3b84

File tree

258 files changed

+984
-964
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+984
-964
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
import java.io.IOException;
5858
import java.util.Locale;
5959

60+
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;
61+
6062
final class IndicesRequestConverters {
6163

6264
private IndicesRequestConverters() {}
@@ -103,6 +105,7 @@ static Request createIndex(CreateIndexRequest createIndexRequest) throws IOExcep
103105
parameters.withTimeout(createIndexRequest.timeout());
104106
parameters.withMasterTimeout(createIndexRequest.masterNodeTimeout());
105107
parameters.withWaitForActiveShards(createIndexRequest.waitForActiveShards());
108+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
106109

107110
request.setEntity(RequestConverters.createEntity(createIndexRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
108111
return request;
@@ -131,6 +134,7 @@ static Request putMapping(PutMappingRequest putMappingRequest) throws IOExceptio
131134
RequestConverters.Params parameters = new RequestConverters.Params(request);
132135
parameters.withTimeout(putMappingRequest.timeout());
133136
parameters.withMasterTimeout(putMappingRequest.masterNodeTimeout());
137+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
134138

135139
request.setEntity(RequestConverters.createEntity(putMappingRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
136140
return request;
@@ -146,6 +150,8 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOExcep
146150
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout());
147151
parameters.withIndicesOptions(getMappingsRequest.indicesOptions());
148152
parameters.withLocal(getMappingsRequest.local());
153+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
154+
149155
return request;
150156
}
151157

@@ -165,6 +171,8 @@ static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest)
165171
parameters.withIndicesOptions(getFieldMappingsRequest.indicesOptions());
166172
parameters.withIncludeDefaults(getFieldMappingsRequest.includeDefaults());
167173
parameters.withLocal(getFieldMappingsRequest.local());
174+
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
175+
168176
return request;
169177
}
170178

@@ -357,6 +365,7 @@ static Request putTemplate(PutIndexTemplateRequest putIndexTemplateRequest) thro
357365
if (Strings.hasText(putIndexTemplateRequest.cause())) {
358366
params.putParam("cause", putIndexTemplateRequest.cause());
359367
}
368+
params.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
360369
request.setEntity(RequestConverters.createEntity(putIndexTemplateRequest, RequestConverters.REQUEST_BODY_CONTENT_TYPE));
361370
return request;
362371
}
@@ -395,6 +404,7 @@ static Request getTemplates(GetIndexTemplatesRequest getIndexTemplatesRequest) {
395404
final RequestConverters.Params params = new RequestConverters.Params(request);
396405
params.withLocal(getIndexTemplatesRequest.isLocal());
397406
params.withMasterTimeout(getIndexTemplatesRequest.getMasterNodeTimeout());
407+
params.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
398408
return request;
399409
}
400410

client/rest-high-level/src/test/java/org/elasticsearch/client/CrudIT.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ public void testSourceDoesNotExist() throws IOException {
255255
.put("number_of_shards", 1)
256256
.put("number_of_replicas", 0)
257257
.build();
258-
String mapping = "\"_doc\": { \"_source\": {\n" +
259-
" \"enabled\": false\n" +
260-
" } }";
258+
String mapping = "\"_source\": {\"enabled\": false}";
261259
createIndex(noSourceIndex, settings, mapping);
262260
assertEquals(
263261
RestStatus.OK,
@@ -1242,7 +1240,7 @@ public void testTermvectors() throws IOException {
12421240
.put("number_of_shards", 1)
12431241
.put("number_of_replicas", 0)
12441242
.build();
1245-
String mappings = "\"_doc\":{\"properties\":{\"field\":{\"type\":\"text\"}}}";
1243+
String mappings = "\"properties\":{\"field\":{\"type\":\"text\"}}";
12461244
createIndex(sourceIndex, settings, mappings);
12471245
assertEquals(
12481246
RestStatus.OK,
@@ -1318,7 +1316,7 @@ public void testMultiTermvectors() throws IOException {
13181316
.put("number_of_shards", 1)
13191317
.put("number_of_replicas", 0)
13201318
.build();
1321-
String mappings = "\"_doc\":{\"properties\":{\"field\":{\"type\":\"text\"}}}";
1319+
String mappings = "\"properties\":{\"field\":{\"type\":\"text\"}}";
13221320
createIndex(sourceIndex, settings, mappings);
13231321
assertEquals(
13241322
RestStatus.OK,

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public void testGetIndex() throws IOException {
341341
.put(SETTING_NUMBER_OF_SHARDS, 1)
342342
.put(SETTING_NUMBER_OF_REPLICAS, 0)
343343
.build();
344-
String mappings = "\"_doc\":{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}";
344+
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
345345
createIndex(indexName, basicSettings, mappings);
346346

347347
GetIndexRequest getIndexRequest = new GetIndexRequest()
@@ -371,7 +371,7 @@ public void testGetIndexWithDefaults() throws IOException {
371371
.put(SETTING_NUMBER_OF_SHARDS, 1)
372372
.put(SETTING_NUMBER_OF_REPLICAS, 0)
373373
.build();
374-
String mappings = "\"_doc\":{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}";
374+
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
375375
createIndex(indexName, basicSettings, mappings);
376376

377377
GetIndexRequest getIndexRequest = new GetIndexRequest()
@@ -1251,8 +1251,8 @@ public void testPutTemplate() throws Exception {
12511251
assertThat(extractRawValues("my-template.index_patterns", templates), contains("pattern-1", "name-*"));
12521252
assertThat(extractValue("my-template.settings.index.number_of_shards", templates), equalTo("3"));
12531253
assertThat(extractValue("my-template.settings.index.number_of_replicas", templates), equalTo("0"));
1254-
assertThat(extractValue("my-template.mappings.doc.properties.host_name.type", templates), equalTo("keyword"));
1255-
assertThat(extractValue("my-template.mappings.doc.properties.description.type", templates), equalTo("text"));
1254+
assertThat(extractValue("my-template.mappings.properties.host_name.type", templates), equalTo("keyword"));
1255+
assertThat(extractValue("my-template.mappings.properties.description.type", templates), equalTo("text"));
12561256
assertThat((Map<String, String>) extractValue("my-template.aliases.alias-1", templates), hasEntry("index_routing", "abc"));
12571257
assertThat((Map<String, String>) extractValue("my-template.aliases.{index}-write", templates), hasEntry("search_routing", "xyz"));
12581258
}

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import static org.elasticsearch.index.RandomCreateIndexGenerator.randomCreateIndexRequest;
7979
import static org.elasticsearch.index.RandomCreateIndexGenerator.randomIndexSettings;
8080
import static org.elasticsearch.index.alias.RandomAliasActionsGenerator.randomAliasAction;
81+
import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER;
8182
import static org.hamcrest.CoreMatchers.equalTo;
8283
import static org.hamcrest.Matchers.nullValue;
8384

@@ -132,6 +133,7 @@ public void testCreateIndex() throws IOException {
132133
RequestConvertersTests.setRandomTimeout(createIndexRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
133134
RequestConvertersTests.setRandomMasterTimeout(createIndexRequest, expectedParams);
134135
RequestConvertersTests.setRandomWaitForActiveShards(createIndexRequest::waitForActiveShards, expectedParams);
136+
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
135137

136138
Request request = IndicesRequestConverters.createIndex(createIndexRequest);
137139
Assert.assertEquals("/" + createIndexRequest.index(), request.getEndpoint());
@@ -173,6 +175,7 @@ public void testPutMapping() throws IOException {
173175

174176
RequestConvertersTests.setRandomTimeout(putMappingRequest::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams);
175177
RequestConvertersTests.setRandomMasterTimeout(putMappingRequest, expectedParams);
178+
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
176179

177180
Request request = IndicesRequestConverters.putMapping(putMappingRequest);
178181
StringJoiner endpoint = new StringJoiner("/", "/", "");
@@ -214,6 +217,7 @@ public void testGetMapping() throws IOException {
214217
getMappingRequest::indicesOptions, expectedParams);
215218
RequestConvertersTests.setRandomMasterTimeout(getMappingRequest, expectedParams);
216219
RequestConvertersTests.setRandomLocal(getMappingRequest, expectedParams);
220+
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
217221

218222
Request request = IndicesRequestConverters.getMappings(getMappingRequest);
219223
StringJoiner endpoint = new StringJoiner("/", "/", "");
@@ -266,6 +270,7 @@ public void testGetFieldMapping() throws IOException {
266270
RequestConvertersTests.setRandomIndicesOptions(getFieldMappingsRequest::indicesOptions, getFieldMappingsRequest::indicesOptions,
267271
expectedParams);
268272
RequestConvertersTests.setRandomLocal(getFieldMappingsRequest::local, expectedParams);
273+
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
269274

270275
Request request = IndicesRequestConverters.getFieldMapping(getFieldMappingsRequest);
271276
StringJoiner endpoint = new StringJoiner("/", "/", "");
@@ -835,6 +840,8 @@ public void testPutTemplateRequest() throws Exception {
835840
expectedParams.put("cause", cause);
836841
}
837842
RequestConvertersTests.setRandomMasterTimeout(putTemplateRequest, expectedParams);
843+
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
844+
838845
Request request = IndicesRequestConverters.putTemplate(putTemplateRequest);
839846
Assert.assertThat(request.getEndpoint(), equalTo("/_template/" + names.get(putTemplateRequest.name())));
840847
Assert.assertThat(request.getParameters(), equalTo(expectedParams));
@@ -888,6 +895,8 @@ public void testGetTemplateRequest() throws Exception {
888895
Map<String, String> expectedParams = new HashMap<>();
889896
RequestConvertersTests.setRandomMasterTimeout(getTemplatesRequest::setMasterNodeTimeout, expectedParams);
890897
RequestConvertersTests.setRandomLocal(getTemplatesRequest::setLocal, expectedParams);
898+
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
899+
891900
Request request = IndicesRequestConverters.getTemplates(getTemplatesRequest);
892901
Assert.assertThat(request.getEndpoint(),
893902
equalTo("/_template/" + names.stream().map(encodes::get).collect(Collectors.joining(","))));

client/rest-high-level/src/test/java/org/elasticsearch/client/SearchIT.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,9 @@ public void indexDocuments() throws IOException {
140140
create.setJsonEntity(
141141
"{" +
142142
" \"mappings\": {" +
143-
" \"_doc\": {" +
144-
" \"properties\": {" +
145-
" \"rating\": {" +
146-
" \"type\": \"keyword\"" +
147-
" }" +
143+
" \"properties\": {" +
144+
" \"rating\": {" +
145+
" \"type\": \"keyword\"" +
148146
" }" +
149147
" }" +
150148
" }" +
@@ -172,16 +170,14 @@ public void indexDocuments() throws IOException {
172170
create.setJsonEntity(
173171
"{" +
174172
" \"mappings\": {" +
175-
" \"_doc\": {" +
176-
" \"properties\": {" +
177-
" \"field1\": {" +
178-
" \"type\": \"keyword\"," +
179-
" \"store\": true" +
180-
" }," +
181-
" \"field2\": {" +
182-
" \"type\": \"keyword\"," +
183-
" \"store\": true" +
184-
" }" +
173+
" \"properties\": {" +
174+
" \"field1\": {" +
175+
" \"type\": \"keyword\"," +
176+
" \"store\": true" +
177+
" }," +
178+
" \"field2\": {" +
179+
" \"type\": \"keyword\"," +
180+
" \"store\": true" +
185181
" }" +
186182
" }" +
187183
" }" +
@@ -445,12 +441,10 @@ public void testSearchWithParentJoin() throws IOException {
445441
createIndex.setJsonEntity(
446442
"{\n" +
447443
" \"mappings\": {\n" +
448-
" \"_doc\" : {\n" +
449-
" \"properties\" : {\n" +
450-
" \"qa_join_field\" : {\n" +
451-
" \"type\" : \"join\",\n" +
452-
" \"relations\" : { \"question\" : \"answer\" }\n" +
453-
" }\n" +
444+
" \"properties\" : {\n" +
445+
" \"qa_join_field\" : {\n" +
446+
" \"type\" : \"join\",\n" +
447+
" \"relations\" : { \"question\" : \"answer\" }\n" +
454448
" }\n" +
455449
" }\n" +
456450
" }" +

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -792,17 +792,15 @@ public void testReindex() throws Exception {
792792
RestHighLevelClient client = highLevelClient();
793793
{
794794
String mapping =
795-
"\"_doc\": {\n" +
796-
" \"properties\": {\n" +
797-
" \"user\": {\n" +
798-
" \"type\": \"text\"\n" +
799-
" },\n" +
800-
" \"field1\": {\n" +
801-
" \"type\": \"integer\"\n" +
802-
" },\n" +
803-
" \"field2\": {\n" +
804-
" \"type\": \"integer\"\n" +
805-
" }\n" +
795+
" \"properties\": {\n" +
796+
" \"user\": {\n" +
797+
" \"type\": \"text\"\n" +
798+
" },\n" +
799+
" \"field1\": {\n" +
800+
" \"type\": \"integer\"\n" +
801+
" },\n" +
802+
" \"field2\": {\n" +
803+
" \"type\": \"integer\"\n" +
806804
" }\n" +
807805
" }";
808806
createIndex("source1", Settings.EMPTY, mapping);
@@ -1000,19 +998,17 @@ public void testUpdateByQuery() throws Exception {
1000998
RestHighLevelClient client = highLevelClient();
1001999
{
10021000
String mapping =
1003-
"\"_doc\": {\n" +
1004-
" \"properties\": {\n" +
1005-
" \"user\": {\n" +
1006-
" \"type\": \"text\"\n" +
1007-
" },\n" +
1008-
" \"field1\": {\n" +
1009-
" \"type\": \"integer\"\n" +
1010-
" },\n" +
1011-
" \"field2\": {\n" +
1012-
" \"type\": \"integer\"\n" +
1013-
" }\n" +
1014-
" }\n" +
1015-
" }";
1001+
" \"properties\": {\n" +
1002+
" \"user\": {\n" +
1003+
" \"type\": \"text\"\n" +
1004+
" },\n" +
1005+
" \"field1\": {\n" +
1006+
" \"type\": \"integer\"\n" +
1007+
" },\n" +
1008+
" \"field2\": {\n" +
1009+
" \"type\": \"integer\"\n" +
1010+
" }\n" +
1011+
" }";
10161012
createIndex("source1", Settings.EMPTY, mapping);
10171013
createIndex("source2", Settings.EMPTY, mapping);
10181014
createPipeline("my_pipeline");
@@ -1125,19 +1121,17 @@ public void testDeleteByQuery() throws Exception {
11251121
RestHighLevelClient client = highLevelClient();
11261122
{
11271123
String mapping =
1128-
"\"_doc\": {\n" +
1129-
" \"properties\": {\n" +
1130-
" \"user\": {\n" +
1131-
" \"type\": \"text\"\n" +
1132-
" },\n" +
1133-
" \"field1\": {\n" +
1134-
" \"type\": \"integer\"\n" +
1135-
" },\n" +
1136-
" \"field2\": {\n" +
1137-
" \"type\": \"integer\"\n" +
1138-
" }\n" +
1139-
" }\n" +
1140-
" }";
1124+
" \"properties\": {\n" +
1125+
" \"user\": {\n" +
1126+
" \"type\": \"text\"\n" +
1127+
" },\n" +
1128+
" \"field1\": {\n" +
1129+
" \"type\": \"integer\"\n" +
1130+
" },\n" +
1131+
" \"field2\": {\n" +
1132+
" \"type\": \"integer\"\n" +
1133+
" }\n" +
1134+
" }";
11411135
createIndex("source1", Settings.EMPTY, mapping);
11421136
createIndex("source2", Settings.EMPTY, mapping);
11431137
}

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/RequestsWithoutContentIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void testPutSettingsMissingBody() throws IOException {
4848

4949
public void testPutMappingsMissingBody() throws IOException {
5050
ResponseException responseException = expectThrows(ResponseException.class, () ->
51-
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/test_index/test_type/_mapping")));
51+
client().performRequest(new Request(randomBoolean() ? "POST" : "PUT", "/test_index/_mapping")));
5252
assertResponseException(responseException, "request body is required");
5353
}
5454

docs/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ for (int i = 0; i < 5; i++) {
525525
buildRestTests.setups['library'] = '''
526526
- do:
527527
indices.create:
528+
include_type_name: true
528529
index: library
529530
body:
530531
settings:

docs/painless/painless-contexts/painless-context-examples.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ the request URL.
4343
+
4444
[source,js]
4545
----
46-
PUT /seats
46+
PUT /seats?include_type_name=true
4747
{
4848
"mappings": {
4949
"seat": {

docs/painless/painless-execute-script.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ index:: The name of an index containing a mapping that is compatible with the do
7171

7272
[source,js]
7373
----------------------------------------------------------------
74-
PUT /my-index
74+
PUT /my-index?include_type_name=true
7575
{
7676
"mappings": {
7777
"_doc": {
@@ -129,7 +129,7 @@ query:: If `_score` is used in the script then a query can specified that will b
129129

130130
[source,js]
131131
----------------------------------------------------------------
132-
PUT /my-index
132+
PUT /my-index?include_type_name=true
133133
{
134134
"mappings": {
135135
"_doc": {

0 commit comments

Comments
 (0)