From f34a75381d40575c9859760a6be655acd5da2058 Mon Sep 17 00:00:00 2001 From: Suraj Singh <79435743+dreamer-89@users.noreply.github.com> Date: Thu, 17 Mar 2022 09:02:08 -0700 Subject: [PATCH 1/2] [Remove] Type metadata from ingest documents (#2491) Signed-off-by: Suraj Singh --- .../ingest/common/AppendProcessorTests.java | 2 +- .../ingest/common/SetProcessorTests.java | 2 +- .../ingest/SimulatePipelineRequest.java | 6 ---- .../org/opensearch/ingest/IngestDocument.java | 2 -- .../SimulatePipelineRequestParsingTests.java | 33 ++----------------- 5 files changed, 4 insertions(+), 41 deletions(-) diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/AppendProcessorTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/AppendProcessorTests.java index 9a507338df332..7caa63792f347 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/AppendProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/AppendProcessorTests.java @@ -147,7 +147,7 @@ public void testConvertScalarToList() throws Exception { public void testAppendMetadataExceptVersion() throws Exception { // here any metadata field value becomes a list, which won't make sense in most of the cases, // but support for append is streamlined like for set so we test it - Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.TYPE, Metadata.ID, Metadata.ROUTING); + Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.ID, Metadata.ROUTING); List values = new ArrayList<>(); Processor appendProcessor; if (randomBoolean()) { diff --git a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/SetProcessorTests.java b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/SetProcessorTests.java index 0e7ba5556fbf8..923757b605108 100644 --- a/modules/ingest-common/src/test/java/org/opensearch/ingest/common/SetProcessorTests.java +++ b/modules/ingest-common/src/test/java/org/opensearch/ingest/common/SetProcessorTests.java @@ -116,7 +116,7 @@ public void testSetExistingNullFieldWithOverrideDisabled() throws Exception { } public void testSetMetadataExceptVersion() throws Exception { - Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.TYPE, Metadata.ID, Metadata.ROUTING); + Metadata randomMetadata = randomFrom(Metadata.INDEX, Metadata.ID, Metadata.ROUTING); Processor processor = createSetProcessor(randomMetadata.getFieldName(), "_value", true, false); IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random()); processor.execute(ingestDocument); diff --git a/server/src/main/java/org/opensearch/action/ingest/SimulatePipelineRequest.java b/server/src/main/java/org/opensearch/action/ingest/SimulatePipelineRequest.java index 6223f25488d88..bc0317e076319 100644 --- a/server/src/main/java/org/opensearch/action/ingest/SimulatePipelineRequest.java +++ b/server/src/main/java/org/opensearch/action/ingest/SimulatePipelineRequest.java @@ -194,12 +194,6 @@ private static List parseDocs(Map config) { Map dataMap = (Map) object; Map document = ConfigurationUtils.readMap(null, null, dataMap, Fields.SOURCE); String index = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.INDEX.getFieldName(), "_index"); - if (dataMap.containsKey(Metadata.TYPE.getFieldName())) { - deprecationLogger.deprecate( - "simulate_pipeline_with_types", - "[types removal] specifying _type in pipeline simulation requests is deprecated" - ); - } String id = ConfigurationUtils.readStringOrIntProperty(null, null, dataMap, Metadata.ID.getFieldName(), "_id"); String routing = ConfigurationUtils.readOptionalStringOrIntProperty(null, null, dataMap, Metadata.ROUTING.getFieldName()); Long version = null; diff --git a/server/src/main/java/org/opensearch/ingest/IngestDocument.java b/server/src/main/java/org/opensearch/ingest/IngestDocument.java index b496799c34dd0..b18946486f8c6 100644 --- a/server/src/main/java/org/opensearch/ingest/IngestDocument.java +++ b/server/src/main/java/org/opensearch/ingest/IngestDocument.java @@ -38,7 +38,6 @@ import org.opensearch.index.mapper.IndexFieldMapper; import org.opensearch.index.mapper.RoutingFieldMapper; import org.opensearch.index.mapper.SourceFieldMapper; -import org.opensearch.index.mapper.TypeFieldMapper; import org.opensearch.index.mapper.VersionFieldMapper; import org.opensearch.script.TemplateScript; @@ -846,7 +845,6 @@ public String toString() { public enum Metadata { INDEX(IndexFieldMapper.NAME), - TYPE(TypeFieldMapper.NAME), ID(IdFieldMapper.NAME), ROUTING(RoutingFieldMapper.NAME), VERSION(VersionFieldMapper.NAME), diff --git a/server/src/test/java/org/opensearch/action/ingest/SimulatePipelineRequestParsingTests.java b/server/src/test/java/org/opensearch/action/ingest/SimulatePipelineRequestParsingTests.java index c85c0a01de63e..36b1f8089fdea 100644 --- a/server/src/test/java/org/opensearch/action/ingest/SimulatePipelineRequestParsingTests.java +++ b/server/src/test/java/org/opensearch/action/ingest/SimulatePipelineRequestParsingTests.java @@ -57,7 +57,6 @@ import static org.opensearch.ingest.IngestDocument.Metadata.ID; import static org.opensearch.ingest.IngestDocument.Metadata.INDEX; import static org.opensearch.ingest.IngestDocument.Metadata.ROUTING; -import static org.opensearch.ingest.IngestDocument.Metadata.TYPE; import static org.opensearch.ingest.IngestDocument.Metadata.VERSION; import static org.opensearch.ingest.IngestDocument.Metadata.VERSION_TYPE; import static org.opensearch.ingest.IngestDocument.Metadata.IF_SEQ_NO; @@ -132,15 +131,7 @@ public void testParseUsingPipelineStore(boolean useExplicitType) throws Exceptio assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(1)); } - public void testParseWithProvidedPipelineNoType() throws Exception { - innerTestParseWithProvidedPipeline(false); - } - - public void testParseWithProvidedPipelineWithType() throws Exception { - innerTestParseWithProvidedPipeline(true); - } - - private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws Exception { + public void innerTestParseWithProvidedPipeline() throws Exception { int numDocs = randomIntBetween(1, 10); Map requestContent = new HashMap<>(); @@ -150,16 +141,7 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws for (int i = 0; i < numDocs; i++) { Map doc = new HashMap<>(); Map expectedDoc = new HashMap<>(); - List fields = Arrays.asList( - INDEX, - TYPE, - ID, - ROUTING, - VERSION, - VERSION_TYPE, - IF_SEQ_NO, - IF_PRIMARY_TERM - ); + List fields = Arrays.asList(INDEX, ID, ROUTING, VERSION, VERSION_TYPE, IF_SEQ_NO, IF_PRIMARY_TERM); for (IngestDocument.Metadata field : fields) { if (field == VERSION) { Long value = randomLong(); @@ -173,14 +155,6 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws Long value = randomNonNegativeLong(); doc.put(field.getFieldName(), value); expectedDoc.put(field.getFieldName(), value); - } else if (field == TYPE) { - if (useExplicitType) { - String value = randomAlphaOfLengthBetween(1, 10); - doc.put(field.getFieldName(), value); - expectedDoc.put(field.getFieldName(), value); - } else { - expectedDoc.put(field.getFieldName(), "_doc"); - } } else { if (randomBoolean()) { String value = randomAlphaOfLengthBetween(1, 10); @@ -249,9 +223,6 @@ private void innerTestParseWithProvidedPipeline(boolean useExplicitType) throws assertThat(actualRequest.getPipeline().getId(), equalTo(SIMULATED_PIPELINE_ID)); assertThat(actualRequest.getPipeline().getDescription(), nullValue()); assertThat(actualRequest.getPipeline().getProcessors().size(), equalTo(numProcessors)); - if (useExplicitType) { - assertWarnings("[types removal] specifying _type in pipeline simulation requests is deprecated"); - } } public void testNullPipelineId() { From 2e3d3fef135442a59ec970c6bec7917467fa8d07 Mon Sep 17 00:00:00 2001 From: Nick Knize Date: Thu, 17 Mar 2022 12:05:24 -0500 Subject: [PATCH 2/2] [Remove] Type from PutIndexTemplateRequest and PITRB (#2497) Continues removal of types from PutIndexTemplateRequest and PutIndexTemplateRequestBuilder.mapping. Delegated mapping method in PutIndexTemplateRequestBuilder is refactored to setMapping for consistency with similar methods (e.g., setSettings, setAliases). Signed-off-by: Nicholas Walter Knize --- .../index/query/RankFeatureQueryBuilderTests.java | 2 +- .../percolator/PercolatorQuerySearchIT.java | 2 +- .../percolator/PercolateQueryBuilderTests.java | 4 ++-- .../PercolateWithNestedQueryBuilderTests.java | 2 +- .../document/AliasedIndexDocumentActionsIT.java | 2 +- .../java/org/opensearch/index/HiddenIndexIT.java | 10 +++++----- .../indices/template/SimpleIndexTemplateIT.java | 6 +++--- .../search/basic/TransportTwoNodesSearchIT.java | 2 +- .../search/searchafter/SearchAfterIT.java | 2 +- .../admin/indices/create/CreateIndexRequest.java | 6 ++---- .../indices/create/CreateIndexRequestBuilder.java | 4 ++-- .../indices/mapping/put/PutMappingRequest.java | 14 +++++++------- .../mapping/put/PutMappingRequestBuilder.java | 2 +- .../indices/rollover/RolloverRequestBuilder.java | 4 ++-- .../template/put/PutIndexTemplateRequest.java | 5 +++-- .../put/PutIndexTemplateRequestBuilder.java | 4 ++-- .../mapping/put/PutMappingRequestTests.java | 7 ++----- .../RangeFieldQueryStringQueryBuilderTests.java | 2 +- .../index/query/MatchQueryBuilderTests.java | 2 +- .../index/query/NestedQueryBuilderTests.java | 2 +- .../index/query/QueryStringQueryBuilderTests.java | 4 ++-- .../index/query/TermsSetQueryBuilderTests.java | 2 +- .../opensearch/test/AbstractBuilderTestCase.java | 2 +- .../test/OpenSearchSingleNodeTestCase.java | 2 +- 24 files changed, 45 insertions(+), 49 deletions(-) diff --git a/modules/mapper-extras/src/test/java/org/opensearch/index/query/RankFeatureQueryBuilderTests.java b/modules/mapper-extras/src/test/java/org/opensearch/index/query/RankFeatureQueryBuilderTests.java index b0d7bb9d2e14e..e183ba6f6735c 100644 --- a/modules/mapper-extras/src/test/java/org/opensearch/index/query/RankFeatureQueryBuilderTests.java +++ b/modules/mapper-extras/src/test/java/org/opensearch/index/query/RankFeatureQueryBuilderTests.java @@ -62,7 +62,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws "_doc", new CompressedXContent( Strings.toString( - PutMappingRequest.buildFromSimplifiedDef( + PutMappingRequest.simpleMapping( "my_feature_field", "type=rank_feature", "my_negative_feature_field", diff --git a/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java b/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java index 1cb5d81136de1..11fc61d6c6d99 100644 --- a/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java @@ -565,7 +565,7 @@ public void testPercolatorQueryWithHighlighting() throws Exception { client().admin() .indices() .prepareCreate("test") - .addMapping("type", "id", "type=keyword", "field1", fieldMapping, "query", "type=percolator") + .addMapping("type", "id", "type=keyword", "field1", fieldMapping.toString(), "query", "type=percolator") ); client().prepareIndex("test") .setId("1") diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java index 12be15552652c..44d8d64086091 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolateQueryBuilderTests.java @@ -110,14 +110,14 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws docType, new CompressedXContent( Strings.toString( - PutMappingRequest.buildFromSimplifiedDef(queryField, "type=percolator", aliasField, "type=alias,path=" + queryField) + PutMappingRequest.simpleMapping(queryField, "type=percolator", aliasField, "type=alias,path=" + queryField) ) ), MapperService.MergeReason.MAPPING_UPDATE ); mapperService.merge( docType, - new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(TEXT_FIELD_NAME, "type=text"))), + new CompressedXContent(Strings.toString(PutMappingRequest.simpleMapping(TEXT_FIELD_NAME, "type=text"))), MapperService.MergeReason.MAPPING_UPDATE ); } diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolateWithNestedQueryBuilderTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolateWithNestedQueryBuilderTests.java index 5038e72e9be5e..0ab9eff731bff 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolateWithNestedQueryBuilderTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolateWithNestedQueryBuilderTests.java @@ -50,7 +50,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws super.initializeAdditionalMappings(mapperService); mapperService.merge( "_doc", - new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("some_nested_object", "type=nested"))), + new CompressedXContent(Strings.toString(PutMappingRequest.simpleMapping("some_nested_object", "type=nested"))), MapperService.MergeReason.MAPPING_UPDATE ); } diff --git a/server/src/internalClusterTest/java/org/opensearch/document/AliasedIndexDocumentActionsIT.java b/server/src/internalClusterTest/java/org/opensearch/document/AliasedIndexDocumentActionsIT.java index de9db5f145116..1d9f7c1e39de2 100644 --- a/server/src/internalClusterTest/java/org/opensearch/document/AliasedIndexDocumentActionsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/document/AliasedIndexDocumentActionsIT.java @@ -49,7 +49,7 @@ protected void createIndex() { logger.info("--> creating index test"); client().admin() .indices() - .create(createIndexRequest("test1").mapping("type1", "name", "type=keyword,store=true").alias(new Alias("test"))) + .create(createIndexRequest("test1").simpleMapping("name", "type=keyword,store=true").alias(new Alias("test"))) .actionGet(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/index/HiddenIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/index/HiddenIndexIT.java index 54fbc8cecb967..7d1c92cba3205 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/HiddenIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/HiddenIndexIT.java @@ -122,7 +122,7 @@ public void testGlobalTemplatesDoNotApply() { .indices() .preparePutTemplate("a_global_template") .setPatterns(Collections.singletonList("*")) - .addMapping("_doc", "foo", "type=text") + .setMapping("foo", "type=text") .get() ); assertAcked( @@ -130,7 +130,7 @@ public void testGlobalTemplatesDoNotApply() { .indices() .preparePutTemplate("not_global_template") .setPatterns(Collections.singletonList("a*")) - .addMapping("_doc", "bar", "type=text") + .setMapping("bar", "type=text") .get() ); assertAcked( @@ -138,7 +138,7 @@ public void testGlobalTemplatesDoNotApply() { .indices() .preparePutTemplate("specific_template") .setPatterns(Collections.singletonList("a_hidden_index")) - .addMapping("_doc", "baz", "type=text") + .setMapping("baz", "type=text") .get() ); assertAcked( @@ -146,7 +146,7 @@ public void testGlobalTemplatesDoNotApply() { .indices() .preparePutTemplate("unused_template") .setPatterns(Collections.singletonList("not_used")) - .addMapping("_doc", "foobar", "type=text") + .setMapping("foobar", "type=text") .get() ); @@ -192,7 +192,7 @@ public void testNonGlobalTemplateCanMakeIndexHidden() { .indices() .preparePutTemplate("a_global_template") .setPatterns(Collections.singletonList("my_hidden_pattern*")) - .addMapping("_doc", "foo", "type=text") + .setMapping("foo", "type=text") .setSettings(Settings.builder().put("index.hidden", true).build()) .get() ); 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 378657a6554b4..6065db46d8ee2 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/template/SimpleIndexTemplateIT.java @@ -554,7 +554,7 @@ public void testIndexTemplateWithAliases() throws Exception { .indices() .preparePutTemplate("template_with_aliases") .setPatterns(Collections.singletonList("te*")) - .addMapping("_doc", "type", "type=keyword", "field", "type=text") + .setMapping("type", "type=keyword", "field", "type=text") .addAlias(new Alias("simple_alias")) .addAlias(new Alias("templated_alias-{index}")) .addAlias(new Alias("filtered_alias").filter("{\"term\":{\"type\":\"type2\"}}")) @@ -820,7 +820,7 @@ public void testStrictAliasParsingInIndicesCreatedViaTemplates() throws Exceptio .preparePutTemplate("template1") .setPatterns(Collections.singletonList("a*")) .setOrder(0) - .addMapping("test", "field", "type=text") + .setMapping("field", "type=text") .addAlias(new Alias("alias1").filter(termQuery("field", "value"))) .get(); // Indexing into b index should fail, since there is field with name 'field' in the mapping @@ -930,7 +930,7 @@ public void testOrderAndVersion() { .setPatterns(Collections.singletonList("te*")) .setVersion(version) .setOrder(order) - .addMapping("test", "field", "type=text") + .setMapping("field", "type=text") .get() ); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportTwoNodesSearchIT.java b/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportTwoNodesSearchIT.java index 420121006a943..5cd6e76e1e487 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportTwoNodesSearchIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/basic/TransportTwoNodesSearchIT.java @@ -96,7 +96,7 @@ private Set prepareData(int numShards) throws Exception { client().admin() .indices() - .create(createIndexRequest("test").settings(settingsBuilder).mapping("type", "foo", "type=geo_point")) + .create(createIndexRequest("test").settings(settingsBuilder).simpleMapping("foo", "type=geo_point")) .actionGet(); ensureGreen(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/searchafter/SearchAfterIT.java b/server/src/internalClusterTest/java/org/opensearch/search/searchafter/SearchAfterIT.java index b88e56b4f675d..aae6c1dec48b3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/searchafter/SearchAfterIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/searchafter/SearchAfterIT.java @@ -323,7 +323,7 @@ private void createIndexMappingsFromObjectType(String indexName, String typeName fail("Can't match type [" + type + "]"); } } - indexRequestBuilder.addMapping(typeName, mappings.toArray()).get(); + indexRequestBuilder.addMapping(typeName, mappings.toArray(new String[0])).get(); ensureGreen(); } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java index b234561563e56..7f1f516d13a04 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequest.java @@ -305,11 +305,9 @@ private CreateIndexRequest mapping(String type, Map source) { /** * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). - * @deprecated types are being removed */ - @Deprecated - public CreateIndexRequest mapping(String type, Object... source) { - mapping(PutMappingRequest.buildFromSimplifiedDef(source)); + public CreateIndexRequest simpleMapping(String... source) { + mapping(PutMappingRequest.simpleMapping(source)); return this; } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequestBuilder.java index 41f364517fd06..ac80b3eb6a155 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/create/CreateIndexRequestBuilder.java @@ -144,8 +144,8 @@ public CreateIndexRequestBuilder setMapping(Map source) { * @deprecated types are being removed */ @Deprecated - public CreateIndexRequestBuilder addMapping(String type, Object... source) { - request.mapping(type, source); + public CreateIndexRequestBuilder addMapping(String type, String... source) { + request.simpleMapping(source); return this; } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java index 52be45054ba55..be3e676a4a1a2 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequest.java @@ -217,8 +217,8 @@ public String source() { * Also supports metadata mapping fields such as `_all` and `_parent` as property definition, these metadata * mapping fields will automatically be put on the top level mapping object. */ - public PutMappingRequest source(Object... source) { - return source(buildFromSimplifiedDef(source)); + public PutMappingRequest source(String... source) { + return source(simpleMapping(source)); } public String origin() { @@ -239,7 +239,7 @@ public PutMappingRequest origin(String origin) { * if the number of the source arguments is not divisible by two * @return the mappings definition */ - public static XContentBuilder buildFromSimplifiedDef(Object... source) { + public static XContentBuilder simpleMapping(String... source) { if (source.length % 2 != 0) { throw new IllegalArgumentException("mapping source must be pairs of fieldnames and properties definition."); } @@ -248,10 +248,10 @@ public static XContentBuilder buildFromSimplifiedDef(Object... source) { builder.startObject(); for (int i = 0; i < source.length; i++) { - String fieldName = source[i++].toString(); + String fieldName = source[i++]; if (RESERVED_FIELDS.contains(fieldName)) { builder.startObject(fieldName); - String[] s1 = Strings.splitStringByCommaToArray(source[i].toString()); + String[] s1 = Strings.splitStringByCommaToArray(source[i]); for (String s : s1) { String[] s2 = Strings.split(s, "="); if (s2.length != 2) { @@ -265,13 +265,13 @@ public static XContentBuilder buildFromSimplifiedDef(Object... source) { builder.startObject("properties"); for (int i = 0; i < source.length; i++) { - String fieldName = source[i++].toString(); + String fieldName = source[i++]; if (RESERVED_FIELDS.contains(fieldName)) { continue; } builder.startObject(fieldName); - String[] s1 = Strings.splitStringByCommaToArray(source[i].toString()); + String[] s1 = Strings.splitStringByCommaToArray(source[i]); for (String s : s1) { String[] s2 = Strings.split(s, "="); if (s2.length != 2) { diff --git a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java index a1b3b40d4e961..3ef96254b3f9b 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestBuilder.java @@ -102,7 +102,7 @@ public PutMappingRequestBuilder setSource(String mappingSource, XContentType xCo * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). */ - public PutMappingRequestBuilder setSource(Object... source) { + public PutMappingRequestBuilder setSource(String... source) { request.source(source); return this; } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverRequestBuilder.java index a7af2f963d15b..c74f71a70e09d 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverRequestBuilder.java @@ -84,8 +84,8 @@ public RolloverRequestBuilder alias(Alias alias) { return this; } - public RolloverRequestBuilder mapping(String type, Object... source) { - this.request.getCreateIndexRequest().mapping(type, source); + public RolloverRequestBuilder simpleMapping(String... source) { + this.request.getCreateIndexRequest().simpleMapping(source); return this; } 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 2ea2e492ffe4d..d443d14f3f463 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 @@ -58,6 +58,7 @@ import org.opensearch.common.xcontent.XContentType; import org.opensearch.common.xcontent.json.JsonXContent; import org.opensearch.common.xcontent.support.XContentMapValues; +import org.opensearch.index.mapper.MapperService; import java.io.IOException; import java.util.Collections; @@ -303,8 +304,8 @@ public PutIndexTemplateRequest mapping(String type, Map source) * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). */ - public PutIndexTemplateRequest mapping(String type, Object... source) { - mapping(type, PutMappingRequest.buildFromSimplifiedDef(source)); + public PutIndexTemplateRequest mapping(String... source) { + mapping(MapperService.SINGLE_MAPPING_NAME, PutMappingRequest.simpleMapping(source)); return this; } 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 caff201abeda7..df3b5f6417576 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 @@ -137,8 +137,8 @@ public PutIndexTemplateRequestBuilder addMapping(String type, String source, XCo * A specialized simplified mapping source method, takes the form of simple properties definition: * ("field1", "type=string,store=true"). */ - public PutIndexTemplateRequestBuilder addMapping(String type, Object... source) { - request.mapping(type, source); + public PutIndexTemplateRequestBuilder setMapping(String... source) { + request.mapping(source); return this; } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestTests.java index ab401b7d45792..d8178769ba7b1 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/mapping/put/PutMappingRequestTests.java @@ -92,15 +92,12 @@ public void testValidation() { } /** - * Test that {@link PutMappingRequest#buildFromSimplifiedDef(Object...)} + * Test that {@link PutMappingRequest#simpleMapping(String...)} * rejects inputs where the {@code Object...} varargs of field name and properties are not * paired correctly */ public void testBuildFromSimplifiedDef() { - IllegalArgumentException e = expectThrows( - IllegalArgumentException.class, - () -> PutMappingRequest.buildFromSimplifiedDef("only_field") - ); + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> PutMappingRequest.simpleMapping("only_field")); assertEquals("mapping source must be pairs of fieldnames and properties definition.", e.getMessage()); } diff --git a/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java index 0a01d86e76dea..a8245627c6930 100644 --- a/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/RangeFieldQueryStringQueryBuilderTests.java @@ -73,7 +73,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws "_doc", new CompressedXContent( Strings.toString( - PutMappingRequest.buildFromSimplifiedDef( + PutMappingRequest.simpleMapping( INTEGER_RANGE_FIELD_NAME, "type=integer_range", LONG_RANGE_FIELD_NAME, diff --git a/server/src/test/java/org/opensearch/index/query/MatchQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/query/MatchQueryBuilderTests.java index dac32849e3cef..d6cd157d6f84e 100644 --- a/server/src/test/java/org/opensearch/index/query/MatchQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/query/MatchQueryBuilderTests.java @@ -390,7 +390,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws "_doc", new CompressedXContent( Strings.toString( - PutMappingRequest.buildFromSimplifiedDef("string_boost", "type=text", "string_no_pos", "type=text,index_options=docs") + PutMappingRequest.simpleMapping("string_boost", "type=text", "string_no_pos", "type=text,index_options=docs") ) ), MapperService.MergeReason.MAPPING_UPDATE diff --git a/server/src/test/java/org/opensearch/index/query/NestedQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/query/NestedQueryBuilderTests.java index b95d9f8d36ad8..abc3e0bb8c4c3 100644 --- a/server/src/test/java/org/opensearch/index/query/NestedQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/query/NestedQueryBuilderTests.java @@ -77,7 +77,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws "_doc", new CompressedXContent( Strings.toString( - PutMappingRequest.buildFromSimplifiedDef( + PutMappingRequest.simpleMapping( TEXT_FIELD_NAME, "type=text", INT_FIELD_NAME, diff --git a/server/src/test/java/org/opensearch/index/query/QueryStringQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/query/QueryStringQueryBuilderTests.java index b091fc2103344..393d4cb3f2121 100644 --- a/server/src/test/java/org/opensearch/index/query/QueryStringQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/query/QueryStringQueryBuilderTests.java @@ -1096,7 +1096,7 @@ public void testDisabledFieldNamesField() throws Exception { .merge( "_doc", new CompressedXContent( - Strings.toString(PutMappingRequest.buildFromSimplifiedDef("foo", "type=text", "_field_names", "enabled=false")) + Strings.toString(PutMappingRequest.simpleMapping("foo", "type=text", "_field_names", "enabled=false")) ), MapperService.MergeReason.MAPPING_UPDATE ); @@ -1112,7 +1112,7 @@ public void testDisabledFieldNamesField() throws Exception { .merge( "_doc", new CompressedXContent( - Strings.toString(PutMappingRequest.buildFromSimplifiedDef("foo", "type=text", "_field_names", "enabled=true")) + Strings.toString(PutMappingRequest.simpleMapping("foo", "type=text", "_field_names", "enabled=true")) ), MapperService.MergeReason.MAPPING_UPDATE ); diff --git a/server/src/test/java/org/opensearch/index/query/TermsSetQueryBuilderTests.java b/server/src/test/java/org/opensearch/index/query/TermsSetQueryBuilderTests.java index 3c39773108830..43ca3139e30cb 100644 --- a/server/src/test/java/org/opensearch/index/query/TermsSetQueryBuilderTests.java +++ b/server/src/test/java/org/opensearch/index/query/TermsSetQueryBuilderTests.java @@ -93,7 +93,7 @@ protected void initializeAdditionalMappings(MapperService mapperService) throws String docType = "_doc"; mapperService.merge( docType, - new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("m_s_m", "type=long"))), + new CompressedXContent(Strings.toString(PutMappingRequest.simpleMapping("m_s_m", "type=long"))), MapperService.MergeReason.MAPPING_UPDATE ); } diff --git a/test/framework/src/main/java/org/opensearch/test/AbstractBuilderTestCase.java b/test/framework/src/main/java/org/opensearch/test/AbstractBuilderTestCase.java index e5d14333de828..ae32db5fe6032 100644 --- a/test/framework/src/main/java/org/opensearch/test/AbstractBuilderTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/AbstractBuilderTestCase.java @@ -438,7 +438,7 @@ public void onRemoval(ShardId shardId, Accountable accountable) { "_doc", new CompressedXContent( Strings.toString( - PutMappingRequest.buildFromSimplifiedDef( + PutMappingRequest.simpleMapping( TEXT_FIELD_NAME, "type=text", KEYWORD_FIELD_NAME, diff --git a/test/framework/src/main/java/org/opensearch/test/OpenSearchSingleNodeTestCase.java b/test/framework/src/main/java/org/opensearch/test/OpenSearchSingleNodeTestCase.java index fb4831f881092..fe65d14bbcd0f 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchSingleNodeTestCase.java @@ -320,7 +320,7 @@ protected IndexService createIndex(String index, Settings settings, String type, * @deprecated types are being removed */ @Deprecated - protected IndexService createIndex(String index, Settings settings, String type, Object... mappings) { + protected IndexService createIndex(String index, Settings settings, String type, String... mappings) { CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings); if (type != null) { createIndexRequestBuilder.addMapping(type, mappings);