From 59d1e6912951884df56da24bf06bd4cc33b12476 Mon Sep 17 00:00:00 2001 From: Suraj Singh <79435743+dreamer-89@users.noreply.github.com> Date: Mon, 21 Mar 2022 16:49:18 -0700 Subject: [PATCH] [Remove] Types from PutIndexTemplateRequest and builder to reduce mapping to a string (#2510) Signed-off-by: Suraj Singh --- .../cluster/SimpleClusterStateIT.java | 10 +-- .../gateway/RecoveryFromGatewayIT.java | 5 +- .../template/IndexTemplateBlocksIT.java | 5 +- .../template/SimpleIndexTemplateIT.java | 64 +++----------- .../snapshots/RestoreSnapshotIT.java | 5 +- .../SnapshotCustomPluginStateIT.java | 5 +- .../template/put/PutIndexTemplateRequest.java | 86 ++++++++++--------- .../put/PutIndexTemplateRequestBuilder.java | 21 +---- .../MetadataIndexTemplateService.java | 17 ++-- .../put/PutIndexTemplateRequestTests.java | 16 ++-- .../MetadataIndexTemplateServiceTests.java | 11 +-- 11 files changed, 85 insertions(+), 160 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java index fcf5dcf3891..19f7b0b4c63 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java @@ -166,11 +166,9 @@ public class SimpleClusterStateIT extends OpenSearchIntegTestCase { .preparePutTemplate("foo_template") .setPatterns(Collections.singletonList("te*")) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -182,7 +180,6 @@ public class SimpleClusterStateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .get(); @@ -191,11 +188,9 @@ public class SimpleClusterStateIT extends OpenSearchIntegTestCase { .preparePutTemplate("fuu_template") .setPatterns(Collections.singletonList("test*")) .setOrder(1) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field2") .field("type", "text") @@ -203,7 +198,6 @@ public class SimpleClusterStateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java index d76e21ea712..92d8dc6a0bb 100644 --- a/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java @@ -461,11 +461,9 @@ public class RecoveryFromGatewayIT extends OpenSearchIntegTestCase { .preparePutTemplate("template_1") .setPatterns(Collections.singletonList("te*")) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -477,7 +475,6 @@ public class RecoveryFromGatewayIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/template/IndexTemplateBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/template/IndexTemplateBlocksIT.java index 721e05a8671..21e3e58d4d0 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/template/IndexTemplateBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/template/IndexTemplateBlocksIT.java @@ -54,11 +54,9 @@ public class IndexTemplateBlocksIT extends OpenSearchIntegTestCase { .preparePutTemplate("template_blocks") .setPatterns(Collections.singletonList("te*")) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -70,7 +68,6 @@ public class IndexTemplateBlocksIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java index 090cf81de60..0e15a0c8954 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java @@ -110,11 +110,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .setPatterns(Collections.singletonList("te*")) .setSettings(indexSettings()) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -126,7 +124,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .get(); @@ -136,11 +133,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .setPatterns(Collections.singletonList("test*")) .setSettings(indexSettings()) .setOrder(1) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field2") .field("type", "text") @@ -148,7 +143,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .get(); @@ -161,11 +155,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .setSettings(indexSettings()) .setCreate(true) .setOrder(1) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field2") .field("type", "text") @@ -173,7 +165,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ), IllegalArgumentException.class ); @@ -223,11 +214,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .preparePutTemplate("template_1") .setPatterns(Collections.singletonList("te*")) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -239,7 +228,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); @@ -249,11 +237,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .preparePutTemplate("template_2") .setPatterns(Collections.singletonList("test*")) .setOrder(1) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field2") .field("type", "text") @@ -261,7 +247,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); @@ -281,11 +266,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .preparePutTemplate("template_1") .setPatterns(Collections.singletonList("te*")) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -297,7 +280,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); @@ -322,11 +304,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .setPatterns(Collections.singletonList("te*")) .setOrder(0) .setVersion(123) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -338,7 +318,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); @@ -367,11 +346,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .preparePutTemplate("template_1") .setPatterns(Collections.singletonList("te*")) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -383,7 +360,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); @@ -394,11 +370,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .preparePutTemplate("template_2") .setPatterns(Collections.singletonList("te*")) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -410,7 +384,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); @@ -421,11 +394,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .preparePutTemplate("template3") .setPatterns(Collections.singletonList("te*")) .setOrder(0) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -437,7 +408,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .execute() .actionGet(); @@ -507,7 +477,7 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .indices() .preparePutTemplate("template_1") .setPatterns(Collections.singletonList("te*")) - .addMapping("type1", "{\"foo\": \"abcde\"}", XContentType.JSON) + .setMapping("{\"foo\": \"abcde\"}", XContentType.JSON) .get() ); assertThat(e.getMessage(), containsString("Failed to parse mapping ")); @@ -896,11 +866,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .setPatterns(Collections.singletonList("test*")) .setCreate(true) .setOrder(1) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field2") .field("type", "text") @@ -908,7 +876,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .get() ); @@ -946,11 +913,9 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .preparePutTemplate("template_1") .setPatterns(Arrays.asList("a*", "b*")) .setSettings(indexSettings()) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -962,7 +927,6 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .get(); @@ -1027,7 +991,7 @@ public class SimpleIndexTemplateIT extends OpenSearchIntegTestCase { .indices() .preparePutTemplate("template_2") .setPatterns(Collections.singletonList("te*")) - .addMapping("type", "{\"type\":{\"_routing\":{\"required\":false}}}", XContentType.JSON) + .setMapping("{\"_routing\":{\"required\":false}}", XContentType.JSON) .setSettings(Settings.builder().put("index.number_of_shards", "6").put("index.routing_partition_size", "3")) .get() ); diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java index 643a301c025..3a7fdd40936 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java @@ -424,11 +424,9 @@ public class RestoreSnapshotIT extends AbstractSnapshotIntegTestCase { .indices() .preparePutTemplate("test-template") .setPatterns(Collections.singletonList("te*")) - .addMapping( - "_doc", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") .startObject("properties") .startObject("field1") .field("type", "text") @@ -440,7 +438,6 @@ public class RestoreSnapshotIT extends AbstractSnapshotIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .get() .isAcknowledged(), diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java index 90ec4940a95..ea1635b1d80 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/SnapshotCustomPluginStateIT.java @@ -81,11 +81,9 @@ public class SnapshotCustomPluginStateIT extends AbstractSnapshotIntegTestCase { .indices() .preparePutTemplate("test-template") .setPatterns(Collections.singletonList("te*")) - .addMapping( - "_doc", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") .startObject("properties") .startObject("field1") .field("type", "text") @@ -97,7 +95,6 @@ public class SnapshotCustomPluginStateIT extends AbstractSnapshotIntegTestCase { .endObject() .endObject() .endObject() - .endObject() ) .get() .isAcknowledged(), diff --git a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java index d443d14f3f4..608e3da6993 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequest.java @@ -33,16 +33,17 @@ package org.opensearch.action.admin.indices.template.put; import org.opensearch.OpenSearchGenerationException; import org.opensearch.OpenSearchParseException; +import org.opensearch.Version; import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.IndicesRequest; import org.opensearch.action.admin.indices.alias.Alias; import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest; import org.opensearch.action.support.IndicesOptions; import org.opensearch.action.support.master.MasterNodeRequest; +import org.opensearch.common.Nullable; import org.opensearch.common.Strings; import org.opensearch.common.bytes.BytesArray; import org.opensearch.common.bytes.BytesReference; -import org.opensearch.common.collect.MapBuilder; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.logging.DeprecationLogger; @@ -62,7 +63,6 @@ import org.opensearch.index.mapper.MapperService; import java.io.IOException; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -94,7 +94,8 @@ public class PutIndexTemplateRequest extends MasterNodeRequest mappings = new HashMap<>(); + @Nullable + private String mappings; private final Set aliases = new HashSet<>(); @@ -108,11 +109,14 @@ public class PutIndexTemplateRequest extends MasterNodeRequest mappingAsMap = XContentHelper.convertToMap(source, false, xContentType).v2(); - return mapping(type, mappingAsMap); + return mapping(mappingAsMap); } /** * Adds mapping that will be added when the index gets created. * - * @param type The mapping type * @param source The mapping source */ - public PutIndexTemplateRequest mapping(String type, Map source) { - // wrap it in a type map if its not - if (source.size() != 1 || !source.containsKey(type)) { - source = MapBuilder.newMapBuilder().put(type, source).map(); + public PutIndexTemplateRequest mapping(Map source) { + if (source.size() != 1 || source.containsKey(MapperService.SINGLE_MAPPING_NAME) == false) { + source = Map.of(MapperService.SINGLE_MAPPING_NAME, source); } try { XContentBuilder builder = XContentFactory.jsonBuilder(); builder.map(source); - mappings.put(type, Strings.toString(builder)); + mappings = Strings.toString(builder); return this; } catch (IOException e) { throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e); @@ -305,11 +304,11 @@ public class PutIndexTemplateRequest extends MasterNodeRequest mappings() { + public String mappings() { return this.mappings; } @@ -372,7 +371,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest) entry1.getValue()); + mapping((Map) entry1.getValue()); } } else if (name.equals("aliases")) { aliases((Map) entry.getValue()); @@ -489,10 +488,14 @@ public class PutIndexTemplateRequest extends MasterNodeRequest entry : mappings.entrySet()) { - out.writeString(entry.getKey()); - out.writeString(entry.getValue()); + if (out.getVersion().before(Version.V_2_0_0)) { + out.writeVInt(mappings == null ? 0 : 1); + if (mappings != null) { + out.writeString(MapperService.SINGLE_MAPPING_NAME); + out.writeString(mappings); + } + } else { + out.writeOptionalString(mappings); } out.writeVInt(aliases.size()); for (Alias alias : aliases) { @@ -516,20 +519,19 @@ public class PutIndexTemplateRequest extends MasterNodeRequest entry : mappings.entrySet()) { - builder.field(entry.getKey()); + if (mappings != null) { + builder.field(MapperService.SINGLE_MAPPING_NAME); try ( XContentParser parser = JsonXContent.jsonXContent.createParser( NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - entry.getValue() + mappings ) ) { builder.copyCurrentStructure(parser); } } builder.endObject(); - builder.startObject("aliases"); for (Alias alias : aliases) { alias.toXContent(builder, params); diff --git a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java index df3b5f64175..e5a02acb4a6 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequestBuilder.java @@ -124,12 +124,11 @@ public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBu /** * Adds mapping that will be added when the index template gets created. * - * @param type The mapping type * @param source The mapping source * @param xContentType The type/format of the source */ - public PutIndexTemplateRequestBuilder addMapping(String type, String source, XContentType xContentType) { - request.mapping(type, source, xContentType); + public PutIndexTemplateRequestBuilder setMapping(String source, XContentType xContentType) { + request.mapping(source, xContentType); return this; } @@ -196,22 +195,10 @@ public class PutIndexTemplateRequestBuilder extends MasterNodeOperationRequestBu /** * Adds mapping that will be added when the index template gets created. * - * @param type The mapping type * @param source The mapping source */ - public PutIndexTemplateRequestBuilder addMapping(String type, XContentBuilder source) { - request.mapping(type, source); - return this; - } - - /** - * Adds mapping that will be added when the index gets created. - * - * @param type The mapping type - * @param source The mapping source - */ - public PutIndexTemplateRequestBuilder addMapping(String type, Map source) { - request.mapping(type, source); + public PutIndexTemplateRequestBuilder setMapping(XContentBuilder source) { + request.mapping(source); return this; } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java index 22cd5c1dbbb..896679206ae 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/MetadataIndexTemplateService.java @@ -915,11 +915,11 @@ public class MetadataIndexTemplateService { templateBuilder.patterns(request.indexPatterns); templateBuilder.settings(request.settings); - for (Map.Entry entry : request.mappings.entrySet()) { + if (request.mappings != null) { try { - templateBuilder.putMapping(entry.getKey(), entry.getValue()); + templateBuilder.putMapping(MapperService.SINGLE_MAPPING_NAME, request.mappings); } catch (Exception e) { - throw new MapperParsingException("Failed to parse mapping [{}]: {}", e, entry.getKey(), e.getMessage()); + throw new MapperParsingException("Failed to parse mapping: {}", e, request.mappings); } } @@ -1511,7 +1511,7 @@ public class MetadataIndexTemplateService { Integer version; List indexPatterns; Settings settings = Settings.Builder.EMPTY_SETTINGS; - Map mappings = new HashMap<>(); + String mappings = null; List aliases = new ArrayList<>(); TimeValue masterTimeout = MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT; @@ -1541,8 +1541,8 @@ public class MetadataIndexTemplateService { return this; } - public PutRequest mappings(Map mappings) { - this.mappings.putAll(mappings); + public PutRequest mappings(String mappings) { + this.mappings = mappings; return this; } @@ -1551,11 +1551,6 @@ public class MetadataIndexTemplateService { return this; } - public PutRequest putMapping(String mappingType, String mappingSource) { - mappings.put(mappingType, mappingSource); - return this; - } - public PutRequest masterTimeout(TimeValue masterTimeout) { this.masterTimeout = masterTimeout; return this; diff --git a/server/src/test/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java index db174aeca94..f4cdb778a31 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/template/put/PutIndexTemplateRequestTests.java @@ -39,6 +39,7 @@ import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentFactory; import org.opensearch.common.xcontent.XContentParser; import org.opensearch.common.xcontent.XContentType; +import org.opensearch.index.mapper.MapperService; import org.opensearch.test.AbstractXContentTestCase; import java.io.IOException; @@ -90,10 +91,9 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCasenewMapBuilder().put("type3", nakedMapping).map()); + request1.mapping(nakedMapping); + request2.mapping(MapBuilder.newMapBuilder().put(MapperService.SINGLE_MAPPING_NAME, nakedMapping).map()); assertEquals(request1.mappings(), request2.mappings()); } } @@ -163,7 +162,6 @@ public class PutIndexTemplateRequestTests extends AbstractXContentTestCase errors = putTemplateDetail(request); assertThat(errors.size(), equalTo(1)); @@ -223,7 +220,7 @@ public class MetadataIndexTemplateServiceTests extends OpenSearchSingleNodeTestC // invalid json: put index template fails PutRequest request = new PutRequest("api", "blank_mapping"); request.patterns(singletonList("te*")); - request.putMapping("type1", "{}"); + request.mappings("{}"); Set aliases = new HashSet<>(); aliases.add(new Alias("invalid_alias").filter("abcde")); request.aliases(aliases); @@ -2073,7 +2070,7 @@ public class MetadataIndexTemplateServiceTests extends OpenSearchSingleNodeTestC pr.settings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).build()); } if (randomBoolean()) { - pr.mappings(Collections.emptyMap()); + pr.mappings("{}"); } if (randomBoolean()) { pr.aliases(Collections.singleton(new Alias("alias")));