diff --git a/modules/analysis-common/src/test/java/org/opensearch/analysis/common/HighlighterWithAnalyzersTests.java b/modules/analysis-common/src/test/java/org/opensearch/analysis/common/HighlighterWithAnalyzersTests.java index faaf636d4a8ff..a8dd2d2578541 100644 --- a/modules/analysis-common/src/test/java/org/opensearch/analysis/common/HighlighterWithAnalyzersTests.java +++ b/modules/analysis-common/src/test/java/org/opensearch/analysis/common/HighlighterWithAnalyzersTests.java @@ -70,10 +70,8 @@ protected Collection> nodePlugins() { public void testNgramHighlightingWithBrokenPositions() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "test", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("test") .startObject("properties") .startObject("name") .field("type", "text") @@ -88,7 +86,6 @@ public void testNgramHighlightingWithBrokenPositions() throws IOException { .endObject() .endObject() .endObject() - .endObject() ) .setSettings( Settings.builder() @@ -260,7 +257,7 @@ public void testPhrasePrefix() throws IOException { .put("index.analysis.filter.synonym.type", "synonym") .putList("index.analysis.filter.synonym.synonyms", "quick => fast"); - assertAcked(prepareCreate("first_test_index").setSettings(builder.build()).addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("first_test_index").setSettings(builder.build()).setMapping(type1TermVectorMapping())); ensureGreen(); @@ -421,7 +418,6 @@ public void testPhrasePrefix() throws IOException { public static XContentBuilder type1TermVectorMapping() throws IOException { return XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -432,7 +428,6 @@ public static XContentBuilder type1TermVectorMapping() throws IOException { .field("term_vector", "with_positions_offsets") .endObject() .endObject() - .endObject() .endObject(); } } diff --git a/modules/lang-expression/src/internalClusterTest/java/org/opensearch/script/expression/MoreExpressionIT.java b/modules/lang-expression/src/internalClusterTest/java/org/opensearch/script/expression/MoreExpressionIT.java index 259234d79ab42..450e70c3c8938 100644 --- a/modules/lang-expression/src/internalClusterTest/java/org/opensearch/script/expression/MoreExpressionIT.java +++ b/modules/lang-expression/src/internalClusterTest/java/org/opensearch/script/expression/MoreExpressionIT.java @@ -641,12 +641,11 @@ public void testPipelineAggregationScript() throws Exception { public void testGeo() throws Exception { XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("location") .field("type", "geo_point"); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setMapping(xContentBuilder)); ensureGreen(); client().prepareIndex("test") .setId("1") @@ -687,12 +686,11 @@ public void testGeo() throws Exception { public void testBoolean() throws Exception { XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("doc") .startObject("properties") .startObject("vip") .field("type", "boolean"); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("doc", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setMapping(xContentBuilder)); ensureGreen(); indexRandom( true, diff --git a/modules/mapper-extras/src/javaRestTest/java/org/opensearch/index/mapper/TokenCountFieldMapperIntegrationIT.java b/modules/mapper-extras/src/javaRestTest/java/org/opensearch/index/mapper/TokenCountFieldMapperIntegrationIT.java index cbba425a04889..e25344a4bb4e3 100644 --- a/modules/mapper-extras/src/javaRestTest/java/org/opensearch/index/mapper/TokenCountFieldMapperIntegrationIT.java +++ b/modules/mapper-extras/src/javaRestTest/java/org/opensearch/index/mapper/TokenCountFieldMapperIntegrationIT.java @@ -128,10 +128,8 @@ private void init() throws IOException { settings.put("index.analysis.analyzer.mock_english.tokenizer", "standard"); settings.put("index.analysis.analyzer.mock_english.filter", "stop"); prepareCreate("test").setSettings(settings) - .addMapping( - "test", + .setMapping( jsonBuilder().startObject() - .startObject("test") .startObject("properties") .startObject("foo") .field("type", "text") @@ -162,7 +160,6 @@ private void init() throws IOException { .endObject() .endObject() .endObject() - .endObject() ) .get(); ensureGreen(); diff --git a/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/aggregations/AbstractParentChildTestCase.java b/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/aggregations/AbstractParentChildTestCase.java index c2536897f352a..5566c688aefbf 100644 --- a/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/aggregations/AbstractParentChildTestCase.java +++ b/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/aggregations/AbstractParentChildTestCase.java @@ -55,8 +55,7 @@ public abstract class AbstractParentChildTestCase extends ParentChildTestCase { @Before public void setupCluster() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "doc", + prepareCreate("test").setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "article", "comment"), "commenter", diff --git a/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/aggregations/ChildrenIT.java b/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/aggregations/ChildrenIT.java index 4e98d2aa1af08..08354cbaaf93b 100644 --- a/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/aggregations/ChildrenIT.java +++ b/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/aggregations/ChildrenIT.java @@ -174,8 +174,7 @@ public void testParentWithMultipleBuckets() throws Exception { public void testWithDeletes() throws Exception { String indexName = "xyz"; assertAcked( - prepareCreate(indexName).addMapping( - "doc", + prepareCreate(indexName).setMapping( addFieldMappings(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"), "name", "keyword") ) ); @@ -234,8 +233,7 @@ public void testPostCollection() throws Exception { prepareCreate(indexName).setSettings( Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) ) - .addMapping( - "doc", + .setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, masterType, childType), "brand", @@ -309,8 +307,7 @@ public void testHierarchicalChildrenAggs() { String parentType = "country"; String childType = "city"; assertAcked( - prepareCreate(indexName).addMapping( - "doc", + prepareCreate(indexName).setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, grandParentType, parentType, parentType, childType), "name", @@ -352,8 +349,7 @@ public void testPostCollectAllLeafReaders() throws Exception { // Before we only evaluated segments that yielded matches in 'towns' and 'parent_names' aggs, which caused // us to miss to evaluate child docs in segments we didn't have parent matches for. assertAcked( - prepareCreate("index").addMapping( - "doc", + prepareCreate("index").setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parentType", "childType"), "name", diff --git a/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/query/ChildQuerySearchIT.java b/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/query/ChildQuerySearchIT.java index ce83790c0d302..d684f0bfebcfb 100644 --- a/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/query/ChildQuerySearchIT.java +++ b/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/query/ChildQuerySearchIT.java @@ -102,8 +102,7 @@ public class ChildQuerySearchIT extends ParentChildTestCase { public void testMultiLevelChild() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "doc", + prepareCreate("test").setMapping( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child", "child", "grandchild") ) ); @@ -166,9 +165,7 @@ public void testMultiLevelChild() throws Exception { // see #2744 public void test2744() throws IOException { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "foo", "test")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "foo", "test"))); ensureGreen(); // index simple data @@ -185,9 +182,7 @@ public void test2744() throws IOException { } public void testSimpleChildQuery() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); // index simple data @@ -251,9 +246,7 @@ public void testSimpleChildQuery() throws Exception { // Issue #3290 public void testCachingBugWithFqueryFilter() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); List builders = new ArrayList<>(); // index simple data @@ -290,9 +283,7 @@ public void testCachingBugWithFqueryFilter() throws Exception { } public void testHasParentFilter() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); Map> parentToChildren = new HashMap<>(); // Childless parent @@ -340,9 +331,7 @@ public void testHasParentFilter() throws Exception { } public void testSimpleChildQueryWithFlush() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); // index simple data with flushes, so we have many segments @@ -408,8 +397,7 @@ public void testSimpleChildQueryWithFlush() throws Exception { public void testScopedFacet() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "doc", + prepareCreate("test").setMapping( addFieldMappings(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"), "c_field", "keyword") ) ); @@ -459,9 +447,7 @@ public void testScopedFacet() throws Exception { } public void testDeletedParent() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); // index simple data createIndexRequest("test", "parent", "p1", null, "p_field", "p_value1").get(); @@ -496,9 +482,7 @@ public void testDeletedParent() throws Exception { } public void testDfsSearchType() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); // index simple data @@ -526,9 +510,7 @@ public void testDfsSearchType() throws Exception { } public void testHasChildAndHasParentFailWhenSomeSegmentsDontContainAnyParentOrChildDocs() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); createIndexRequest("test", "parent", "1", null, "p_field", 1).get(); @@ -551,9 +533,7 @@ public void testHasChildAndHasParentFailWhenSomeSegmentsDontContainAnyParentOrCh } public void testCountApiUsage() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); String parentId = "p1"; @@ -584,9 +564,7 @@ public void testCountApiUsage() throws Exception { } public void testExplainUsage() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); String parentId = "p1"; @@ -650,10 +628,8 @@ List createDocBuilders() { public void testScoreForParentChildQueriesWithFunctionScore() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "doc", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("doc") .startObject("properties") .startObject("join_field") .field("type", "join") @@ -663,7 +639,6 @@ public void testScoreForParentChildQueriesWithFunctionScore() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -758,9 +733,7 @@ public void testScoreForParentChildQueriesWithFunctionScore() throws Exception { // Issue #2536 public void testParentChildQueriesCanHandleNoRelevantTypesInIndex() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); SearchResponse response = client().prepareSearch("test") @@ -792,9 +765,7 @@ public void testParentChildQueriesCanHandleNoRelevantTypesInIndex() throws Excep } public void testHasChildAndHasParentFilter_withFilter() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); createIndexRequest("test", "parent", "1", null, "p_field", 1).get(); @@ -820,9 +791,7 @@ public void testHasChildAndHasParentFilter_withFilter() throws Exception { } public void testHasChildInnerHitsHighlighting() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); createIndexRequest("test", "parent", "1", null, "p_field", 1).get(); @@ -848,9 +817,7 @@ public void testHasChildInnerHitsHighlighting() throws Exception { } public void testHasChildAndHasParentWrappedInAQueryFilter() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); // query filter in case for p/c shouldn't execute per segment, but rather @@ -884,8 +851,7 @@ public void testHasChildAndHasParentWrappedInAQueryFilter() throws Exception { public void testSimpleQueryRewrite() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "doc", + prepareCreate("test").setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"), "c_field", @@ -945,9 +911,7 @@ public void testSimpleQueryRewrite() throws Exception { // Issue #3144 public void testReIndexingParentAndChildDocuments() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); // index simple data @@ -1004,9 +968,7 @@ public void testReIndexingParentAndChildDocuments() throws Exception { // Issue #3203 public void testHasChildQueryWithMinimumScore() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); // index simple data @@ -1031,7 +993,7 @@ public void testHasChildQueryWithMinimumScore() throws Exception { public void testParentFieldQuery() throws Exception { assertAcked( prepareCreate("test").setSettings(Settings.builder().put("index.refresh_interval", -1)) - .addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) + .setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) ); ensureGreen(); @@ -1063,7 +1025,7 @@ public void testParentFieldQuery() throws Exception { public void testParentIdQuery() throws Exception { assertAcked( prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.refresh_interval", -1)) - .addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) + .setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) ); ensureGreen(); @@ -1083,9 +1045,7 @@ public void testParentIdQuery() throws Exception { } public void testHasChildNotBeingCached() throws IOException { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); // index simple data @@ -1146,10 +1106,8 @@ private QueryBuilder randomHasParent(String type, String field, String value) { // Issue #3818 public void testHasChildQueryOnlyReturnsSingleChildType() throws Exception { assertAcked( - prepareCreate("grandissue").addMapping( - "doc", + prepareCreate("grandissue").setMapping( jsonBuilder().startObject() - .startObject("doc") .startObject("properties") .startObject("join_field") .field("type", "join") @@ -1160,7 +1118,6 @@ public void testHasChildQueryOnlyReturnsSingleChildType() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -1203,8 +1160,7 @@ public void testHasChildQueryOnlyReturnsSingleChildType() throws Exception { public void testHasChildQueryWithNestedInnerObjects() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "doc", + prepareCreate("test").setMapping( addFieldMappings(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"), "objects", "nested") ) ); @@ -1282,9 +1238,7 @@ public void testHasChildQueryWithNestedInnerObjects() throws Exception { } public void testNamedFilters() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); String parentId = "p1"; @@ -1368,7 +1322,7 @@ public void testParentChildQueriesNoParentType() throws Exception { public void testParentChildCaching() throws Exception { assertAcked( prepareCreate("test").setSettings(Settings.builder().put("index.refresh_interval", -1)) - .addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) + .setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) ); ensureGreen(); @@ -1413,9 +1367,7 @@ public void testParentChildCaching() throws Exception { } public void testParentChildQueriesViaScrollApi() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); for (int i = 0; i < 10; i++) { createIndexRequest("test", "parent", "p" + i, null).get(); @@ -1496,9 +1448,7 @@ private SearchResponse minMaxQuery(ScoreMode scoreMode, int minChildren, Integer } public void testMinMaxChildren() throws Exception { - assertAcked( - prepareCreate("test").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); ensureGreen(); indexRandom(true, createMinMaxDocBuilders().toArray(new IndexRequestBuilder[0])); @@ -1811,10 +1761,7 @@ public void testMinMaxChildren() throws Exception { public void testHasParentInnerQueryType() { assertAcked( - prepareCreate("test").addMapping( - "doc", - buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent-type", "child-type") - ) + prepareCreate("test").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent-type", "child-type")) ); createIndexRequest("test", "child-type", "child-id", "parent-id").get(); createIndexRequest("test", "parent-type", "parent-id", null).get(); @@ -1834,8 +1781,7 @@ public void testHasParentInnerQueryType() { public void testHighlightersIgnoreParentChild() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "doc", + prepareCreate("test").setMapping( jsonBuilder().startObject() .startObject("properties") .startObject("join_field") @@ -1888,7 +1834,7 @@ public void testHighlightersIgnoreParentChild() throws IOException { public void testAliasesFilterWithHasChildQuery() throws Exception { assertAcked( - prepareCreate("my-index").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) + prepareCreate("my-index").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) ); createIndexRequest("my-index", "parent", "1", null).get(); createIndexRequest("my-index", "child", "2", "1").get(); diff --git a/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/query/InnerHitsIT.java b/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/query/InnerHitsIT.java index ed53b1643cc75..ffcc9cf38545f 100644 --- a/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/query/InnerHitsIT.java +++ b/modules/parent-join/src/internalClusterTest/java/org/opensearch/join/query/InnerHitsIT.java @@ -103,10 +103,8 @@ protected Map, Object>> pluginScripts() { public void testSimpleParentChild() throws Exception { assertAcked( - prepareCreate("articles").addMapping( - "doc", + prepareCreate("articles").setMapping( jsonBuilder().startObject() - .startObject("doc") .startObject("properties") .startObject("join_field") .field("type", "join") @@ -123,7 +121,6 @@ public void testSimpleParentChild() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -223,10 +220,8 @@ public void testSimpleParentChild() throws Exception { public void testRandomParentChild() throws Exception { assertAcked( - prepareCreate("idx").addMapping( - "doc", + prepareCreate("idx").setMapping( jsonBuilder().startObject() - .startObject("doc") .startObject("properties") .startObject("id") .field("type", "keyword") @@ -239,7 +234,6 @@ public void testRandomParentChild() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); int numDocs = scaledRandomIntBetween(5, 50); @@ -323,8 +317,7 @@ public void testRandomParentChild() throws Exception { public void testInnerHitsOnHasParent() throws Exception { assertAcked( - prepareCreate("stack").addMapping( - "doc", + prepareCreate("stack").setMapping( addFieldMappings(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "question", "answer"), "body", "text") ) ); @@ -379,8 +372,7 @@ public void testInnerHitsOnHasParent() throws Exception { public void testParentChildMultipleLayers() throws Exception { assertAcked( - prepareCreate("articles").addMapping( - "doc", + prepareCreate("articles").setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "article", "comment", "comment", "remark"), "title", @@ -449,8 +441,7 @@ public void testParentChildMultipleLayers() throws Exception { public void testRoyals() throws Exception { assertAcked( - prepareCreate("royals").addMapping( - "doc", + prepareCreate("royals").setMapping( buildParentJoinFieldMappingFromSimplifiedDef( "join_field", true, @@ -536,9 +527,7 @@ public void testRoyals() throws Exception { } public void testMatchesQueriesParentChildInnerHits() throws Exception { - assertAcked( - prepareCreate("index").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) - ); + assertAcked(prepareCreate("index").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child"))); List requests = new ArrayList<>(); requests.add(createIndexRequest("index", "parent", "1", null)); requests.add(createIndexRequest("index", "child", "3", "1", "field", "value1")); @@ -577,7 +566,7 @@ public void testMatchesQueriesParentChildInnerHits() throws Exception { public void testUseMaxDocInsteadOfSize() throws Exception { assertAcked( - prepareCreate("index1").addMapping("doc", buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) + prepareCreate("index1").setMapping(buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent", "child")) ); client().admin() .indices() @@ -599,8 +588,7 @@ public void testUseMaxDocInsteadOfSize() throws Exception { public void testNestedInnerHitWrappedInParentChildInnerhit() { assertAcked( - prepareCreate("test").addMapping( - "doc", + prepareCreate("test").setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent_type", "child_type"), "nested_type", @@ -632,8 +620,7 @@ public void testNestedInnerHitWrappedInParentChildInnerhit() { public void testInnerHitsWithIgnoreUnmapped() { assertAcked( - prepareCreate("index1").addMapping( - "doc", + prepareCreate("index1").setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent_type", "child_type"), "nested_type", @@ -662,8 +649,7 @@ public void testInnerHitsWithIgnoreUnmapped() { public void testTooHighResultWindow() { assertAcked( - prepareCreate("index1").addMapping( - "doc", + prepareCreate("index1").setMapping( addFieldMappings( buildParentJoinFieldMappingFromSimplifiedDef("join_field", true, "parent_type", "child_type"), "nested_type", 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 37c0eb051cd55..1cb5d81136de1 100644 --- a/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/internalClusterTest/java/org/opensearch/percolator/PercolatorQuerySearchIT.java @@ -844,10 +844,8 @@ public void testManyPercolatorFields() throws Exception { client().admin() .indices() .prepareCreate("test3") - .addMapping( - "type", + .setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("field") .field("type", "keyword") @@ -862,7 +860,6 @@ public void testManyPercolatorFields() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); } @@ -876,10 +873,8 @@ public void testWithMultiplePercolatorFields() throws Exception { client().admin() .indices() .prepareCreate("test2") - .addMapping( - "type", + .setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("field") .field("type", "keyword") @@ -894,7 +889,6 @@ public void testWithMultiplePercolatorFields() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -977,7 +971,7 @@ public void testPercolateQueryWithNestedDocuments() throws Exception { .endObject() .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate("test").addMapping("employee", mapping)); + assertAcked(client().admin().indices().prepareCreate("test").setMapping(mapping)); client().prepareIndex("test") .setId("q1") .setSource( diff --git a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java index e212ad6630e9a..d3da99ffbc102 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java @@ -150,7 +150,7 @@ public void testPercolateQueryWithNestedDocuments_doNotLeakBitsetCacheEntries() .prepareCreate("test") // to avoid normal document from being cached by BitsetFilterCache .setSettings(Settings.builder().put(BitsetFilterCache.INDEX_LOAD_RANDOM_ACCESS_FILTERS_EAGERLY_SETTING.getKey(), false)) - .addMapping("employee", mapping) + .setMapping(mapping) ); client().prepareIndex("test") .setId("q1") @@ -238,7 +238,7 @@ public void testPercolateQueryWithNestedDocuments_doLeakFieldDataCacheEntries() mapping.endObject(); } mapping.endObject(); - createIndex("test", client().admin().indices().prepareCreate("test").addMapping("employee", mapping)); + createIndex("test", client().admin().indices().prepareCreate("test").setMapping(mapping)); Script script = new Script(ScriptType.INLINE, MockScriptPlugin.NAME, "use_fielddata_please", Collections.emptyMap()); client().prepareIndex("test") .setId("q1") diff --git a/plugins/analysis-icu/src/internalClusterTest/java/org/opensearch/index/mapper/ICUCollationKeywordFieldMapperIT.java b/plugins/analysis-icu/src/internalClusterTest/java/org/opensearch/index/mapper/ICUCollationKeywordFieldMapperIT.java index 46b9c45b9cf82..4735f39033081 100644 --- a/plugins/analysis-icu/src/internalClusterTest/java/org/opensearch/index/mapper/ICUCollationKeywordFieldMapperIT.java +++ b/plugins/analysis-icu/src/internalClusterTest/java/org/opensearch/index/mapper/ICUCollationKeywordFieldMapperIT.java @@ -71,8 +71,6 @@ protected Collection> nodePlugins() { */ public void testBasicUsage() throws Exception { String index = "foo"; - String type = "mytype"; - String[] equivalent = { "I WİLL USE TURKİSH CASING", "ı will use turkish casıng" }; XContentBuilder builder = jsonBuilder().startObject() @@ -88,7 +86,7 @@ public void testBasicUsage() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); // both values should collate to same value indexRandom( @@ -114,7 +112,6 @@ public void testBasicUsage() throws Exception { public void testMultipleValues() throws Exception { String index = "foo"; - String type = "mytype"; String[] equivalent = { "a", "C", "a", "B" }; @@ -130,7 +127,7 @@ public void testMultipleValues() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); // everything should be indexed fine, no exceptions indexRandom( @@ -177,7 +174,6 @@ public void testMultipleValues() throws Exception { */ public void testNormalization() throws Exception { String index = "foo"; - String type = "mytype"; String[] equivalent = { "I W\u0049\u0307LL USE TURKİSH CASING", "ı will use turkish casıng" }; @@ -195,7 +191,7 @@ public void testNormalization() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); indexRandom( true, @@ -223,7 +219,6 @@ public void testNormalization() throws Exception { */ public void testSecondaryStrength() throws Exception { String index = "foo"; - String type = "mytype"; String[] equivalent = { "TESTING", "testing" }; @@ -241,7 +236,7 @@ public void testSecondaryStrength() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); indexRandom( true, @@ -269,7 +264,6 @@ public void testSecondaryStrength() throws Exception { */ public void testIgnorePunctuation() throws Exception { String index = "foo"; - String type = "mytype"; String[] equivalent = { "foo-bar", "foo bar" }; @@ -287,7 +281,7 @@ public void testIgnorePunctuation() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); indexRandom( true, @@ -315,7 +309,6 @@ public void testIgnorePunctuation() throws Exception { */ public void testIgnoreWhitespace() throws Exception { String index = "foo"; - String type = "mytype"; XContentBuilder builder = jsonBuilder().startObject() .startObject("properties") @@ -333,7 +326,7 @@ public void testIgnoreWhitespace() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); indexRandom( true, @@ -363,7 +356,6 @@ public void testIgnoreWhitespace() throws Exception { */ public void testNumerics() throws Exception { String index = "foo"; - String type = "mytype"; XContentBuilder builder = jsonBuilder().startObject() .startObject("properties") @@ -376,7 +368,7 @@ public void testNumerics() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); indexRandom( true, @@ -399,7 +391,6 @@ public void testNumerics() throws Exception { */ public void testIgnoreAccentsButNotCase() throws Exception { String index = "foo"; - String type = "mytype"; XContentBuilder builder = jsonBuilder().startObject() .startObject("properties") @@ -416,7 +407,7 @@ public void testIgnoreAccentsButNotCase() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); indexRandom( true, @@ -441,7 +432,6 @@ public void testIgnoreAccentsButNotCase() throws Exception { */ public void testUpperCaseFirst() throws Exception { String index = "foo"; - String type = "mytype"; XContentBuilder builder = jsonBuilder().startObject() .startObject("properties") @@ -455,7 +445,7 @@ public void testUpperCaseFirst() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); indexRandom( true, @@ -481,7 +471,6 @@ public void testUpperCaseFirst() throws Exception { */ public void testCustomRules() throws Exception { String index = "foo"; - String type = "mytype"; RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de_DE")); String DIN5007_2_tailorings = "& ae , a\u0308 & AE , A\u0308" + "& oe , o\u0308 & OE , O\u0308" + "& ue , u\u0308 & UE , u\u0308"; @@ -504,7 +493,7 @@ public void testCustomRules() throws Exception { .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); indexRandom( true, diff --git a/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingIT.java b/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingIT.java index 2cf05da26c193..375222cd2af44 100644 --- a/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingIT.java +++ b/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingIT.java @@ -63,10 +63,9 @@ protected Collection> nodePlugins() { // issue 5053 public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() throws Exception { String index = "foo"; - String type = MapperService.SINGLE_MAPPING_NAME; XContentBuilder builder = jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); // check mapping again assertSizeMappingEnabled(index, true); @@ -88,10 +87,9 @@ public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() thr public void testThatSizeCanBeSwitchedOnAndOff() throws Exception { String index = "foo"; - String type = MapperService.SINGLE_MAPPING_NAME; XContentBuilder builder = jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject(); - assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); + assertAcked(client().admin().indices().prepareCreate(index).setMapping(builder)); // check mapping again assertSizeMappingEnabled(index, true); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java index 476bd72ee3ca3..3ef2a63c7d0ac 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/create/CreateIndexIT.java @@ -110,8 +110,7 @@ public void testCreationDateGenerated() { public void testNonNestedMappings() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "_doc", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() .startObject("properties") @@ -131,7 +130,7 @@ public void testNonNestedMappings() throws Exception { } public void testEmptyNestedMappings() throws Exception { - assertAcked(prepareCreate("test").addMapping("_doc", XContentFactory.jsonBuilder().startObject().endObject())); + assertAcked(prepareCreate("test").setMapping(XContentFactory.jsonBuilder().startObject().endObject())); GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); @@ -144,10 +143,8 @@ public void testEmptyNestedMappings() throws Exception { public void testMappingParamAndNestedMismatch() throws Exception { MapperParsingException e = expectThrows( MapperParsingException.class, - () -> prepareCreate("test").addMapping( - MapperService.SINGLE_MAPPING_NAME, - XContentFactory.jsonBuilder().startObject().startObject("type2").endObject().endObject() - ).get() + () -> prepareCreate("test").setMapping(XContentFactory.jsonBuilder().startObject().startObject("type2").endObject().endObject()) + .get() ); assertThat( e.getMessage(), @@ -159,10 +156,7 @@ public void testMappingParamAndNestedMismatch() throws Exception { public void testEmptyMappings() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "_doc", - XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject() - ) + prepareCreate("test").setMapping(XContentFactory.jsonBuilder().startObject().startObject("_doc").endObject().endObject()) ); GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/termvectors/GetTermVectorsIT.java b/server/src/internalClusterTest/java/org/opensearch/action/termvectors/GetTermVectorsIT.java index d28dcbb924f95..8ab6450ead2af 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/termvectors/GetTermVectorsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/termvectors/GetTermVectorsIT.java @@ -88,7 +88,7 @@ public void testNoSuchDoc() throws Exception { .endObject() .endObject() .endObject(); - assertAcked(prepareCreate("test").addAlias(new Alias("alias")).addMapping("type1", mapping)); + assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setMapping(mapping)); client().prepareIndex("test").setId("667").setSource("field", "foo bar").execute().actionGet(); refresh(); @@ -105,16 +105,14 @@ public void testNoSuchDoc() throws Exception { public void testExistingFieldWithNoTermVectorsNoNPE() throws Exception { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("existingfield") .field("type", "text") .field("term_vector", "with_positions_offsets_payloads") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addAlias(new Alias("alias")).addMapping("type1", mapping)); + assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setMapping(mapping)); // when indexing a field that simply has a question mark, the term vectors will be null client().prepareIndex("test").setId("0").setSource("existingfield", "?").execute().actionGet(); @@ -133,16 +131,14 @@ public void testExistingFieldWithNoTermVectorsNoNPE() throws Exception { public void testExistingFieldButNotInDocNPE() throws Exception { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("existingfield") .field("type", "text") .field("term_vector", "with_positions_offsets_payloads") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addAlias(new Alias("alias")).addMapping("type1", mapping)); + assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setMapping(mapping)); // when indexing a field that simply has a question mark, the term vectors will be null client().prepareIndex("test").setId("0").setSource("anotherexistingfield", 1).execute().actionGet(); @@ -205,7 +201,6 @@ public void testNotIndexedField() throws Exception { public void testSimpleTermVectors() throws IOException { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("field") .field("type", "text") @@ -213,10 +208,9 @@ public void testSimpleTermVectors() throws IOException { .field("analyzer", "tv_test") .endObject() .endObject() - .endObject() .endObject(); assertAcked( - prepareCreate("test").addMapping("type1", mapping) + prepareCreate("test").setMapping(mapping) .addAlias(new Alias("alias")) .setSettings( Settings.builder() @@ -316,7 +310,6 @@ public void testRandomSingleTermVectors() throws IOException { String optionString = termVectorOptionsToString(ft); XContentBuilder mapping = jsonBuilder().startObject() - .startObject("_doc") .startObject("properties") .startObject("field") .field("type", "text") @@ -324,10 +317,9 @@ public void testRandomSingleTermVectors() throws IOException { .field("analyzer", "tv_test") .endObject() .endObject() - .endObject() .endObject(); assertAcked( - prepareCreate("test").addMapping("_doc", mapping) + prepareCreate("test").setMapping(mapping) .setSettings( Settings.builder() .put("index.analysis.analyzer.tv_test.tokenizer", "standard") @@ -466,7 +458,7 @@ public void testSimpleTermVectorsWithGenerate() throws IOException { fieldNames[i] = "field" + String.valueOf(i); } - XContentBuilder mapping = jsonBuilder().startObject().startObject("type1").startObject("properties"); + XContentBuilder mapping = jsonBuilder().startObject().startObject("properties"); XContentBuilder source = jsonBuilder().startObject(); for (String field : fieldNames) { mapping.startObject(field) @@ -476,11 +468,11 @@ public void testSimpleTermVectorsWithGenerate() throws IOException { .endObject(); source.field(field, "the quick brown fox jumps over the lazy dog"); } - mapping.endObject().endObject().endObject(); + mapping.endObject().endObject(); source.endObject(); assertAcked( - prepareCreate("test").addMapping("type1", mapping) + prepareCreate("test").setMapping(mapping) .setSettings( Settings.builder() .put(indexSettings()) @@ -640,16 +632,16 @@ private void compareTermVectors(String fieldName, Fields fields0, Fields fields1 public void testSimpleWildCards() throws IOException { int numFields = 25; - XContentBuilder mapping = jsonBuilder().startObject().startObject("type1").startObject("properties"); + XContentBuilder mapping = jsonBuilder().startObject().startObject("properties"); XContentBuilder source = jsonBuilder().startObject(); for (int i = 0; i < numFields; i++) { mapping.startObject("field" + i).field("type", "text").field("term_vector", randomBoolean() ? "yes" : "no").endObject(); source.field("field" + i, "some text here"); } source.endObject(); - mapping.endObject().endObject().endObject(); + mapping.endObject().endObject(); - assertAcked(prepareCreate("test").addAlias(new Alias("alias")).addMapping("type1", mapping)); + assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setMapping(mapping)); ensureGreen(); client().prepareIndex("test").setId("0").setSource(source).get(); @@ -744,7 +736,7 @@ public void testPerFieldAnalyzer() throws IOException { // setup mapping and document source Set withTermVectors = new HashSet<>(); - XContentBuilder mapping = jsonBuilder().startObject().startObject("type1").startObject("properties"); + XContentBuilder mapping = jsonBuilder().startObject().startObject("properties"); XContentBuilder source = jsonBuilder().startObject(); for (int i = 0; i < numFields; i++) { String fieldName = "field" + i; @@ -758,11 +750,11 @@ public void testPerFieldAnalyzer() throws IOException { source.field(fieldName, "some text here"); } source.endObject(); - mapping.endObject().endObject().endObject(); + mapping.endObject().endObject(); // setup indices with mapping Settings.Builder settings = Settings.builder().put(indexSettings()).put("index.analysis.analyzer", "standard"); - assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSettings(settings).addMapping("type1", mapping)); + assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSettings(settings).setMapping(mapping)); ensureGreen(); // index a single document with prepared source diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java index 93a903e0b5e0c..fcf5dcf3891ce 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/SimpleClusterStateIT.java @@ -261,7 +261,7 @@ public void testLargeClusterStatePublishing() throws Exception { ByteSizeValue.parseBytesSizeValue("10k", "estimatedBytesSize").bytesAsInt(), ByteSizeValue.parseBytesSizeValue("256k", "estimatedBytesSize").bytesAsInt() ); - XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties"); + XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("properties"); int counter = 0; int numberOfFields = 0; while (true) { @@ -273,7 +273,7 @@ public void testLargeClusterStatePublishing() throws Exception { } } logger.info("number of fields [{}], estimated bytes [{}]", numberOfFields, estimatedBytesSize); - mapping.endObject().endObject().endObject(); + mapping.endObject().endObject(); int numberOfShards = scaledRandomIntBetween(1, cluster().numDataNodes()); // if the create index is ack'ed, then all nodes have successfully processed the cluster state @@ -287,7 +287,7 @@ public void testLargeClusterStatePublishing() throws Exception { .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) .put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), Long.MAX_VALUE) ) - .addMapping("type", mapping) + .setMapping(mapping) .setTimeout("60s") .get() ); diff --git a/server/src/internalClusterTest/java/org/opensearch/gateway/GatewayIndexStateIT.java b/server/src/internalClusterTest/java/org/opensearch/gateway/GatewayIndexStateIT.java index 24aff104ce837..a8828c7ad38b5 100644 --- a/server/src/internalClusterTest/java/org/opensearch/gateway/GatewayIndexStateIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/gateway/GatewayIndexStateIT.java @@ -105,10 +105,7 @@ public void testMappingMetadataParsed() throws Exception { client().admin() .indices() .prepareCreate("test") - .addMapping( - "type1", - XContentFactory.jsonBuilder().startObject().startObject("_routing").field("required", true).endObject().endObject() - ) + .setMapping(XContentFactory.jsonBuilder().startObject().startObject("_routing").field("required", true).endObject().endObject()) .execute() .actionGet(); diff --git a/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java b/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java index ec0b47ccd0ecf..a09778582b604 100644 --- a/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/get/GetActionIT.java @@ -541,10 +541,8 @@ public void testMultiGetWithVersion() throws Exception { public void testGetFieldsNonLeafField() throws Exception { assertAcked( prepareCreate("test").addAlias(new Alias("alias")) - .addMapping( - "my-type1", + .setMapping( jsonBuilder().startObject() - .startObject("my-type1") .startObject("properties") .startObject("field1") .startObject("properties") @@ -555,7 +553,6 @@ public void testGetFieldsNonLeafField() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) .setSettings(Settings.builder().put("index.refresh_interval", -1)) ); @@ -582,10 +579,8 @@ public void testGetFieldsComplexField() throws Exception { prepareCreate("my-index") // multi types in 5.6 .setSettings(Settings.builder().put("index.refresh_interval", -1)) - .addMapping( - "my-type", + .setMapping( jsonBuilder().startObject() - .startObject("my-type") .startObject("properties") .startObject("field1") .field("type", "object") @@ -608,7 +603,6 @@ public void testGetFieldsComplexField() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/IndexSortIT.java b/server/src/internalClusterTest/java/org/opensearch/index/IndexSortIT.java index c0bc9d29af992..69eb34c39c10c 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/IndexSortIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/IndexSortIT.java @@ -92,7 +92,7 @@ public void testIndexSort() { .put("index.number_of_shards", "1") .put("index.number_of_replicas", "1") .putList("index.sort.field", "date", "numeric_dv", "keyword_dv") - ).addMapping("test", TEST_MAPPING).get(); + ).setMapping(TEST_MAPPING).get(); for (int i = 0; i < 20; i++) { client().prepareIndex("test") .setId(Integer.toString(i)) @@ -108,7 +108,7 @@ public void testInvalidIndexSort() { IllegalArgumentException exc = expectThrows( IllegalArgumentException.class, () -> prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).putList("index.sort.field", "invalid_field")) - .addMapping("test", TEST_MAPPING) + .setMapping(TEST_MAPPING) .get() ); assertThat(exc.getMessage(), containsString("unknown index sort field:[invalid_field]")); @@ -116,7 +116,7 @@ public void testInvalidIndexSort() { exc = expectThrows( IllegalArgumentException.class, () -> prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).putList("index.sort.field", "numeric")) - .addMapping("test", TEST_MAPPING) + .setMapping(TEST_MAPPING) .get() ); assertThat(exc.getMessage(), containsString("docvalues not found for index sort field:[numeric]")); @@ -124,7 +124,7 @@ public void testInvalidIndexSort() { exc = expectThrows( IllegalArgumentException.class, () -> prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).putList("index.sort.field", "keyword")) - .addMapping("test", TEST_MAPPING) + .setMapping(TEST_MAPPING) .get() ); assertThat(exc.getMessage(), containsString("docvalues not found for index sort field:[keyword]")); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/fielddata/FieldDataLoadingIT.java b/server/src/internalClusterTest/java/org/opensearch/index/fielddata/FieldDataLoadingIT.java index 0aa2abed14b79..51e2cf669cbfb 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/fielddata/FieldDataLoadingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/fielddata/FieldDataLoadingIT.java @@ -43,10 +43,8 @@ public class FieldDataLoadingIT extends OpenSearchIntegTestCase { public void testEagerGlobalOrdinalsFieldDataLoading() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("name") .field("type", "text") @@ -55,7 +53,6 @@ public void testEagerGlobalOrdinalsFieldDataLoading() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/mapper/CopyToMapperIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/index/mapper/CopyToMapperIntegrationIT.java index f23e319a5e8d2..d4733e4f31cb2 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/mapper/CopyToMapperIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/mapper/CopyToMapperIntegrationIT.java @@ -50,7 +50,7 @@ public class CopyToMapperIntegrationIT extends OpenSearchIntegTestCase { public void testDynamicTemplateCopyTo() throws Exception { - assertAcked(client().admin().indices().prepareCreate("test-idx").addMapping("_doc", createDynamicTemplateMapping())); + assertAcked(client().admin().indices().prepareCreate("test-idx").setMapping(createDynamicTemplateMapping())); int recordCount = between(1, 200); @@ -98,7 +98,6 @@ public void testDynamicObjectCopyTo() throws Exception { private XContentBuilder createDynamicTemplateMapping() throws IOException { return XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") .startArray("dynamic_templates") .startObject() @@ -124,7 +123,6 @@ private XContentBuilder createDynamicTemplateMapping() throws IOException { .endObject() .endArray() - .endObject() .endObject(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/index/mapper/ExternalValuesMapperIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/index/mapper/ExternalValuesMapperIntegrationIT.java index 2251ec62f5c15..138081e56dd63 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/mapper/ExternalValuesMapperIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/mapper/ExternalValuesMapperIntegrationIT.java @@ -55,18 +55,15 @@ protected Collection> nodePlugins() { } public void testHighlightingOnCustomString() throws Exception { - prepareCreate("test-idx").addMapping( - "type", + prepareCreate("test-idx").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field") .field("type", FakeStringFieldMapper.CONTENT_TYPE) .endObject() .endObject() .endObject() - .endObject() ).execute().get(); index( @@ -118,11 +115,9 @@ public void testHighlightingOnCustomString() throws Exception { } public void testExternalValues() throws Exception { - prepareCreate("test-idx").addMapping( - "type", + prepareCreate("test-idx").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject(ExternalMetadataMapper.CONTENT_TYPE) .endObject() .startObject("properties") @@ -131,7 +126,6 @@ public void testExternalValues() throws Exception { .endObject() .endObject() .endObject() - .endObject() ).execute().get(); index("test-idx", "type", "1", XContentFactory.jsonBuilder().startObject().field("field", "1234").endObject()); @@ -166,11 +160,9 @@ public void testExternalValues() throws Exception { } public void testExternalValuesWithMultifield() throws Exception { - prepareCreate("test-idx").addMapping( - "_doc", + prepareCreate("test-idx").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") .startObject("properties") .startObject("f") .field("type", ExternalMapperPlugin.EXTERNAL_UPPER) @@ -189,7 +181,6 @@ public void testExternalValuesWithMultifield() throws Exception { .endObject() .endObject() .endObject() - .endObject() ).execute().get(); index("test-idx", "_doc", "1", "f", "This is my text"); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/mapper/MultiFieldsIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/index/mapper/MultiFieldsIntegrationIT.java index 37fa8cdd11a8b..7dbb6a45b857d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/mapper/MultiFieldsIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/mapper/MultiFieldsIntegrationIT.java @@ -58,7 +58,7 @@ public class MultiFieldsIntegrationIT extends OpenSearchIntegTestCase { @SuppressWarnings("unchecked") public void testMultiFields() throws Exception { - assertAcked(client().admin().indices().prepareCreate("my-index").addMapping("my-type", createTypeSource())); + assertAcked(client().admin().indices().prepareCreate("my-index").setMapping(createTypeSource())); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); MappingMetadata mappingMetadata = getMappingsResponse.mappings().get("my-index"); @@ -98,7 +98,7 @@ public void testMultiFields() throws Exception { @SuppressWarnings("unchecked") public void testGeoPointMultiField() throws Exception { - assertAcked(client().admin().indices().prepareCreate("my-index").addMapping("my-type", createMappingSource("geo_point"))); + assertAcked(client().admin().indices().prepareCreate("my-index").setMapping(createMappingSource("geo_point"))); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); MappingMetadata mappingMetadata = getMappingsResponse.mappings().get("my-index"); @@ -127,7 +127,7 @@ public void testGeoPointMultiField() throws Exception { @SuppressWarnings("unchecked") public void testCompletionMultiField() throws Exception { - assertAcked(client().admin().indices().prepareCreate("my-index").addMapping("my-type", createMappingSource("completion"))); + assertAcked(client().admin().indices().prepareCreate("my-index").setMapping(createMappingSource("completion"))); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); MappingMetadata mappingMetadata = getMappingsResponse.mappings().get("my-index"); @@ -149,7 +149,7 @@ public void testCompletionMultiField() throws Exception { @SuppressWarnings("unchecked") public void testIpMultiField() throws Exception { - assertAcked(client().admin().indices().prepareCreate("my-index").addMapping("my-type", createMappingSource("ip"))); + assertAcked(client().admin().indices().prepareCreate("my-index").setMapping(createMappingSource("ip"))); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); MappingMetadata mappingMetadata = getMappingsResponse.mappings().get("my-index"); @@ -172,7 +172,6 @@ public void testIpMultiField() throws Exception { private XContentBuilder createMappingSource(String fieldType) throws IOException { return XContentFactory.jsonBuilder() .startObject() - .startObject("my-type") .startObject("properties") .startObject("a") .field("type", fieldType) @@ -183,14 +182,12 @@ private XContentBuilder createMappingSource(String fieldType) throws IOException .endObject() .endObject() .endObject() - .endObject() .endObject(); } private XContentBuilder createTypeSource() throws IOException { return XContentFactory.jsonBuilder() .startObject() - .startObject("my-type") .startObject("properties") .startObject("title") .field("type", "text") @@ -201,7 +198,6 @@ private XContentBuilder createTypeSource() throws IOException { .endObject() .endObject() .endObject() - .endObject() .endObject(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java index d38fbfa1a51e1..a857f6cf6e96c 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/analysis/PreBuiltAnalyzerIntegrationIT.java @@ -78,18 +78,16 @@ public void testThatPreBuiltAnalyzersAreNotClosedOnIndexClose() throws Exception loadedAnalyzers.get(preBuiltAnalyzer).add(randomVersion); final XContentBuilder mapping = jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("foo") .field("type", "text") .field("analyzer", name) .endObject() .endObject() - .endObject() .endObject(); Settings versionSettings = settings(randomVersion).build(); - client().admin().indices().prepareCreate(indexName).addMapping("type", mapping).setSettings(versionSettings).get(); + client().admin().indices().prepareCreate(indexName).setMapping(mapping).setSettings(versionSettings).get(); } ensureGreen(); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/mapping/SimpleGetFieldMappingsIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/mapping/SimpleGetFieldMappingsIT.java index 92a65f43361d6..3de2001acd1e7 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/mapping/SimpleGetFieldMappingsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/mapping/SimpleGetFieldMappingsIT.java @@ -80,9 +80,8 @@ public void testGetMappingsWhereThereAreNone() { assertThat(response.fieldMappings("index", "field"), nullValue()); } - private XContentBuilder getMappingForType(String type) throws IOException { + private XContentBuilder getMappingForType() throws IOException { return jsonBuilder().startObject() - .startObject(type) .startObject("properties") .startObject("field1") .field("type", "text") @@ -99,14 +98,13 @@ private XContentBuilder getMappingForType(String type) throws IOException { .endObject() .endObject() .endObject() - .endObject() .endObject(); } public void testGetFieldMappings() throws Exception { - assertAcked(prepareCreate("indexa").addMapping("typeA", getMappingForType("typeA"))); - assertAcked(client().admin().indices().prepareCreate("indexb").addMapping("typeB", getMappingForType("typeB"))); + assertAcked(prepareCreate("indexa").setMapping(getMappingForType())); + assertAcked(client().admin().indices().prepareCreate("indexb").setMapping(getMappingForType())); // Get mappings by full name GetFieldMappingsResponse response = client().admin() @@ -136,7 +134,7 @@ public void testGetFieldMappings() throws Exception { @SuppressWarnings("unchecked") public void testSimpleGetFieldMappingsWithDefaults() throws Exception { - assertAcked(prepareCreate("test").addMapping("type", getMappingForType("type"))); + assertAcked(prepareCreate("test").setMapping(getMappingForType())); client().admin().indices().preparePutMapping("test").setSource("num", "type=long").get(); client().admin().indices().preparePutMapping("test").setSource("field2", "type=text,index=false").get(); @@ -163,7 +161,7 @@ public void testSimpleGetFieldMappingsWithDefaults() throws Exception { @SuppressWarnings("unchecked") public void testGetFieldMappingsWithFieldAlias() throws Exception { - assertAcked(prepareCreate("test").addMapping("type", getMappingForType("type"))); + assertAcked(prepareCreate("test").setMapping(getMappingForType())); GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings().setFields("alias", "field1").get(); @@ -179,7 +177,7 @@ public void testGetFieldMappingsWithFieldAlias() throws Exception { // fix #6552 public void testSimpleGetFieldMappingsWithPretty() throws Exception { - assertAcked(prepareCreate("index").addMapping("type", getMappingForType("type"))); + assertAcked(prepareCreate("index").setMapping(getMappingForType())); Map params = new HashMap<>(); params.put("pretty", "true"); GetFieldMappingsResponse response = client().admin() @@ -209,7 +207,7 @@ public void testSimpleGetFieldMappingsWithPretty() throws Exception { } public void testGetFieldMappingsWithBlocks() throws Exception { - assertAcked(prepareCreate("test").addMapping("_doc", getMappingForType("_doc"))); + assertAcked(prepareCreate("test").setMapping(getMappingForType())); for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) { try { diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/mapping/SimpleGetMappingsIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/mapping/SimpleGetMappingsIT.java index aac12522afa2f..f54e60a8baa88 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/mapping/SimpleGetMappingsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/mapping/SimpleGetMappingsIT.java @@ -70,21 +70,19 @@ public void testGetMappingsWhereThereAreNone() { assertEquals(MappingMetadata.EMPTY_MAPPINGS, response.mappings().get("index")); } - private XContentBuilder getMappingForType(String type) throws IOException { + private XContentBuilder getMappingForType() throws IOException { return jsonBuilder().startObject() - .startObject(type) .startObject("properties") .startObject("field1") .field("type", "text") .endObject() .endObject() - .endObject() .endObject(); } public void testSimpleGetMappings() throws Exception { - client().admin().indices().prepareCreate("indexa").addMapping("typeA", getMappingForType("typeA")).execute().actionGet(); - client().admin().indices().prepareCreate("indexb").addMapping("typeA", getMappingForType("typeA")).execute().actionGet(); + client().admin().indices().prepareCreate("indexa").setMapping(getMappingForType()).execute().actionGet(); + client().admin().indices().prepareCreate("indexb").setMapping(getMappingForType()).execute().actionGet(); ClusterHealthResponse clusterHealth = client().admin() .cluster() @@ -114,7 +112,7 @@ public void testSimpleGetMappings() throws Exception { } public void testGetMappingsWithBlocks() throws IOException { - client().admin().indices().prepareCreate("test").addMapping("_doc", getMappingForType("_doc")).execute().actionGet(); + client().admin().indices().prepareCreate("test").setMapping(getMappingForType()).execute().actionGet(); ensureGreen(); for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) { diff --git a/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java b/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java index 5b78c5686dc6a..c9d18e64ca038 100644 --- a/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/mget/SimpleMgetIT.java @@ -129,16 +129,7 @@ public void testThatMgetShouldWorkWithMultiIndexAlias() throws IOException { public void testThatMgetShouldWorkWithAliasRouting() throws IOException { assertAcked( prepareCreate("test").addAlias(new Alias("alias1").routing("abc")) - .addMapping( - "test", - jsonBuilder().startObject() - .startObject("test") - .startObject("_routing") - .field("required", true) - .endObject() - .endObject() - .endObject() - ) + .setMapping(jsonBuilder().startObject().startObject("_routing").field("required", true).endObject().endObject()) ); client().prepareIndex("alias1") diff --git a/server/src/internalClusterTest/java/org/opensearch/routing/SimpleRoutingIT.java b/server/src/internalClusterTest/java/org/opensearch/routing/SimpleRoutingIT.java index f3179a0c4acb3..8909b9deece9b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/routing/SimpleRoutingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/routing/SimpleRoutingIT.java @@ -351,17 +351,7 @@ public void testRequiredRoutingCrudApis() throws Exception { .indices() .prepareCreate("test") .addAlias(new Alias("alias")) - .addMapping( - "type1", - XContentFactory.jsonBuilder() - .startObject() - .startObject("type1") - .startObject("_routing") - .field("required", true) - .endObject() - .endObject() - .endObject() - ) + .setMapping(XContentFactory.jsonBuilder().startObject().startObject("_routing").field("required", true).endObject().endObject()) .execute() .actionGet(); ensureGreen(); @@ -450,17 +440,7 @@ public void testRequiredRoutingBulk() throws Exception { .indices() .prepareCreate("test") .addAlias(new Alias("alias")) - .addMapping( - "type1", - XContentFactory.jsonBuilder() - .startObject() - .startObject("type1") - .startObject("_routing") - .field("required", true) - .endObject() - .endObject() - .endObject() - ) + .setMapping(XContentFactory.jsonBuilder().startObject().startObject("_routing").field("required", true).endObject().endObject()) .execute() .actionGet(); ensureGreen(); @@ -544,17 +524,7 @@ public void testRequiredRoutingMappingVariousAPIs() throws Exception { .indices() .prepareCreate("test") .addAlias(new Alias("alias")) - .addMapping( - "type1", - XContentFactory.jsonBuilder() - .startObject() - .startObject("type1") - .startObject("_routing") - .field("required", true) - .endObject() - .endObject() - .endObject() - ) + .setMapping(XContentFactory.jsonBuilder().startObject().startObject("_routing").field("required", true).endObject().endObject()) .execute() .actionGet(); ensureGreen(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/CombiIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/CombiIT.java index f49938fb27e72..c5794c76e21de 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/CombiIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/CombiIT.java @@ -115,10 +115,8 @@ public void testMultipleAggsOnSameField_WithDifferentRequiredValueSourceType() t */ public void testSubAggregationForTopAggregationOnUnmappedField() throws Exception { - prepareCreate("idx").addMapping( - "type", + prepareCreate("idx").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("name") .field("type", "keyword") @@ -128,7 +126,6 @@ public void testSubAggregationForTopAggregationOnUnmappedField() throws Exceptio .endObject() .endObject() .endObject() - .endObject() ).get(); ensureSearchable("idx"); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/EquivalenceIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/EquivalenceIT.java index 29c325d01492e..d03b10ce092c9 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/EquivalenceIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/EquivalenceIT.java @@ -133,17 +133,14 @@ public void testRandomRanges() throws Exception { } } - prepareCreate("idx").addMapping( - "type", + prepareCreate("idx").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("values") .field("type", "double") .endObject() .endObject() .endObject() - .endObject() ).get(); for (int i = 0; i < docs.length; ++i) { @@ -235,10 +232,8 @@ public void testDuelTerms() throws Exception { final IntHashSet valuesSet = new IntHashSet(); cluster().wipeIndices("idx"); - prepareCreate("idx").addMapping( - "type", + prepareCreate("idx").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("num") .field("type", "double") @@ -260,7 +255,6 @@ public void testDuelTerms() throws Exception { .endObject() .endObject() .endObject() - .endObject() ).get(); List indexingRequests = new ArrayList<>(); @@ -358,17 +352,14 @@ public void testDuelTerms() throws Exception { // Duel between histograms and scripted terms public void testDuelTermsHistogram() throws Exception { - prepareCreate("idx").addMapping( - "type", + prepareCreate("idx").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("num") .field("type", "double") .endObject() .endObject() .endObject() - .endObject() ).get(); final int numDocs = scaledRandomIntBetween(500, 5000); @@ -422,17 +413,14 @@ public void testDuelTermsHistogram() throws Exception { public void testLargeNumbersOfPercentileBuckets() throws Exception { // test high numbers of percentile buckets to make sure paging and release work correctly - prepareCreate("idx").addMapping( - "type", + prepareCreate("idx").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("double_value") .field("type", "double") .endObject() .endObject() .endObject() - .endObject() ).get(); final int numDocs = scaledRandomIntBetween(2500, 5000); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/NestedIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/NestedIT.java index 256281f8c6833..969a48b514f1a 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/NestedIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/NestedIT.java @@ -158,10 +158,8 @@ public void setupSuiteScopeCluster() throws Exception { } assertAcked( - prepareCreate("idx_nested_nested_aggs").addMapping( - "type", + prepareCreate("idx_nested_nested_aggs").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("nested1") .field("type", "nested") @@ -173,7 +171,6 @@ public void setupSuiteScopeCluster() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen("idx_nested_nested_aggs"); @@ -400,7 +397,6 @@ public void testNestedOnObjectField() throws Exception { // Test based on: https://github.com/elastic/elasticsearch/issues/9280 public void testParentFilterResolvedCorrectly() throws Exception { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("provider") .startObject("properties") .startObject("comments") .field("type", "nested") @@ -450,11 +446,10 @@ public void testParentFilterResolvedCorrectly() throws Exception { .endObject() .endObject() .endObject() - .endObject() .endObject(); assertAcked( prepareCreate("idx2").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0)) - .addMapping("provider", mapping) + .setMapping(mapping) ); ensureGreen("idx2"); @@ -649,10 +644,8 @@ public void testNestedSameDocIdProcessedMultipleTime() throws Exception { public void testFilterAggInsideNestedAgg() throws Exception { assertAcked( - prepareCreate("classes").addMapping( - "class", + prepareCreate("classes").setMapping( jsonBuilder().startObject() - .startObject("class") .startObject("properties") .startObject("name") .field("type", "text") @@ -681,7 +674,6 @@ public void testFilterAggInsideNestedAgg() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/ReverseNestedIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/ReverseNestedIT.java index e8a57ea3941ff..67ae145aece11 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/ReverseNestedIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/bucket/ReverseNestedIT.java @@ -75,8 +75,7 @@ public class ReverseNestedIT extends OpenSearchIntegTestCase { @Override public void setupSuiteScopeCluster() throws Exception { assertAcked( - prepareCreate("idx1").addMapping( - "type", + prepareCreate("idx1").setMapping( jsonBuilder().startObject() .startObject("properties") .startObject("field1") @@ -99,8 +98,7 @@ public void setupSuiteScopeCluster() throws Exception { ) ); assertAcked( - prepareCreate("idx2").addMapping( - "type", + prepareCreate("idx2").setMapping( jsonBuilder().startObject() .startObject("properties") .startObject("nested1") @@ -531,7 +529,6 @@ public void testNonExistingNestedField() throws Exception { public void testSameParentDocHavingMultipleBuckets() throws Exception { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("product") .field("dynamic", "strict") .startObject("properties") .startObject("id") @@ -562,11 +559,10 @@ public void testSameParentDocHavingMultipleBuckets() throws Exception { .endObject() .endObject() .endObject() - .endObject() .endObject(); assertAcked( prepareCreate("idx3").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0)) - .addMapping("product", mapping) + .setMapping(mapping) ); client().prepareIndex("idx3") diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/metrics/CardinalityIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/metrics/CardinalityIT.java index e01f966cadd9b..7996e2bee44c1 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/metrics/CardinalityIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/metrics/CardinalityIT.java @@ -128,10 +128,8 @@ public Settings indexSettings() { @Override public void setupSuiteScopeCluster() throws Exception { - prepareCreate("idx").addMapping( - "type", + prepareCreate("idx").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("str_value") .field("type", "keyword") @@ -153,7 +151,6 @@ public void setupSuiteScopeCluster() throws Exception { .endObject() .endObject() .endObject() - .endObject() ).get(); numDocs = randomIntBetween(2, 100); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/metrics/TopHitsIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/metrics/TopHitsIT.java index b6fdcf4b6267d..53a3cd4da5446 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/metrics/TopHitsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/metrics/TopHitsIT.java @@ -139,10 +139,8 @@ public void setupSuiteScopeCluster() throws Exception { assertAcked(prepareCreate("field-collapsing").addMapping("type", "group", "type=keyword")); createIndex("empty"); assertAcked( - prepareCreate("articles").addMapping( - "article", + prepareCreate("articles").setMapping( jsonBuilder().startObject() - .startObject("article") .startObject("properties") .startObject(TERMS_AGGS_FIELD) .field("type", "keyword") @@ -174,7 +172,6 @@ public void setupSuiteScopeCluster() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen("idx", "empty", "articles"); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/MaxBucketIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/MaxBucketIT.java index 3d9ebb469cba6..0d63e6d719610 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/MaxBucketIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/MaxBucketIT.java @@ -556,7 +556,7 @@ public void testFieldIsntWrittenOutTwice() throws Exception { .endObject() .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate("foo_2").addMapping("doc", builder).get()); + assertAcked(client().admin().indices().prepareCreate("foo_2").setMapping(builder).get()); XContentBuilder docBuilder = jsonBuilder().startObject() .startObject("license") diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/MovAvgIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/MovAvgIT.java index dc37b49e7a910..91390edc7e872 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/MovAvgIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/pipeline/MovAvgIT.java @@ -130,18 +130,15 @@ public String toString() { @Override public void setupSuiteScopeCluster() throws Exception { - prepareCreate("idx").addMapping( - "type", + prepareCreate("idx").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject(VALUE_FIELD) .field("type", "double") .endObject() .endObject() .endObject() - .endObject() ).execute().get(); createIndex("idx_unmapped"); List builders = new ArrayList<>(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/fetch/FetchSubPhasePluginIT.java b/server/src/internalClusterTest/java/org/opensearch/search/fetch/FetchSubPhasePluginIT.java index 68bac89213c57..def247676ac1a 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/fetch/FetchSubPhasePluginIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/fetch/FetchSubPhasePluginIT.java @@ -79,10 +79,8 @@ public void testPlugin() throws Exception { client().admin() .indices() .prepareCreate("test") - .addMapping( - "type1", + .setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -90,7 +88,6 @@ public void testPlugin() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) .get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/InnerHitsIT.java b/server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/InnerHitsIT.java index b16678d60fce7..e28ef3c00a485 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/InnerHitsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/InnerHitsIT.java @@ -100,10 +100,8 @@ protected Map, Object>> pluginScripts() { public void testSimpleNested() throws Exception { assertAcked( - prepareCreate("articles").addMapping( - "article", + prepareCreate("articles").setMapping( jsonBuilder().startObject() - .startObject("article") .startObject("properties") .startObject("comments") .field("type", "nested") @@ -119,7 +117,6 @@ public void testSimpleNested() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -313,10 +310,8 @@ public void testRandomNested() throws Exception { public void testNestedMultipleLayers() throws Exception { assertAcked( - prepareCreate("articles").addMapping( - "article", + prepareCreate("articles").setMapping( jsonBuilder().startObject() - .startObject("article") .startObject("properties") .startObject("comments") .field("type", "nested") @@ -339,7 +334,6 @@ public void testNestedMultipleLayers() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -583,8 +577,7 @@ public void testInnerHitsWithObjectFieldThatHasANestedField() throws Exception { // number_of_shards = 1, because then we catch the expected exception in the same way. // (See expectThrows(...) below) .setSettings(Settings.builder().put("index.number_of_shards", 1)) - .addMapping( - "article", + .setMapping( jsonBuilder().startObject() .startObject("properties") .startObject("comments") @@ -741,7 +734,6 @@ public void testInnerHitsWithObjectFieldThatHasANestedField() throws Exception { public void testMatchesQueriesNestedInnerHits() throws Exception { XContentBuilder builder = jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("nested1") .field("type", "nested") @@ -755,9 +747,8 @@ public void testMatchesQueriesNestedInnerHits() throws Exception { .field("type", "long") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("type1", builder)); + assertAcked(prepareCreate("test").setMapping(builder)); ensureGreen(); List requests = new ArrayList<>(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/highlight/HighlighterSearchIT.java b/server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/highlight/HighlighterSearchIT.java index 27513b575d6f0..74c2922ebf328 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/highlight/HighlighterSearchIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/fetch/subphase/highlight/HighlighterSearchIT.java @@ -139,18 +139,16 @@ protected Collection> nodePlugins() { public void testHighlightingWithKeywordIgnoreBoundaryScanner() throws IOException { XContentBuilder mappings = jsonBuilder(); mappings.startObject(); - mappings.startObject("type") - .startObject("properties") + mappings.startObject("properties") .startObject("tags") .field("type", "keyword") .endObject() .startObject("sort") .field("type", "long") .endObject() - .endObject() .endObject(); mappings.endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test") .setId("1") .setSource(jsonBuilder().startObject().array("tags", "foo bar", "foo bar", "foo bar", "foo baz").field("sort", 1).endObject()) @@ -176,16 +174,9 @@ public void testHighlightingWithKeywordIgnoreBoundaryScanner() throws IOExceptio public void testHighlightingWithStoredKeyword() throws IOException { XContentBuilder mappings = jsonBuilder(); mappings.startObject(); - mappings.startObject("type") - .startObject("properties") - .startObject("text") - .field("type", "keyword") - .field("store", true) - .endObject() - .endObject() - .endObject(); + mappings.startObject("properties").startObject("text").field("type", "keyword").field("store", true).endObject().endObject(); mappings.endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("text", "foo").endObject()).get(); refresh(); SearchResponse search = client().prepareSearch() @@ -199,18 +190,16 @@ public void testHighlightingWithWildcardName() throws IOException { // test the kibana case with * as fieldname that will try highlight all fields including meta fields XContentBuilder mappings = jsonBuilder(); mappings.startObject(); - mappings.startObject("type") - .startObject("properties") + mappings.startObject("properties") .startObject("text") .field("type", "text") .field("analyzer", "keyword") .field("index_options", "offsets") .field("term_vector", "with_positions_offsets") .endObject() - .endObject() .endObject(); mappings.endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("text", "text").endObject()).get(); refresh(); for (String type : ALL_TYPES) { @@ -224,7 +213,6 @@ public void testHighlightingWithWildcardName() throws IOException { public void testFieldAlias() throws IOException { XContentBuilder mappings = jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("text") .field("type", "text") @@ -236,9 +224,8 @@ public void testFieldAlias() throws IOException { .field("path", "text") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test").setId("1").setSource("text", "foo").get(); refresh(); @@ -253,7 +240,6 @@ public void testFieldAlias() throws IOException { public void testFieldAliasWithSourceLookup() throws IOException { XContentBuilder mappings = jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("text") .field("type", "text") @@ -266,9 +252,8 @@ public void testFieldAliasWithSourceLookup() throws IOException { .field("path", "text") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test").setId("1").setSource("text", "foo bar").get(); refresh(); @@ -283,7 +268,6 @@ public void testFieldAliasWithSourceLookup() throws IOException { public void testFieldAliasWithWildcardField() throws IOException { XContentBuilder mappings = jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("keyword") .field("type", "keyword") @@ -293,9 +277,8 @@ public void testFieldAliasWithWildcardField() throws IOException { .field("path", "keyword") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test").setId("1").setSource("keyword", "foo").get(); refresh(); @@ -308,8 +291,7 @@ public void testFieldAliasWithWildcardField() throws IOException { public void testHighlightingWhenFieldsAreNotStoredThereIsNoSource() throws IOException { XContentBuilder mappings = jsonBuilder(); mappings.startObject(); - mappings.startObject("type") - .startObject("_source") + mappings.startObject("_source") .field("enabled", false) .endObject() .startObject("properties") @@ -325,10 +307,9 @@ public void testHighlightingWhenFieldsAreNotStoredThereIsNoSource() throws IOExc .field("type", "text") .field("store", true) .endObject() - .endObject() .endObject(); mappings.endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test") .setId("1") .setSource(jsonBuilder().startObject().field("unstored_text", "text").field("text", "text").endObject()) @@ -410,10 +391,8 @@ public void testEnsureNoNegativeOffsets() throws Exception { public void testSourceLookupHighlightingUsingPlainHighlighter() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") // we don't store title and don't use term vector, now lets see if it works... .startObject("title") @@ -432,7 +411,6 @@ public void testSourceLookupHighlightingUsingPlainHighlighter() throws Exception .endObject() .endObject() .endObject() - .endObject() ) ); @@ -480,10 +458,8 @@ public void testSourceLookupHighlightingUsingPlainHighlighter() throws Exception public void testSourceLookupHighlightingUsingFastVectorHighlighter() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") // we don't store title, now lets see if it works... .startObject("title") @@ -502,7 +478,6 @@ public void testSourceLookupHighlightingUsingFastVectorHighlighter() throws Exce .endObject() .endObject() .endObject() - .endObject() ) ); @@ -550,10 +525,8 @@ public void testSourceLookupHighlightingUsingFastVectorHighlighter() throws Exce public void testSourceLookupHighlightingUsingPostingsHighlighter() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") // we don't store title, now lets see if it works... .startObject("title") @@ -572,7 +545,6 @@ public void testSourceLookupHighlightingUsingPostingsHighlighter() throws Except .endObject() .endObject() .endObject() - .endObject() ) ); @@ -771,10 +743,8 @@ public void testHighlightingOnWildcardFields() throws Exception { public void testForceSourceWithSourceDisabled() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("_source") .field("enabled", false) .endObject() @@ -790,7 +760,6 @@ public void testForceSourceWithSourceDisabled() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -852,7 +821,7 @@ public void testPlainHighlighter() throws Exception { } public void testFastVectorHighlighter() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); indexRandom( @@ -886,7 +855,7 @@ public void testFastVectorHighlighter() throws Exception { } public void testHighlighterWithSentenceBoundaryScanner() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); indexRandom( @@ -927,7 +896,7 @@ public void testHighlighterWithSentenceBoundaryScanner() throws Exception { } public void testHighlighterWithSentenceBoundaryScannerAndLocale() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); indexRandom( @@ -970,7 +939,7 @@ public void testHighlighterWithSentenceBoundaryScannerAndLocale() throws Excepti } public void testHighlighterWithWordBoundaryScanner() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); indexRandom(true, client().prepareIndex("test").setSource("field1", "some quick and hairy brown:fox jumped over the lazy dog")); @@ -1000,7 +969,7 @@ public void testHighlighterWithWordBoundaryScanner() throws Exception { } public void testHighlighterWithWordBoundaryScannerAndLocale() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); indexRandom(true, client().prepareIndex("test").setSource("field1", "some quick and hairy brown:fox jumped over the lazy dog")); @@ -1034,7 +1003,7 @@ public void testHighlighterWithWordBoundaryScannerAndLocale() throws Exception { * phraseLimit is not set. Its default is now reasonably low. */ public void testFVHManyMatches() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); // Index one megabyte of "t " over and over and over again @@ -1085,11 +1054,9 @@ private void checkMatchedFieldsCase(boolean requireFieldMatch) throws Exception settings.put("index.analysis.analyzer.mock_english.filter", "mock_snowball"); assertAcked( prepareCreate("test").setSettings(settings) - .addMapping( - "type1", + .setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("foo") .field("type", "text") @@ -1119,7 +1086,6 @@ private void checkMatchedFieldsCase(boolean requireFieldMatch) throws Exception .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1270,7 +1236,7 @@ private void checkMatchedFieldsCase(boolean requireFieldMatch) throws Exception } public void testFastVectorHighlighterManyDocs() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); int COUNT = between(20, 100); @@ -1297,7 +1263,6 @@ public void testFastVectorHighlighterManyDocs() throws Exception { public XContentBuilder type1TermVectorMapping() throws IOException { return XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -1308,7 +1273,6 @@ public XContentBuilder type1TermVectorMapping() throws IOException { .field("term_vector", "with_positions_offsets") .endObject() .endObject() - .endObject() .endObject(); } @@ -1406,10 +1370,8 @@ public void testEscapeHtmlVector() throws Exception { public void testMultiMapperVectorWithStore() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") @@ -1427,7 +1389,6 @@ public void testMultiMapperVectorWithStore() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1453,10 +1414,8 @@ public void testMultiMapperVectorWithStore() throws Exception { public void testMultiMapperVectorFromSource() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") @@ -1474,7 +1433,6 @@ public void testMultiMapperVectorFromSource() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1501,10 +1459,8 @@ public void testMultiMapperVectorFromSource() throws Exception { public void testMultiMapperNoVectorWithStore() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") @@ -1522,7 +1478,6 @@ public void testMultiMapperNoVectorWithStore() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -1549,10 +1504,8 @@ public void testMultiMapperNoVectorWithStore() throws Exception { public void testMultiMapperNoVectorFromSource() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") @@ -1570,7 +1523,6 @@ public void testMultiMapperNoVectorFromSource() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1739,7 +1691,7 @@ public void testBoostingQuery() { } public void testBoostingQueryTermVector() throws IOException { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); client().prepareIndex("test").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog").get(); refresh(); @@ -1770,7 +1722,7 @@ public void testCommonTermsQuery() { } public void testCommonTermsTermVector() throws IOException { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); ensureGreen(); client().prepareIndex("test").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog").get(); @@ -2278,7 +2230,7 @@ public void testHighlightNoMatchSizeNumberOfFragments() throws IOException { } public void testPostingsHighlighter() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2349,7 +2301,7 @@ public void testPostingsHighlighter() throws Exception { } public void testPostingsHighlighterMultipleFields() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping()).get()); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping()).get()); ensureGreen(); index( @@ -2371,7 +2323,7 @@ public void testPostingsHighlighterMultipleFields() throws Exception { } public void testPostingsHighlighterNumberOfFragments() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2457,7 +2409,6 @@ public void testPostingsHighlighterNumberOfFragments() throws Exception { public void testMultiMatchQueryHighlight() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -2470,9 +2421,8 @@ public void testMultiMatchQueryHighlight() throws IOException { .field("term_vector", "with_positions_offsets") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("type1", mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); ensureGreen(); client().prepareIndex("test") .setSource("field1", "The quick brown fox jumps over", "field2", "The quick brown fox jumps over") @@ -2507,7 +2457,7 @@ public void testMultiMatchQueryHighlight() throws IOException { } public void testPostingsHighlighterOrderByScore() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2585,10 +2535,8 @@ public void testPostingsHighlighterEscapeHtml() throws Exception { public void testPostingsHighlighterMultiMapperWithStore() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") @@ -2606,7 +2554,6 @@ public void testPostingsHighlighterMultiMapperWithStore() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -2645,10 +2592,8 @@ public void testPostingsHighlighterMultiMapperWithStore() throws Exception { public void testPostingsHighlighterMultiMapperFromSource() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") @@ -2666,7 +2611,6 @@ public void testPostingsHighlighterMultiMapperFromSource() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -2693,10 +2637,8 @@ public void testPostingsHighlighterMultiMapperFromSource() throws Exception { public void testPostingsHighlighterShouldFailIfNoOffsets() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") @@ -2705,7 +2647,6 @@ public void testPostingsHighlighterShouldFailIfNoOffsets() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -2726,7 +2667,7 @@ public void testPostingsHighlighterShouldFailIfNoOffsets() throws Exception { } public void testPostingsHighlighterBoostingQuery() throws IOException { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") .setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog! Second sentence.") @@ -2743,7 +2684,7 @@ public void testPostingsHighlighterBoostingQuery() throws IOException { } public void testPostingsHighlighterCommonTermsQuery() throws IOException { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2770,7 +2711,6 @@ public void testPostingsHighlighterCommonTermsQuery() throws IOException { private static XContentBuilder type1PostingsffsetsMapping() throws IOException { return XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -2781,12 +2721,11 @@ private static XContentBuilder type1PostingsffsetsMapping() throws IOException { .field("index_options", "offsets") .endObject() .endObject() - .endObject() .endObject(); } public void testPostingsHighlighterPrefixQuery() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2808,7 +2747,7 @@ public void testPostingsHighlighterPrefixQuery() throws Exception { } public void testPostingsHighlighterFuzzyQuery() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2831,7 +2770,7 @@ public void testPostingsHighlighterFuzzyQuery() throws Exception { } public void testPostingsHighlighterRegexpQuery() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2854,7 +2793,7 @@ public void testPostingsHighlighterRegexpQuery() throws Exception { } public void testPostingsHighlighterWildcardQuery() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2890,7 +2829,7 @@ public void testPostingsHighlighterWildcardQuery() throws Exception { } public void testPostingsHighlighterTermRangeQuery() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test").setSource("field1", "this is a test", "field2", "aaab").get(); @@ -2905,7 +2844,7 @@ public void testPostingsHighlighterTermRangeQuery() throws Exception { } public void testPostingsHighlighterQueryString() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test") @@ -2928,7 +2867,7 @@ public void testPostingsHighlighterQueryString() throws Exception { } public void testPostingsHighlighterRegexpQueryWithinConstantScoreQuery() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test").setSource("field1", "The photography word will get highlighted").get(); @@ -2942,7 +2881,7 @@ public void testPostingsHighlighterRegexpQueryWithinConstantScoreQuery() throws } public void testPostingsHighlighterMultiTermQueryMultipleLevels() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test").setSource("field1", "The photography word will get highlighted").get(); @@ -2959,7 +2898,7 @@ public void testPostingsHighlighterMultiTermQueryMultipleLevels() throws Excepti } public void testPostingsHighlighterPrefixQueryWithinBooleanQuery() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test").setSource("field1", "The photography word will get highlighted").get(); @@ -2974,7 +2913,7 @@ public void testPostingsHighlighterPrefixQueryWithinBooleanQuery() throws Except } public void testPostingsHighlighterQueryStringWithinFilteredQuery() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); client().prepareIndex("test").setSource("field1", "The photography word will get highlighted").get(); @@ -2989,7 +2928,7 @@ public void testPostingsHighlighterQueryStringWithinFilteredQuery() throws Excep } public void testPostingsHighlighterManyDocs() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1PostingsffsetsMapping())); + assertAcked(prepareCreate("test").setMapping(type1PostingsffsetsMapping())); ensureGreen(); int COUNT = between(20, 100); @@ -3025,7 +2964,6 @@ public void testPostingsHighlighterManyDocs() throws Exception { public void testDoesNotHighlightTypeName() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("typename") .startObject("properties") .startObject("foo") .field("type", "text") @@ -3033,9 +2971,8 @@ public void testDoesNotHighlightTypeName() throws Exception { .field("term_vector", "with_positions_offsets") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("typename", mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); ensureGreen(); indexRandom(true, client().prepareIndex("test").setSource("foo", "test typename")); @@ -3052,7 +2989,6 @@ public void testDoesNotHighlightTypeName() throws Exception { public void testDoesNotHighlightAliasFilters() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("typename") .startObject("properties") .startObject("foo") .field("type", "text") @@ -3060,9 +2996,8 @@ public void testDoesNotHighlightAliasFilters() throws Exception { .field("term_vector", "with_positions_offsets") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("typename", mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); assertAcked(client().admin().indices().prepareAliases().addAlias("test", "filtered_alias", matchQuery("foo", "japanese"))); ensureGreen(); @@ -3078,7 +3013,7 @@ public void testDoesNotHighlightAliasFilters() throws Exception { } public void testFastVectorHighlighterPhraseBoost() throws Exception { - assertAcked(prepareCreate("test").addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test").setMapping(type1TermVectorMapping())); phraseBoostTestCase("fvh"); } @@ -3174,8 +3109,7 @@ public void testGeoFieldHighlightingWithDifferentHighlighters() throws IOExcepti // see https://github.com/elastic/elasticsearch/issues/17537 XContentBuilder mappings = jsonBuilder(); mappings.startObject(); - mappings.startObject("type") - .startObject("properties") + mappings.startObject("properties") .startObject("geo_point") .field("type", "geo_point") .endObject() @@ -3184,10 +3118,9 @@ public void testGeoFieldHighlightingWithDifferentHighlighters() throws IOExcepti .field("term_vector", "with_positions_offsets_payloads") .field("index_options", "offsets") .endObject() - .endObject() .endObject(); mappings.endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test") .setId("1") @@ -3216,18 +3149,16 @@ public void testGeoFieldHighlightingWhenQueryGetsRewritten() throws IOException // see https://github.com/elastic/elasticsearch/issues/17537#issuecomment-244939633 XContentBuilder mappings = jsonBuilder(); mappings.startObject(); - mappings.startObject("jobs") - .startObject("properties") + mappings.startObject("properties") .startObject("loc") .field("type", "geo_point") .endObject() .startObject("jd") .field("type", "text") .endObject() - .endObject() .endObject(); mappings.endObject(); - assertAcked(prepareCreate("test").addMapping("jobs", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); ensureYellow(); client().prepareIndex("test") @@ -3259,15 +3190,9 @@ public void testKeywordFieldHighlighting() throws IOException { // check that keyword highlighting works XContentBuilder mappings = jsonBuilder(); mappings.startObject(); - mappings.startObject("type") - .startObject("properties") - .startObject("keyword_field") - .field("type", "keyword") - .endObject() - .endObject() - .endObject(); + mappings.startObject("properties").startObject("keyword_field").field("type", "keyword").endObject().endObject(); mappings.endObject(); - assertAcked(prepareCreate("test").addMapping("type", mappings)); + assertAcked(prepareCreate("test").setMapping(mappings)); client().prepareIndex("test") .setId("1") @@ -3299,7 +3224,7 @@ public void testCopyToFields() throws Exception { // If field is not stored, it is looked up in source (but source has only 'foo' b.startObject("foo_copy").field("type", "text").field("store", true).endObject(); b.endObject().endObject(); - prepareCreate("test").addMapping("type", b).get(); + prepareCreate("test").setMapping(b).get(); client().prepareIndex("test") .setId("1") diff --git a/server/src/internalClusterTest/java/org/opensearch/search/fieldcaps/FieldCapabilitiesIT.java b/server/src/internalClusterTest/java/org/opensearch/search/fieldcaps/FieldCapabilitiesIT.java index 8767904e03c72..aed2975ed3234 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/fieldcaps/FieldCapabilitiesIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/fieldcaps/FieldCapabilitiesIT.java @@ -88,7 +88,7 @@ public void setUp() throws Exception { .endObject() .endObject() .endObject(); - assertAcked(prepareCreate("old_index").addMapping("_doc", oldIndexMapping)); + assertAcked(prepareCreate("old_index").setMapping(oldIndexMapping)); XContentBuilder newIndexMapping = XContentFactory.jsonBuilder() .startObject() @@ -106,7 +106,7 @@ public void setUp() throws Exception { .endObject() .endObject() .endObject(); - assertAcked(prepareCreate("new_index").addMapping("_doc", newIndexMapping)); + assertAcked(prepareCreate("new_index").setMapping(newIndexMapping)); assertAcked(client().admin().indices().prepareAliases().addAlias("new_index", "current")); } diff --git a/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java b/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java index 72c60e98ec328..46d47d838f68b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/fields/SearchFieldsIT.java @@ -774,10 +774,8 @@ public void testGetFieldsComplexField() throws Exception { .indices() .prepareCreate("my-index") .setSettings(Settings.builder().put("index.refresh_interval", -1)) - .addMapping( - MapperService.SINGLE_MAPPING_NAME, + .setMapping( jsonBuilder().startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject("field1") .field("type", "object") @@ -800,7 +798,6 @@ public void testGetFieldsComplexField() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) .get(); @@ -1181,7 +1178,6 @@ public void testScriptFields() throws Exception { public void testDocValueFieldsWithFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("_source") .field("enabled", false) .endObject() @@ -1203,9 +1199,8 @@ public void testDocValueFieldsWithFieldAlias() throws Exception { .field("path", "date_field") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); ensureGreen("test"); DateTime date = new DateTime(1990, 12, 29, 0, 0, DateTimeZone.UTC); @@ -1244,7 +1239,6 @@ public void testDocValueFieldsWithFieldAlias() throws Exception { public void testWildcardDocValueFieldsWithFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("_source") .field("enabled", false) .endObject() @@ -1266,9 +1260,8 @@ public void testWildcardDocValueFieldsWithFieldAlias() throws Exception { .field("path", "date_field") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); ensureGreen("test"); DateTime date = new DateTime(1990, 12, 29, 0, 0, DateTimeZone.UTC); @@ -1306,7 +1299,6 @@ public void testWildcardDocValueFieldsWithFieldAlias() throws Exception { public void testStoredFieldsWithFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject("field1") .field("type", "text") @@ -1325,9 +1317,8 @@ public void testStoredFieldsWithFieldAlias() throws Exception { .field("path", "field2") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); index("test", MapperService.SINGLE_MAPPING_NAME, "1", "field1", "value1", "field2", "value2"); refresh("test"); @@ -1350,7 +1341,6 @@ public void testStoredFieldsWithFieldAlias() throws Exception { public void testWildcardStoredFieldsWithFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject("field1") .field("type", "text") @@ -1369,9 +1359,8 @@ public void testWildcardStoredFieldsWithFieldAlias() throws Exception { .field("path", "field2") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping(MapperService.SINGLE_MAPPING_NAME, mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); index("test", MapperService.SINGLE_MAPPING_NAME, "1", "field1", "value1", "field2", "value2"); refresh("test"); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/DecayFunctionScoreIT.java b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/DecayFunctionScoreIT.java index 712026eaf5c43..709a916d98838 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/DecayFunctionScoreIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/DecayFunctionScoreIT.java @@ -96,10 +96,8 @@ protected boolean forbidPrivateIndexSettings() { public void testDistanceScoreGeoLinGaussExp() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -109,7 +107,6 @@ public void testDistanceScoreGeoLinGaussExp() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -223,10 +220,8 @@ public void testDistanceScoreGeoLinGaussExp() throws Exception { public void testDistanceScoreGeoLinGaussExpWithOffset() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -236,7 +231,6 @@ public void testDistanceScoreGeoLinGaussExpWithOffset() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -337,10 +331,8 @@ public void testBoostModeSettingWorks() throws Exception { Settings settings = Settings.builder().put(IndexMetadata.INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), 1).build(); assertAcked( prepareCreate("test").setSettings(settings) - .addMapping( - "type1", + .setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -350,7 +342,6 @@ public void testBoostModeSettingWorks() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -436,10 +427,8 @@ public void testBoostModeSettingWorks() throws Exception { public void testParseGeoPoint() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -449,7 +438,6 @@ public void testParseGeoPoint() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -504,10 +492,8 @@ public void testParseGeoPoint() throws Exception { public void testCombineModes() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -517,7 +503,6 @@ public void testCombineModes() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -621,10 +606,8 @@ public void testCombineModes() throws Exception { public void testCombineModesExplain() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -634,7 +617,6 @@ public void testCombineModesExplain() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -691,10 +673,8 @@ public void testCombineModesExplain() throws Exception { public void testExceptionThrownIfScaleLE0() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -704,7 +684,6 @@ public void testExceptionThrownIfScaleLE0() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); client().index( @@ -731,10 +710,8 @@ public void testExceptionThrownIfScaleLE0() throws Exception { public void testParseDateMath() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -745,7 +722,6 @@ public void testParseDateMath() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); client().index( @@ -785,10 +761,8 @@ public void testParseDateMath() throws Exception { public void testValueMissingLin() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -801,7 +775,6 @@ public void testValueMissingLin() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -854,10 +827,8 @@ public void testDateWithoutOrigin() throws Exception { ZonedDateTime dt = ZonedDateTime.now(ZoneOffset.UTC); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -867,7 +838,6 @@ public void testDateWithoutOrigin() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -933,7 +903,6 @@ public void testManyDocsLin() throws Exception { Version version = VersionUtils.randomIndexCompatibleVersion(random()); Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("test") .field("type", "text") @@ -949,8 +918,8 @@ public void testManyDocsLin() throws Exception { .startObject("geo") .field("type", "geo_point") .field("ignore_malformed", true); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").setSettings(settings).addMapping("type", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).setMapping(xContentBuilder)); int numDocs = 200; List indexBuilders = new ArrayList<>(); @@ -1013,10 +982,8 @@ public void testManyDocsLin() throws Exception { public void testParsingExceptionIfFieldDoesNotExist() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("test") .field("type", "text") @@ -1026,7 +993,6 @@ public void testParsingExceptionIfFieldDoesNotExist() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); int numDocs = 2; @@ -1066,10 +1032,8 @@ public void testParsingExceptionIfFieldDoesNotExist() throws Exception { public void testParsingExceptionIfFieldTypeDoesNotMatch() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("test") .field("type", "text") @@ -1079,7 +1043,6 @@ public void testParsingExceptionIfFieldTypeDoesNotMatch() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); client().index( @@ -1105,10 +1068,8 @@ public void testParsingExceptionIfFieldTypeDoesNotMatch() throws Exception { public void testNoQueryGiven() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("test") .field("type", "text") @@ -1118,7 +1079,6 @@ public void testNoQueryGiven() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); client().index(indexRequest("test").source(jsonBuilder().startObject().field("test", "value").field("num", 1.0).endObject())) @@ -1138,10 +1098,8 @@ public void testNoQueryGiven() throws Exception { public void testMultiFieldOptions() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -1154,7 +1112,6 @@ public void testMultiFieldOptions() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -1271,10 +1228,8 @@ public void testMultiFieldOptions() throws Exception { public void testDistanceScoreGeoLinGaussExplain() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -1284,7 +1239,6 @@ public void testDistanceScoreGeoLinGaussExplain() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScoreFieldValueIT.java b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScoreFieldValueIT.java index 8e0a14b7062a7..4e1df591cb245 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScoreFieldValueIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScoreFieldValueIT.java @@ -57,10 +57,8 @@ public class FunctionScoreFieldValueIT extends OpenSearchIntegTestCase { public void testFieldValueFactor() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", randomFrom(new String[] { "short", "float", "long", "integer", "double" })) @@ -70,7 +68,6 @@ public void testFieldValueFactor() throws IOException { .endObject() .endObject() .endObject() - .endObject() ).get() ); @@ -169,10 +166,8 @@ public void testFieldValueFactor() throws IOException { public void testFieldValueFactorExplain() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", randomFrom(new String[] { "short", "float", "long", "integer", "double" })) @@ -182,7 +177,6 @@ public void testFieldValueFactorExplain() throws IOException { .endObject() .endObject() .endObject() - .endObject() ).get() ); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScorePluginIT.java b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScorePluginIT.java index 885f1aa7ff7a0..a7a14f3b0d889 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScorePluginIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/FunctionScorePluginIT.java @@ -76,10 +76,8 @@ public void testPlugin() throws Exception { client().admin() .indices() .prepareCreate("test") - .addMapping( - "type1", + .setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("test") .field("type", "text") @@ -89,7 +87,6 @@ public void testPlugin() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) .get(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/QueryRescorerIT.java b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/QueryRescorerIT.java index e216e92c63bad..c4a41ad5b76e2 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/functionscore/QueryRescorerIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/functionscore/QueryRescorerIT.java @@ -127,10 +127,8 @@ public void testEnforceWindowSize() { public void testRescorePhrase() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("analyzer", "whitespace") @@ -138,7 +136,6 @@ public void testRescorePhrase() throws Exception { .endObject() .endObject() .endObject() - .endObject() ).setSettings(Settings.builder().put(indexSettings()).put("index.number_of_shards", 1)) ); @@ -190,22 +187,16 @@ public void testMoreDocs() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") .field("analyzer", "whitespace") .endObject() .endObject() - .endObject() .endObject(); assertAcked( - client().admin() - .indices() - .prepareCreate("test") - .addMapping("type1", mapping) - .setSettings(builder.put("index.number_of_shards", 1)) + client().admin().indices().prepareCreate("test").setMapping(mapping).setSettings(builder.put("index.number_of_shards", 1)) ); client().prepareIndex("test").setId("1").setSource("field1", "massachusetts avenue boston massachusetts").get(); @@ -285,22 +276,16 @@ public void testSmallRescoreWindow() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") .field("analyzer", "whitespace") .endObject() .endObject() - .endObject() .endObject(); assertAcked( - client().admin() - .indices() - .prepareCreate("test") - .addMapping("type1", mapping) - .setSettings(builder.put("index.number_of_shards", 1)) + client().admin().indices().prepareCreate("test").setMapping(mapping).setSettings(builder.put("index.number_of_shards", 1)) ); client().prepareIndex("test").setId("3").setSource("field1", "massachusetts").get(); @@ -371,22 +356,16 @@ public void testRescorerMadeScoresWorse() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") .field("analyzer", "whitespace") .endObject() .endObject() - .endObject() .endObject(); assertAcked( - client().admin() - .indices() - .prepareCreate("test") - .addMapping("type1", mapping) - .setSettings(builder.put("index.number_of_shards", 1)) + client().admin().indices().prepareCreate("test").setMapping(mapping).setSettings(builder.put("index.number_of_shards", 1)) ); client().prepareIndex("test").setId("3").setSource("field1", "massachusetts").get(); @@ -524,10 +503,8 @@ public void testEquivalence() throws Exception { public void testExplain() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("analyzer", "whitespace") @@ -535,7 +512,6 @@ public void testExplain() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -785,10 +761,8 @@ private int indexRandomNumbers(String analyzer, int shards, boolean dummyDocs) t } assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("analyzer", analyzer) @@ -796,7 +770,6 @@ private int indexRandomNumbers(String analyzer, int shards, boolean dummyDocs) t .endObject() .endObject() .endObject() - .endObject() ).setSettings(builder) ); int numDocs = randomIntBetween(100, 150); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoBoundingBoxQueryIT.java b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoBoundingBoxQueryIT.java index f865e56cd99e3..90e7163342547 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoBoundingBoxQueryIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoBoundingBoxQueryIT.java @@ -64,12 +64,11 @@ public void testSimpleBoundingBoxTest() throws Exception { Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("location") .field("type", "geo_point"); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).setMapping(xContentBuilder)); ensureGreen(); client().prepareIndex("test") @@ -195,12 +194,11 @@ public void testLimit2BoundingBox() throws Exception { Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("location") .field("type", "geo_point"); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).setMapping(xContentBuilder)); ensureGreen(); client().prepareIndex("test") @@ -275,12 +273,11 @@ public void testCompleteLonRange() throws Exception { Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("location") .field("type", "geo_point"); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).setMapping(xContentBuilder)); ensureGreen(); client().prepareIndex("test") diff --git a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoDistanceIT.java b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoDistanceIT.java index d00c0a8c0faf7..ba7af0ecfcb06 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoDistanceIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoDistanceIT.java @@ -124,12 +124,11 @@ public void setupTestIndex() throws IOException { Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("location") .field("type", "geo_point"); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).setMapping(xContentBuilder)); ensureGreen(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java index 8322c9704eecb..975cb5f7e3b8c 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/geo/GeoFilterIT.java @@ -393,7 +393,6 @@ public void testBulk() throws Exception { Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("country") .startObject("properties") .startObject("pin") .field("type", "geo_point"); @@ -404,10 +403,9 @@ public void testBulk() throws Exception { .field("ignore_malformed", true) .endObject() .endObject() - .endObject() .endObject(); - client().admin().indices().prepareCreate("countries").setSettings(settings).addMapping("country", xContentBuilder).get(); + client().admin().indices().prepareCreate("countries").setSettings(settings).setMapping(xContentBuilder).get(); BulkResponse bulk = client().prepareBulk().add(bulkAction, 0, bulkAction.length, null, xContentBuilder.contentType()).get(); for (BulkItemResponse item : bulk.getItems()) { diff --git a/server/src/internalClusterTest/java/org/opensearch/search/morelikethis/MoreLikeThisIT.java b/server/src/internalClusterTest/java/org/opensearch/search/morelikethis/MoreLikeThisIT.java index 7ffd648d06611..69b2e655dd0ad 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/morelikethis/MoreLikeThisIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/morelikethis/MoreLikeThisIT.java @@ -86,17 +86,14 @@ protected Collection> nodePlugins() { public void testSimpleMoreLikeThis() throws Exception { logger.info("Creating index test"); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("text") .field("type", "text") .endObject() .endObject() .endObject() - .endObject() ) ); @@ -119,17 +116,14 @@ public void testSimpleMoreLikeThis() throws Exception { public void testSimpleMoreLikeThisWithTypes() throws Exception { logger.info("Creating index test"); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("text") .field("type", "text") .endObject() .endObject() .endObject() - .endObject() ) ); @@ -151,10 +145,8 @@ public void testSimpleMoreLikeThisWithTypes() throws Exception { // Issue #30148 public void testMoreLikeThisForZeroTokensInOneOfTheAnalyzedFields() throws Exception { - CreateIndexRequestBuilder createIndexRequestBuilder = prepareCreate("test").addMapping( - "type", + CreateIndexRequestBuilder createIndexRequestBuilder = prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("myField") .field("type", "text") @@ -164,7 +156,6 @@ public void testMoreLikeThisForZeroTokensInOneOfTheAnalyzedFields() throws Excep .endObject() .endObject() .endObject() - .endObject() ); assertAcked(createIndexRequestBuilder); @@ -214,17 +205,14 @@ public void testSimpleMoreLikeOnLongField() throws Exception { public void testMoreLikeThisWithAliases() throws Exception { logger.info("Creating index test"); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("text") .field("type", "text") .endObject() .endObject() .endObject() - .endObject() ) ); logger.info("Creating aliases alias release"); @@ -370,10 +358,8 @@ public void testMoreLikeThisIssueRoutingNotSerialized() throws Exception { // Issue #3252 public void testNumericField() throws Exception { final String[] numericTypes = new String[] { "byte", "short", "integer", "long" }; - prepareCreate("test").addMapping( - "type", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("int_value") .field("type", randomFrom(numericTypes)) @@ -383,7 +369,6 @@ public void testNumericField() throws Exception { .endObject() .endObject() .endObject() - .endObject() ).get(); ensureGreen(); client().prepareIndex("test") @@ -486,7 +471,6 @@ public void testNumericField() throws Exception { public void testMoreLikeThisWithFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") .startObject("properties") .startObject("text") .field("type", "text") @@ -496,10 +480,9 @@ public void testMoreLikeThisWithFieldAlias() throws Exception { .field("path", "text") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("_doc", mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); ensureGreen(); index("test", "_doc", "1", "text", "lucene"); @@ -517,17 +500,14 @@ public void testMoreLikeThisWithFieldAlias() throws Exception { public void testSimpleMoreLikeInclude() throws Exception { logger.info("Creating index test"); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("text") .field("type", "text") .endObject() .endObject() .endObject() - .endObject() ) ); @@ -584,17 +564,14 @@ public void testSimpleMoreLikeInclude() throws Exception { public void testSimpleMoreLikeThisIds() throws Exception { logger.info("Creating index test"); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("text") .field("type", "text") .endObject() .endObject() .endObject() - .endObject() ) ); @@ -867,10 +844,8 @@ public void testWithRouting() throws IOException { public void testWithMissingRouting() throws IOException { logger.info("Creating index test with routing required for type1"); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("text") .field("type", "text") @@ -880,7 +855,6 @@ public void testWithMissingRouting() throws IOException { .field("required", true) .endObject() .endObject() - .endObject() ) ); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/nested/SimpleNestedIT.java b/server/src/internalClusterTest/java/org/opensearch/search/nested/SimpleNestedIT.java index c6c58e6fcb6a5..e3c1abff5d206 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/nested/SimpleNestedIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/nested/SimpleNestedIT.java @@ -213,10 +213,8 @@ public void testSimpleNested() throws Exception { public void testMultiNested() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("nested1") .field("type", "nested") @@ -228,7 +226,6 @@ public void testMultiNested() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -371,10 +368,8 @@ public void testMultiNested() throws Exception { public void testDeleteNestedDocsWithAlias() throws Exception { assertAcked( prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.refresh_interval", -1).build()) - .addMapping( - "type1", + .setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("type", "text") @@ -384,7 +379,6 @@ public void testDeleteNestedDocsWithAlias() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -437,17 +431,14 @@ public void testDeleteNestedDocsWithAlias() throws Exception { public void testExplain() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("nested1") .field("type", "nested") .endObject() .endObject() .endObject() - .endObject() ) ); @@ -485,10 +476,8 @@ public void testExplain() throws Exception { public void testSimpleNestedSorting() throws Exception { assertAcked( prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.refresh_interval", -1)) - .addMapping( - "type1", + .setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("nested1") .field("type", "nested") @@ -501,7 +490,6 @@ public void testSimpleNestedSorting() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -586,10 +574,8 @@ public void testSimpleNestedSorting() throws Exception { public void testSimpleNestedSortingWithNestedFilterMissing() throws Exception { assertAcked( prepareCreate("test").setSettings(Settings.builder().put(indexSettings()).put("index.refresh_interval", -1)) - .addMapping( - "type1", + .setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("nested1") .field("type", "nested") @@ -604,7 +590,6 @@ public void testSimpleNestedSortingWithNestedFilterMissing() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1048,11 +1033,9 @@ public void testLeakingSortValues() throws Exception { public void testSortNestedWithNestedFilter() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("grand_parent_values") .field("type", "long") @@ -1075,7 +1058,6 @@ public void testSortNestedWithNestedFilter() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1448,8 +1430,7 @@ public void testSortNestedWithNestedFilter() throws Exception { // Issue #9305 public void testNestedSortingWithNestedFilterAsFilter() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type", + prepareCreate("test").setMapping( jsonBuilder().startObject() .startObject("properties") .startObject("officelocation") diff --git a/server/src/internalClusterTest/java/org/opensearch/search/query/ExistsIT.java b/server/src/internalClusterTest/java/org/opensearch/search/query/ExistsIT.java index 89c614485b620..75b8e46802061 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/query/ExistsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/query/ExistsIT.java @@ -70,7 +70,6 @@ public void testEmptyIndex() throws Exception { public void testExists() throws Exception { XContentBuilder mapping = XContentBuilder.builder(JsonXContent.jsonXContent) .startObject() - .startObject("type") .startObject("properties") .startObject("foo") .field("type", "text") @@ -95,10 +94,9 @@ public void testExists() throws Exception { .endObject() .endObject() .endObject() - .endObject() .endObject(); - assertAcked(client().admin().indices().prepareCreate("idx").addMapping("type", mapping)); + assertAcked(client().admin().indices().prepareCreate("idx").setMapping(mapping)); Map barObject = new HashMap<>(); barObject.put("foo", "bar"); barObject.put("bar", singletonMap("bar", "foo")); @@ -176,7 +174,6 @@ public void testExists() throws Exception { public void testFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("bar") .field("type", "long") @@ -194,9 +191,8 @@ public void testFieldAlias() throws Exception { .field("path", "foo.bar") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("idx").addMapping("type", mapping)); + assertAcked(prepareCreate("idx").setMapping(mapping)); ensureGreen("idx"); List indexRequests = new ArrayList<>(); @@ -226,7 +222,6 @@ public void testFieldAlias() throws Exception { public void testFieldAliasWithNoDocValues() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("foo") .field("type", "long") @@ -237,9 +232,8 @@ public void testFieldAliasWithNoDocValues() throws Exception { .field("path", "foo") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("idx").addMapping("type", mapping)); + assertAcked(prepareCreate("idx").setMapping(mapping)); ensureGreen("idx"); List indexRequests = new ArrayList<>(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/query/MultiMatchQueryIT.java b/server/src/internalClusterTest/java/org/opensearch/search/query/MultiMatchQueryIT.java index b40a034fc2c92..66b42fe266887 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/query/MultiMatchQueryIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/query/MultiMatchQueryIT.java @@ -109,7 +109,7 @@ public void init() throws Exception { .put("index.analysis.analyzer.category.tokenizer", "standard") .put("index.analysis.analyzer.category.filter", "lowercase") ); - assertAcked(builder.addMapping("test", createMapping())); + assertAcked(builder.setMapping(createMapping())); ensureGreen(); int numDocs = scaledRandomIntBetween(50, 100); List builders = new ArrayList<>(); @@ -259,7 +259,6 @@ public void init() throws Exception { private XContentBuilder createMapping() throws IOException { return XContentFactory.jsonBuilder() .startObject() - .startObject("test") .startObject("properties") .startObject("id") .field("type", "keyword") @@ -287,7 +286,6 @@ private XContentBuilder createMapping() throws IOException { .field("type", "date") .endObject() .endObject() - .endObject() .endObject(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/search/query/QueryStringIT.java b/server/src/internalClusterTest/java/org/opensearch/search/query/QueryStringIT.java index 494aa4c0e6b88..5c7e53fda3f23 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/query/QueryStringIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/query/QueryStringIT.java @@ -278,16 +278,14 @@ public void testAllFieldsWithSpecifiedLeniency() throws IOException { public void testLimitOnExpandedFieldsButIgnoreUnmappedFields() throws Exception { XContentBuilder builder = jsonBuilder(); builder.startObject(); - builder.startObject("_doc"); builder.startObject("properties"); for (int i = 0; i < CLUSTER_MAX_CLAUSE_COUNT; i++) { builder.startObject("field" + i).field("type", "text").endObject(); } builder.endObject(); // properties - builder.endObject(); // type1 builder.endObject(); - assertAcked(prepareCreate("ignoreunmappedfields").addMapping("_doc", builder)); + assertAcked(prepareCreate("ignoreunmappedfields").setMapping(builder)); client().prepareIndex("ignoreunmappedfields").setId("1").setSource("field1", "foo bar baz").get(); refresh(); @@ -303,25 +301,19 @@ public void testLimitOnExpandedFields() throws Exception { XContentBuilder builder = jsonBuilder(); builder.startObject(); { - builder.startObject("_doc"); - { - builder.startObject("properties"); - { - for (int i = 0; i < CLUSTER_MAX_CLAUSE_COUNT; i++) { - builder.startObject("field_A" + i).field("type", "text").endObject(); - builder.startObject("field_B" + i).field("type", "text").endObject(); - } - builder.endObject(); - } - builder.endObject(); + builder.startObject("properties"); + for (int i = 0; i < CLUSTER_MAX_CLAUSE_COUNT; i++) { + builder.startObject("field_A" + i).field("type", "text").endObject(); + builder.startObject("field_B" + i).field("type", "text").endObject(); } builder.endObject(); } + builder.endObject(); assertAcked( prepareCreate("testindex").setSettings( Settings.builder().put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), CLUSTER_MAX_CLAUSE_COUNT + 100) - ).addMapping("_doc", builder) + ).setMapping(builder) ); client().prepareIndex("testindex").setId("1").setSource("field_A0", "foo bar baz").get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/query/SearchQueryIT.java b/server/src/internalClusterTest/java/org/opensearch/search/query/SearchQueryIT.java index fb744ccfc4655..fa2d79ecb2017 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/query/SearchQueryIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/query/SearchQueryIT.java @@ -1119,10 +1119,8 @@ public void testTermsQuery() throws Exception { public void testTermsLookupFilter() throws Exception { assertAcked(prepareCreate("lookup").addMapping("type", "terms", "type=text", "other", "type=text")); assertAcked( - prepareCreate("lookup2").addMapping( - "type", + prepareCreate("lookup2").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("arr") .startObject("properties") @@ -1133,7 +1131,6 @@ public void testTermsLookupFilter() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); assertAcked(prepareCreate("lookup3").addMapping("type", "_source", "enabled=false", "terms", "type=text")); @@ -1600,10 +1597,8 @@ public void testSpanNot() throws IOException, ExecutionException, InterruptedExc public void testSimpleDFSQuery() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "_doc", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("_doc") .startObject("_routing") .field("required", true) .endObject() @@ -1621,7 +1616,6 @@ public void testSimpleDFSQuery() throws IOException { .endObject() .endObject() .endObject() - .endObject() ) ); @@ -1876,8 +1870,7 @@ public void testRangeQueryWithLocaleMapping() throws Exception { assert ("SPI,COMPAT".equals(System.getProperty("java.locale.providers"))) : "`-Djava.locale.providers=SPI,COMPAT` needs to be set"; assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() .startObject("properties") .startObject("date_field") @@ -1978,7 +1971,6 @@ public void testRangeQueryRangeFields_24744() throws Exception { public void testNestedQueryWithFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("_doc") .startObject("properties") .startObject("section") .field("type", "nested") @@ -1993,9 +1985,8 @@ public void testNestedQueryWithFieldAlias() throws Exception { .endObject() .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("index").addMapping("_doc", mapping)); + assertAcked(prepareCreate("index").setMapping(mapping)); XContentBuilder source = XContentFactory.jsonBuilder() .startObject() @@ -2019,7 +2010,6 @@ public void testNestedQueryWithFieldAlias() throws Exception { public void testFieldAliasesForMetaFields() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("id-alias") .field("type", "alias") @@ -2030,9 +2020,8 @@ public void testFieldAliasesForMetaFields() throws Exception { .field("path", "_routing") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("type", mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); IndexRequestBuilder indexRequest = client().prepareIndex("test").setId("1").setRouting("custom").setSource("field", "value"); indexRandom(true, false, indexRequest); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/query/SimpleQueryStringIT.java b/server/src/internalClusterTest/java/org/opensearch/search/query/SimpleQueryStringIT.java index c53eda63f155f..e0391d9cbc971 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/query/SimpleQueryStringIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/query/SimpleQueryStringIT.java @@ -239,10 +239,8 @@ public void testSimpleQueryStringMinimumShouldMatch() throws Exception { public void testNestedFieldSimpleQueryString() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("body") .field("type", "text") @@ -253,7 +251,6 @@ public void testNestedFieldSimpleQueryString() throws IOException { .endObject() // fields .endObject() // body .endObject() // properties - .endObject() // type1 .endObject() ) ); @@ -607,19 +604,17 @@ public void testAllFieldsWithSpecifiedLeniency() throws IOException { public void testLimitOnExpandedFields() throws Exception { XContentBuilder builder = jsonBuilder(); builder.startObject(); - builder.startObject("type1"); builder.startObject("properties"); for (int i = 0; i < CLUSTER_MAX_CLAUSE_COUNT + 1; i++) { builder.startObject("field" + i).field("type", "text").endObject(); } builder.endObject(); // properties - builder.endObject(); // type1 builder.endObject(); assertAcked( prepareCreate("toomanyfields").setSettings( Settings.builder().put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), CLUSTER_MAX_CLAUSE_COUNT + 100) - ).addMapping("type1", builder) + ).setMapping(builder) ); client().prepareIndex("toomanyfields").setId("1").setSource("field1", "foo bar baz").get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/scriptfilter/ScriptQuerySearchIT.java b/server/src/internalClusterTest/java/org/opensearch/search/scriptfilter/ScriptQuerySearchIT.java index 3b120dcab22f2..3bc9eb5b25261 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/scriptfilter/ScriptQuerySearchIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/scriptfilter/ScriptQuerySearchIT.java @@ -127,11 +127,7 @@ public void testCustomScriptBinaryField() throws Exception { final byte[] randomBytesDoc2 = getRandomBytes(16); assertAcked( - client().admin() - .indices() - .prepareCreate("my-index") - .addMapping("my-type", createMappingSource("binary")) - .setSettings(indexSettings()) + client().admin().indices().prepareCreate("my-index").setMapping(createMappingSource("binary")).setSettings(indexSettings()) ); client().prepareIndex("my-index") .setId("1") @@ -170,14 +166,12 @@ private byte[] getRandomBytes(int len) { private XContentBuilder createMappingSource(String fieldType) throws IOException { return XContentFactory.jsonBuilder() .startObject() - .startObject("my-type") .startObject("properties") .startObject("binaryData") .field("type", fieldType) .field("doc_values", "true") .endObject() .endObject() - .endObject() .endObject(); } diff --git a/server/src/internalClusterTest/java/org/opensearch/search/scroll/DuelScrollIT.java b/server/src/internalClusterTest/java/org/opensearch/search/scroll/DuelScrollIT.java index be55193da30cc..19cf1ee3a0ee7 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/scroll/DuelScrollIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/scroll/DuelScrollIT.java @@ -115,10 +115,8 @@ public void testDuelQueryThenFetch() throws Exception { private TestContext create(SearchType... searchTypes) throws Exception { assertAcked( - prepareCreate("index").addMapping( - "type", + prepareCreate("index").setMapping( jsonBuilder().startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "long") @@ -139,7 +137,6 @@ private TestContext create(SearchType... searchTypes) throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/sort/FieldSortIT.java b/server/src/internalClusterTest/java/org/opensearch/search/sort/FieldSortIT.java index 38aac2850dc56..3d1d407b386e1 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/sort/FieldSortIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/sort/FieldSortIT.java @@ -276,11 +276,9 @@ public void testTrackScores() throws Exception { public void testRandomSorting() throws IOException, InterruptedException, ExecutionException { Random random = random(); assertAcked( - prepareCreate("test").addMapping( - "type", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("sparse_bytes") .field("type", "keyword") @@ -290,7 +288,6 @@ public void testRandomSorting() throws IOException, InterruptedException, Execut .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -558,11 +555,9 @@ public void testIssue2991() { public void testSimpleSorts() throws Exception { Random random = random(); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("str_value") .field("type", "keyword") @@ -590,7 +585,6 @@ public void testSimpleSorts() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -801,11 +795,9 @@ public void testSimpleSorts() throws Exception { public void testSortMissingNumbers() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("i_value") .field("type", "integer") @@ -815,7 +807,6 @@ public void testSortMissingNumbers() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -873,18 +864,15 @@ public void testSortMissingNumbers() throws Exception { public void testSortMissingStrings() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("value") .field("type", "keyword") .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1009,11 +997,9 @@ public void testIgnoreUnmapped() throws Exception { public void testSortMVField() throws Exception { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("long_values") .field("type", "long") @@ -1038,7 +1024,6 @@ public void testSortMVField() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1345,18 +1330,15 @@ public void testSortMVField() throws Exception { public void testSortOnRareField() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("string_values") .field("type", "keyword") .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -1494,11 +1476,9 @@ public void testSortMetaField() throws Exception { */ public void testNestedSort() throws IOException, InterruptedException, ExecutionException { assertAcked( - prepareCreate("test").addMapping( - "type", + prepareCreate("test").setMapping( XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("nested") .field("type", "nested") @@ -1530,7 +1510,6 @@ public void testNestedSort() throws IOException, InterruptedException, Execution .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/sort/GeoDistanceIT.java b/server/src/internalClusterTest/java/org/opensearch/search/sort/GeoDistanceIT.java index 1739add2ff5e8..5cc9ab77bcb2d 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/sort/GeoDistanceIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/sort/GeoDistanceIT.java @@ -72,12 +72,11 @@ public void testDistanceSortingMVFields() throws Exception { Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("locations") .field("type", "geo_point"); - xContentBuilder.field("ignore_malformed", true).endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); + xContentBuilder.field("ignore_malformed", true).endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).setMapping(xContentBuilder)); ensureGreen(); client().prepareIndex("test") @@ -268,12 +267,11 @@ public void testDistanceSortingWithMissingGeoPoint() throws Exception { Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("locations") .field("type", "geo_point"); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").setSettings(settings).addMapping("type1", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test").setSettings(settings).setMapping(xContentBuilder)); ensureGreen(); client().prepareIndex("test") @@ -333,7 +331,6 @@ public void testDistanceSortingNestedFields() throws Exception { Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build(); XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("company") .startObject("properties") .startObject("name") .field("type", "text") @@ -346,9 +343,9 @@ public void testDistanceSortingNestedFields() throws Exception { .endObject() .startObject("location") .field("type", "geo_point"); - xContentBuilder.endObject().endObject().endObject().endObject().endObject().endObject(); + xContentBuilder.endObject().endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("companies").setSettings(settings).addMapping("company", xContentBuilder)); + assertAcked(prepareCreate("companies").setSettings(settings).setMapping(xContentBuilder)); ensureGreen(); indexRandom( @@ -590,15 +587,14 @@ public void testGeoDistanceFilter() throws IOException { XContentBuilder mapping = JsonXContent.contentBuilder() .startObject() - .startObject("location") .startObject("properties") .startObject("pin") .field("type", "geo_point"); - mapping.endObject().endObject().endObject().endObject(); + mapping.endObject().endObject().endObject(); XContentBuilder source = JsonXContent.contentBuilder().startObject().field("pin", Geohash.stringEncode(lon, lat)).endObject(); - assertAcked(prepareCreate("locations").setSettings(settings).addMapping("location", mapping)); + assertAcked(prepareCreate("locations").setSettings(settings).setMapping(mapping)); client().prepareIndex("locations").setId("1").setCreate(true).setSource(source).get(); refresh(); client().prepareGet("locations", "1").get(); @@ -614,12 +610,11 @@ public void testGeoDistanceFilter() throws IOException { public void testDistanceSortingWithUnmappedField() throws Exception { XContentBuilder xContentBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("locations") .field("type", "geo_point"); - xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test1").addMapping("type1", xContentBuilder)); + xContentBuilder.endObject().endObject().endObject(); + assertAcked(prepareCreate("test1").setMapping(xContentBuilder)); assertAcked(prepareCreate("test2")); ensureGreen(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/sort/SimpleSortIT.java b/server/src/internalClusterTest/java/org/opensearch/search/sort/SimpleSortIT.java index 70bb24532aa7d..8ff0790e7cb48 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/sort/SimpleSortIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/sort/SimpleSortIT.java @@ -134,10 +134,8 @@ static > T getMinValueScript( public void testSimpleSorts() throws Exception { Random random = random(); assertAcked( - prepareCreate("test").addMapping( - "type1", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("str_value") .field("type", "keyword") @@ -165,7 +163,6 @@ public void testSimpleSorts() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); @@ -446,17 +443,14 @@ public void testDocumentsWithNullValue() throws Exception { public void test2920() throws IOException { assertAcked( - prepareCreate("test").addMapping( - "test", + prepareCreate("test").setMapping( jsonBuilder().startObject() - .startObject("test") .startObject("properties") .startObject("value") .field("type", "keyword") .endObject() .endObject() .endObject() - .endObject() ) ); ensureGreen(); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/suggest/CompletionSuggestSearchIT.java b/server/src/internalClusterTest/java/org/opensearch/search/suggest/CompletionSuggestSearchIT.java index e85eff8450ca4..690564fe1cac8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/suggest/CompletionSuggestSearchIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/suggest/CompletionSuggestSearchIT.java @@ -682,15 +682,13 @@ public void testThatDisablingPositionIncrementsWorkForStopwords() throws Excepti public void testThatUpgradeToMultiFieldsWorks() throws Exception { final XContentBuilder mapping = jsonBuilder().startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject(FIELD) .field("type", "text") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate(INDEX).addMapping(MapperService.SINGLE_MAPPING_NAME, mapping)); + assertAcked(prepareCreate(INDEX).setMapping(mapping)); client().prepareIndex(INDEX) .setId("1") .setRefreshPolicy(IMMEDIATE) @@ -1328,7 +1326,7 @@ private void createIndexAndMappingAndSettings(Settings settings, CompletionMappi .indices() .prepareCreate(INDEX) .setSettings(Settings.builder().put(indexSettings()).put(settings)) - .addMapping(MapperService.SINGLE_MAPPING_NAME, mapping) + .setMapping(mapping) .get() ); } @@ -1376,17 +1374,14 @@ public void testVeryLongInput() throws IOException { client().admin() .indices() .prepareCreate(INDEX) - .addMapping( - MapperService.SINGLE_MAPPING_NAME, + .setMapping( jsonBuilder().startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject(FIELD) .field("type", "completion") .endObject() .endObject() .endObject() - .endObject() ) .get() ); @@ -1408,17 +1403,14 @@ public void testReservedChars() throws IOException { client().admin() .indices() .prepareCreate(INDEX) - .addMapping( - MapperService.SINGLE_MAPPING_NAME, + .setMapping( jsonBuilder().startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject(FIELD) .field("type", "completion") .endObject() .endObject() .endObject() - .endObject() ) .get() ); @@ -1449,17 +1441,14 @@ public void testIssue5930() throws IOException { client().admin() .indices() .prepareCreate(INDEX) - .addMapping( - MapperService.SINGLE_MAPPING_NAME, + .setMapping( jsonBuilder().startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject(FIELD) .field("type", "completion") .endObject() .endObject() .endObject() - .endObject() ) .get() ); @@ -1508,7 +1497,6 @@ public void testMultiDocSuggestions() throws Exception { public void testSuggestWithFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject(FIELD) .field("type", "completion") @@ -1518,9 +1506,8 @@ public void testSuggestWithFieldAlias() throws Exception { .field("path", FIELD) .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate(INDEX).addMapping(MapperService.SINGLE_MAPPING_NAME, mapping)); + assertAcked(prepareCreate(INDEX).setMapping(mapping)); List builders = new ArrayList<>(); builders.add(client().prepareIndex(INDEX).setSource(FIELD, "apple")); diff --git a/server/src/internalClusterTest/java/org/opensearch/search/suggest/ContextCompletionSuggestSearchIT.java b/server/src/internalClusterTest/java/org/opensearch/search/suggest/ContextCompletionSuggestSearchIT.java index acc4350d149cd..27d3d455330f5 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/suggest/ContextCompletionSuggestSearchIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/suggest/ContextCompletionSuggestSearchIT.java @@ -42,7 +42,6 @@ import org.opensearch.common.unit.Fuzziness; import org.opensearch.common.xcontent.ToXContent; import org.opensearch.common.xcontent.XContentBuilder; -import org.opensearch.index.mapper.MapperService; import org.opensearch.rest.RestStatus; import org.opensearch.search.suggest.CompletionSuggestSearchIT.CompletionMappingBuilder; import org.opensearch.search.suggest.completion.CompletionSuggestionBuilder; @@ -608,7 +607,7 @@ public void testGeoField() throws Exception { mapping.endObject(); mapping.endObject(); - assertAcked(prepareCreate(INDEX).addMapping(MapperService.SINGLE_MAPPING_NAME, mapping)); + assertAcked(prepareCreate(INDEX).setMapping(mapping)); XContentBuilder source1 = jsonBuilder().startObject() .startObject("location") @@ -754,7 +753,7 @@ private void createIndexAndMappingAndSettings(Settings settings, CompletionMappi .indices() .prepareCreate(INDEX) .setSettings(Settings.builder().put(indexSettings()).put(settings)) - .addMapping(MapperService.SINGLE_MAPPING_NAME, mapping) + .setMapping(mapping) .get() ); } diff --git a/server/src/internalClusterTest/java/org/opensearch/search/suggest/SuggestSearchIT.java b/server/src/internalClusterTest/java/org/opensearch/search/suggest/SuggestSearchIT.java index bb6e1643dd767..cd3921d91a3ed 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/suggest/SuggestSearchIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/suggest/SuggestSearchIT.java @@ -127,16 +127,14 @@ public void testSuggestAcrossMultipleIndices() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("text") .field("type", "text") .field("analyzer", "keyword") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test_2").addMapping("type1", mapping)); + assertAcked(prepareCreate("test_2").setMapping(mapping)); ensureGreen(); index("test_2", "type1", "1", "text", "ab cd"); @@ -217,7 +215,6 @@ public void testSuggestModes() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("name") .field("type", "text") @@ -230,9 +227,8 @@ public void testSuggestModes() throws IOException { .endObject() .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type1", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); index("test", "type1", "1", "name", "I like iced tea"); @@ -300,7 +296,6 @@ public void testUnmappedField() throws IOException, InterruptedException, Execut ); XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("name") .field("type", "text") @@ -313,9 +308,8 @@ public void testUnmappedField() throws IOException, InterruptedException, Execut .endObject() .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type1", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); indexRandom( @@ -558,7 +552,6 @@ public void testPrefixLength() throws IOException { ); XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("body") .field("type", "text") @@ -569,9 +562,8 @@ public void testPrefixLength() throws IOException { .field("analyzer", "bigram") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type1", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); index("test", "type1", "1", "body", "hello world"); @@ -614,7 +606,6 @@ public void testBasicPhraseSuggest() throws IOException, URISyntaxException { ); XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("body") .field("type", "text") @@ -625,9 +616,8 @@ public void testBasicPhraseSuggest() throws IOException, URISyntaxException { .field("analyzer", "bigram") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type1", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); String[] strings = new String[] { @@ -758,7 +748,6 @@ public void testSizeParam() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("body") .field("type", "text") @@ -769,9 +758,8 @@ public void testSizeParam() throws IOException { .field("analyzer", "bigram") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type1", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); String line = "xorr the god jewel"; @@ -833,16 +821,14 @@ public void testShardFailures() throws IOException, InterruptedException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type2") .startObject("properties") .startObject("name") .field("type", "text") .field("analyzer", "suggest") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type2", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); index("test", "type2", "1", "foo", "bar"); @@ -880,14 +866,12 @@ public void testShardFailures() throws IOException, InterruptedException { public void testEmptyShards() throws IOException, InterruptedException { XContentBuilder mappingBuilder = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("name") .field("type", "text") .field("analyzer", "suggest") .endObject() .endObject() - .endObject() .endObject(); assertAcked( prepareCreate("test").setSettings( @@ -901,7 +885,7 @@ public void testEmptyShards() throws IOException, InterruptedException { .put("index.analysis.filter.shingler.min_shingle_size", 2) .put("index.analysis.filter.shingler.max_shingle_size", 5) .put("index.analysis.filter.shingler.output_unigrams", true) - ).addMapping("type1", mappingBuilder) + ).setMapping(mappingBuilder) ); ensureGreen(); @@ -978,16 +962,14 @@ public void testSearchForRarePhrase() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("body") .field("type", "text") .field("analyzer", "body") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type1", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); NumShards test = getNumShards("test"); @@ -1039,16 +1021,14 @@ public void testSuggestWithManyCandidates() throws InterruptedException, Executi XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") .field("analyzer", "text") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type1", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); List titles = new ArrayList<>(); @@ -1166,7 +1146,6 @@ public void testSuggestWithManyCandidates() throws InterruptedException, Executi public void testSuggestWithFieldAlias() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("text") .field("type", "keyword") @@ -1176,9 +1155,8 @@ public void testSuggestWithFieldAlias() throws Exception { .field("path", "text") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(prepareCreate("test").addMapping("type", mapping)); + assertAcked(prepareCreate("test").setMapping(mapping)); List builders = new ArrayList<>(); builders.add(client().prepareIndex("test").setSource("text", "apple")); @@ -1195,17 +1173,13 @@ public void testSuggestWithFieldAlias() throws Exception { public void testPhraseSuggestMinDocFreq() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("text") .field("type", "keyword") .endObject() .endObject() - .endObject() .endObject(); - assertAcked( - prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 1).build()).addMapping("type", mapping) - ); + assertAcked(prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 1).build()).setMapping(mapping)); List builders = new ArrayList<>(); builders.add(client().prepareIndex("test").setSource("text", "apple")); @@ -1298,16 +1272,14 @@ public void testPhraseSuggesterCollate() throws InterruptedException, ExecutionE XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type1") .startObject("properties") .startObject("title") .field("type", "text") .field("analyzer", "text") .endObject() .endObject() - .endObject() .endObject(); - assertAcked(builder.addMapping("type1", mapping)); + assertAcked(builder.setMapping(mapping)); ensureGreen(); List titles = new ArrayList<>(); diff --git a/server/src/internalClusterTest/java/org/opensearch/similarity/SimilarityIT.java b/server/src/internalClusterTest/java/org/opensearch/similarity/SimilarityIT.java index 57c14876b25ff..929aac388b678 100644 --- a/server/src/internalClusterTest/java/org/opensearch/similarity/SimilarityIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/similarity/SimilarityIT.java @@ -53,10 +53,8 @@ public void testCustomBM25Similarity() throws Exception { client().admin() .indices() .prepareCreate("test") - .addMapping( - "type1", + .setMapping( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("field1") .field("similarity", "custom") @@ -68,7 +66,6 @@ public void testCustomBM25Similarity() throws Exception { .endObject() .endObject() .endObject() - .endObject() ) .setSettings( Settings.builder() 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 8b38308d39c93..b234561563e56 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 @@ -248,28 +248,33 @@ public CreateIndexRequest mapping(String mapping) { /** * Adds mapping that will be added when the index gets created. * - * @param type The mapping type * @param source The mapping source * @param xContentType the content type of the mapping source * @deprecated types are being removed */ @Deprecated - private CreateIndexRequest mapping(String type, BytesReference source, XContentType xContentType) { + private CreateIndexRequest mapping(BytesReference source, XContentType xContentType) { Objects.requireNonNull(xContentType); Map mappingAsMap = XContentHelper.convertToMap(source, false, xContentType).v2(); - return mapping(type, mappingAsMap); + return mapping(MapperService.SINGLE_MAPPING_NAME, mappingAsMap); } /** * Adds mapping that will be added when the index gets created. * - * @param type The mapping type * @param source The mapping source - * @deprecated types are being removed */ - @Deprecated - public CreateIndexRequest mapping(String type, XContentBuilder source) { - return mapping(type, BytesReference.bytes(source), source.contentType()); + public CreateIndexRequest mapping(XContentBuilder source) { + return mapping(BytesReference.bytes(source), source.contentType()); + } + + /** + * Set the mapping for this index + * + * @param source The mapping source + */ + public CreateIndexRequest mapping(Map source) { + return mapping(MapperService.SINGLE_MAPPING_NAME, source); } /** @@ -280,7 +285,7 @@ public CreateIndexRequest mapping(String type, XContentBuilder source) { * @deprecated types are being removed */ @Deprecated - public CreateIndexRequest mapping(String type, Map source) { + private CreateIndexRequest mapping(String type, Map source) { // wrap it in a type map if its not if (source.size() != 1 || !source.containsKey(type)) { source = Collections.singletonMap(MapperService.SINGLE_MAPPING_NAME, source); @@ -304,7 +309,7 @@ public CreateIndexRequest mapping(String type, Map source) { */ @Deprecated public CreateIndexRequest mapping(String type, Object... source) { - mapping(type, PutMappingRequest.buildFromSimplifiedDef(source)); + mapping(PutMappingRequest.buildFromSimplifiedDef(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 77e48d079cb5c..41f364517fd06 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 @@ -113,43 +113,28 @@ public CreateIndexRequestBuilder setSettings(Map source) { * * @param source The mapping source */ - @Deprecated public CreateIndexRequestBuilder setMapping(String source) { request.mapping(source); return this; } - /** - * The cause for this index creation. - */ - public CreateIndexRequestBuilder setCause(String cause) { - request.cause(cause); - return this; - } - /** * Adds mapping that will be added when the index gets created. * - * @param type The mapping type * @param source The mapping source - * @deprecated types are being removed */ - @Deprecated - public CreateIndexRequestBuilder addMapping(String type, XContentBuilder source) { - request.mapping(type, source); + public CreateIndexRequestBuilder setMapping(XContentBuilder source) { + request.mapping(source); return this; } /** * Adds mapping that will be added when the index gets created. * - * @param type The mapping type * @param source The mapping source - * @deprecated types are being removed */ - @Deprecated - public CreateIndexRequestBuilder addMapping(String type, Map source) { - request.mapping(type, source); + public CreateIndexRequestBuilder setMapping(Map source) { + request.mapping(source); return this; } @@ -164,6 +149,14 @@ public CreateIndexRequestBuilder addMapping(String type, Object... source) { return this; } + /** + * The cause for this index creation. + */ + public CreateIndexRequestBuilder setCause(String cause) { + request.cause(cause); + return this; + } + /** * Sets the aliases that will be associated with the index when it gets created */ diff --git a/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverRequest.java b/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverRequest.java index f06cb599a60df..402b3741205a2 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/rollover/RolloverRequest.java @@ -101,7 +101,7 @@ public class RolloverRequest extends AcknowledgedRequest implem if (MapperService.isMappingSourceTyped(MapperService.SINGLE_MAPPING_NAME, mappings)) { throw new IllegalArgumentException("The mapping definition cannot be nested under a type"); } - request.createIndexRequest.mapping(MapperService.SINGLE_MAPPING_NAME, mappings); + request.createIndexRequest.mapping(mappings); }, CreateIndexRequest.MAPPINGS, ObjectParser.ValueType.OBJECT); PARSER.declareField( (parser, request, context) -> request.createIndexRequest.aliases(parser.map()), diff --git a/server/src/test/java/org/opensearch/action/admin/indices/create/CreateIndexRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/create/CreateIndexRequestTests.java index 320db79428300..31039826868ac 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/create/CreateIndexRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/create/CreateIndexRequestTests.java @@ -116,10 +116,10 @@ public void testMappingKeyedByType() throws IOException { .endObject() .endObject() .endObject(); - request1.mapping("type1", builder); + request1.mapping(builder); builder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); builder.startObject() - .startObject("type1") + .startObject(MapperService.SINGLE_MAPPING_NAME) .startObject("properties") .startObject("field1") .field("type", "text") @@ -134,7 +134,7 @@ public void testMappingKeyedByType() throws IOException { .endObject() .endObject() .endObject(); - request2.mapping("type1", builder); + request2.mapping(builder); assertEquals(request1.mappings(), request2.mappings()); } } 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 fd6fc3b6839d7..ab401b7d45792 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 @@ -160,7 +160,7 @@ private static PutMappingRequest createTestItem() throws IOException { String index = randomAlphaOfLength(5); PutMappingRequest request = new PutMappingRequest(index); - request.source(RandomCreateIndexGenerator.randomMapping("_doc")); + request.source(RandomCreateIndexGenerator.randomMapping()); return request; } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java b/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java index 0fcc60e2a4087..079e5d388bbf4 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/rollover/RolloverRequestTests.java @@ -218,8 +218,7 @@ public void testValidation() { private static RolloverRequest createTestItem() throws IOException { RolloverRequest rolloverRequest = new RolloverRequest(); if (randomBoolean()) { - rolloverRequest.getCreateIndexRequest() - .mapping(MapperService.SINGLE_MAPPING_NAME, RandomCreateIndexGenerator.randomMapping(MapperService.SINGLE_MAPPING_NAME)); + rolloverRequest.getCreateIndexRequest().mapping(RandomCreateIndexGenerator.randomMapping()); } if (randomBoolean()) { RandomCreateIndexGenerator.randomAliases(rolloverRequest.getCreateIndexRequest()); diff --git a/server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsTests.java b/server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsTests.java index 6a84c5894fceb..171639083be58 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsTests.java @@ -67,7 +67,6 @@ public void testSegmentStats() throws Exception { IndexModule.Type storeType = IndexModule.defaultStoreType(true); XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("doc") .startObject("properties") .startObject("foo") .field("type", "keyword") @@ -82,13 +81,12 @@ public void testSegmentStats() throws Exception { .field("type", "long") .endObject() .endObject() - .endObject() .endObject(); assertAcked( client().admin() .indices() .prepareCreate("test") - .addMapping("doc", mapping) + .setMapping(mapping) .setSettings(Settings.builder().put("index.store.type", storeType.getSettingsKey())) ); ensureGreen("test"); diff --git a/server/src/test/java/org/opensearch/action/termvectors/AbstractTermVectorsTestCase.java b/server/src/test/java/org/opensearch/action/termvectors/AbstractTermVectorsTestCase.java index 78214334928a4..d9613176c0156 100644 --- a/server/src/test/java/org/opensearch/action/termvectors/AbstractTermVectorsTestCase.java +++ b/server/src/test/java/org/opensearch/action/termvectors/AbstractTermVectorsTestCase.java @@ -219,16 +219,16 @@ public String toString() { protected void createIndexBasedOnFieldSettings(String index, String alias, TestFieldSetting[] fieldSettings) throws IOException { XContentBuilder mappingBuilder = jsonBuilder(); - mappingBuilder.startObject().startObject("type1").startObject("properties"); + mappingBuilder.startObject().startObject("properties"); for (TestFieldSetting field : fieldSettings) { field.addToMappings(mappingBuilder); } - mappingBuilder.endObject().endObject().endObject(); + mappingBuilder.endObject().endObject(); Settings.Builder settings = Settings.builder() .put(indexSettings()) .put("index.analysis.analyzer.tv_test.tokenizer", "standard") .putList("index.analysis.analyzer.tv_test.filter", "lowercase"); - assertAcked(prepareCreate(index).addMapping("type1", mappingBuilder).setSettings(settings).addAlias(new Alias(alias))); + assertAcked(prepareCreate(index).setMapping(mappingBuilder).setSettings(settings).addAlias(new Alias(alias))); } /** diff --git a/server/src/test/java/org/opensearch/action/termvectors/GetTermVectorsTests.java b/server/src/test/java/org/opensearch/action/termvectors/GetTermVectorsTests.java index 5486d110c9329..1217efb883468 100644 --- a/server/src/test/java/org/opensearch/action/termvectors/GetTermVectorsTests.java +++ b/server/src/test/java/org/opensearch/action/termvectors/GetTermVectorsTests.java @@ -169,7 +169,6 @@ public void testRandomPayloadWithDelimitedPayloadTokenFilter() throws IOExceptio String queryString = createString(tokens, payloads, encoding, delimiter.charAt(0)); // create the mapping XContentBuilder mapping = jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("field") .field("type", "text") @@ -177,7 +176,6 @@ public void testRandomPayloadWithDelimitedPayloadTokenFilter() throws IOExceptio .field("analyzer", "payload_test") .endObject() .endObject() - .endObject() .endObject(); Settings setting = Settings.builder() .put("index.analysis.analyzer.payload_test.tokenizer", "mock-whitespace") diff --git a/server/src/test/java/org/opensearch/index/analysis/PreBuiltAnalyzerTests.java b/server/src/test/java/org/opensearch/index/analysis/PreBuiltAnalyzerTests.java index 9dfdbb4469956..d8e0a4ea3bc2e 100644 --- a/server/src/test/java/org/opensearch/index/analysis/PreBuiltAnalyzerTests.java +++ b/server/src/test/java/org/opensearch/index/analysis/PreBuiltAnalyzerTests.java @@ -114,14 +114,12 @@ public void testThatAnalyzersAreUsedInMapping() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field") .field("type", "text") .field("analyzer", analyzerName) .endObject() .endObject() - .endObject() .endObject(); MapperService mapperService = createIndex("test", indexSettings, "type", mapping).mapperService(); diff --git a/server/src/test/java/org/opensearch/index/mapper/FieldFilterMapperPluginTests.java b/server/src/test/java/org/opensearch/index/mapper/FieldFilterMapperPluginTests.java index c0900cc40abff..1e5a212c59825 100644 --- a/server/src/test/java/org/opensearch/index/mapper/FieldFilterMapperPluginTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/FieldFilterMapperPluginTests.java @@ -101,7 +101,7 @@ public void testGetFieldMappings() { // as the one coming from a filtered index with same mappings GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("filtered").get(); MappingMetadata filtered = getMappingsResponse.getMappings().get("filtered"); - assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filtered.getSourceAsMap())); + assertAcked(client().admin().indices().prepareCreate("test").setMapping(filtered.getSourceAsMap())); GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("test").setFields("*").get(); assertEquals(1, response.mappings().size()); assertFieldMappings(response.mappings().get("test"), FILTERED_FLAT_FIELDS); @@ -128,7 +128,7 @@ public void testFieldCapabilities() { // as the one coming from a filtered index with same mappings GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("filtered").get(); MappingMetadata filteredMapping = getMappingsResponse.getMappings().get("filtered"); - assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filteredMapping.getSourceAsMap())); + assertAcked(client().admin().indices().prepareCreate("test").setMapping(filteredMapping.getSourceAsMap())); FieldCapabilitiesResponse test = client().fieldCaps(new FieldCapabilitiesRequest().fields("*").indices("test")).actionGet(); // properties.value is an object field in the new mapping filteredFields.add("properties.value"); @@ -176,7 +176,7 @@ private void assertExpectedMappings(ImmutableOpenMap ma private void assertMappingsAreValid(Map sourceAsMap) { // check that the returned filtered mappings are still valid mappings by submitting them and retrieving them back - assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", sourceAsMap)); + assertAcked(client().admin().indices().prepareCreate("test").setMapping(sourceAsMap)); GetMappingsResponse testMappingsResponse = client().admin().indices().prepareGetMappings("test").get(); assertEquals(1, testMappingsResponse.getMappings().size()); // the mappings are returned unfiltered for this index, yet they are the same as the previous ones that were returned filtered diff --git a/server/src/test/java/org/opensearch/index/search/NestedHelperTests.java b/server/src/test/java/org/opensearch/index/search/NestedHelperTests.java index 9164dba8a3f62..c02df8168afee 100644 --- a/server/src/test/java/org/opensearch/index/search/NestedHelperTests.java +++ b/server/src/test/java/org/opensearch/index/search/NestedHelperTests.java @@ -66,7 +66,6 @@ public void setUp() throws Exception { super.setUp(); XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("foo") .field("type", "keyword") @@ -110,7 +109,6 @@ public void setUp() throws Exception { .endObject() .endObject() .endObject() - .endObject() .endObject(); indexService = createIndex("index", Settings.EMPTY, "type", mapping); mapperService = indexService.mapperService(); diff --git a/server/src/test/java/org/opensearch/index/similarity/SimilarityTests.java b/server/src/test/java/org/opensearch/index/similarity/SimilarityTests.java index 418b933558e63..625064820df44 100644 --- a/server/src/test/java/org/opensearch/index/similarity/SimilarityTests.java +++ b/server/src/test/java/org/opensearch/index/similarity/SimilarityTests.java @@ -100,14 +100,12 @@ public void testResolveSimilaritiesFromMapping_classicIsForbidden() throws IOExc public void testResolveSimilaritiesFromMapping_bm25() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "text") .field("similarity", "my_similarity") .endObject() .endObject() - .endObject() .endObject(); Settings indexSettings = Settings.builder() @@ -131,14 +129,12 @@ public void testResolveSimilaritiesFromMapping_bm25() throws IOException { public void testResolveSimilaritiesFromMapping_boolean() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "text") .field("similarity", "boolean") .endObject() .endObject() - .endObject() .endObject(); MapperService mapperService = createIndex("foo", Settings.EMPTY, "type", mapping).mapperService(); @@ -148,14 +144,12 @@ public void testResolveSimilaritiesFromMapping_boolean() throws IOException { public void testResolveSimilaritiesFromMapping_DFR() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "text") .field("similarity", "my_similarity") .endObject() .endObject() - .endObject() .endObject(); Settings indexSettings = Settings.builder() @@ -178,14 +172,12 @@ public void testResolveSimilaritiesFromMapping_DFR() throws IOException { public void testResolveSimilaritiesFromMapping_IB() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "text") .field("similarity", "my_similarity") .endObject() .endObject() - .endObject() .endObject(); Settings indexSettings = Settings.builder() @@ -208,14 +200,12 @@ public void testResolveSimilaritiesFromMapping_IB() throws IOException { public void testResolveSimilaritiesFromMapping_DFI() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "text") .field("similarity", "my_similarity") .endObject() .endObject() - .endObject() .endObject(); Settings indexSettings = Settings.builder() @@ -233,14 +223,12 @@ public void testResolveSimilaritiesFromMapping_DFI() throws IOException { public void testResolveSimilaritiesFromMapping_LMDirichlet() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "text") .field("similarity", "my_similarity") .endObject() .endObject() - .endObject() .endObject(); Settings indexSettings = Settings.builder() @@ -261,14 +249,12 @@ public void testResolveSimilaritiesFromMapping_LMDirichlet() throws IOException public void testResolveSimilaritiesFromMapping_LMJelinekMercer() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "text") .field("similarity", "my_similarity") .endObject() .endObject() - .endObject() .endObject(); Settings indexSettings = Settings.builder() @@ -292,7 +278,6 @@ public void testResolveSimilaritiesFromMapping_Unknown() throws IOException { String mapping = Strings.toString( XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("field1") .field("type", "text") @@ -300,7 +285,6 @@ public void testResolveSimilaritiesFromMapping_Unknown() throws IOException { .endObject() .endObject() .endObject() - .endObject() ); IndexService indexService = createIndex("foo"); diff --git a/server/src/test/java/org/opensearch/index/termvectors/TermVectorsServiceTests.java b/server/src/test/java/org/opensearch/index/termvectors/TermVectorsServiceTests.java index f35911c8a3553..60694c7d6d61a 100644 --- a/server/src/test/java/org/opensearch/index/termvectors/TermVectorsServiceTests.java +++ b/server/src/test/java/org/opensearch/index/termvectors/TermVectorsServiceTests.java @@ -60,14 +60,12 @@ public class TermVectorsServiceTests extends OpenSearchSingleNodeTestCase { public void testTook() throws Exception { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("field") .field("type", "text") .field("term_vector", "with_positions_offsets_payloads") .endObject() .endObject() - .endObject() .endObject(); createIndex("test", Settings.EMPTY, "type1", mapping); ensureGreen(); @@ -90,14 +88,12 @@ public void testTook() throws Exception { public void testDocFreqs() throws IOException { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("_doc") .startObject("properties") .startObject("text") .field("type", "text") .field("term_vector", "with_positions_offsets_payloads") .endObject() .endObject() - .endObject() .endObject(); Settings settings = Settings.builder().put("number_of_shards", 1).build(); createIndex("test", settings, "_doc", mapping); @@ -130,7 +126,6 @@ public void testDocFreqs() throws IOException { public void testWithIndexedPhrases() throws IOException { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("_doc") .startObject("properties") .startObject("text") .field("type", "text") @@ -138,7 +133,6 @@ public void testWithIndexedPhrases() throws IOException { .field("term_vector", "with_positions_offsets_payloads") .endObject() .endObject() - .endObject() .endObject(); Settings settings = Settings.builder().put("number_of_shards", 1).build(); createIndex("test", settings, "_doc", mapping); diff --git a/server/src/test/java/org/opensearch/search/geo/GeoPointShapeQueryTests.java b/server/src/test/java/org/opensearch/search/geo/GeoPointShapeQueryTests.java index a2171e6eabab3..3d4c82da0107e 100644 --- a/server/src/test/java/org/opensearch/search/geo/GeoPointShapeQueryTests.java +++ b/server/src/test/java/org/opensearch/search/geo/GeoPointShapeQueryTests.java @@ -89,7 +89,7 @@ protected XContentBuilder createDefaultMapping() throws Exception { public void testProcessRelationSupport() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); Rectangle rectangle = new Rectangle(-35, -25, -25, -35); @@ -112,7 +112,7 @@ public void testProcessRelationSupport() throws Exception { public void testQueryLine() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); Line line = new Line(new double[] { -25, -25 }, new double[] { -35, -35 }); @@ -126,7 +126,7 @@ public void testQueryLine() throws Exception { public void testQueryLinearRing() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); LinearRing linearRing = new LinearRing(new double[] { -25, -35, -25 }, new double[] { -25, -35, -25 }); @@ -148,7 +148,7 @@ public void testQueryLinearRing() throws Exception { public void testQueryMultiLine() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); CoordinatesBuilder coords1 = new CoordinatesBuilder().coordinate(-35, -35).coordinate(-25, -25); @@ -167,7 +167,7 @@ public void testQueryMultiLine() throws Exception { public void testQueryMultiPoint() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); MultiPointBuilder mpb = new MultiPointBuilder().coordinate(-35, -25).coordinate(-15, -5); @@ -182,7 +182,7 @@ public void testQueryMultiPoint() throws Exception { public void testQueryPoint() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); PointBuilder pb = new PointBuilder().coordinate(-35, -25); diff --git a/server/src/test/java/org/opensearch/search/geo/GeoQueryTests.java b/server/src/test/java/org/opensearch/search/geo/GeoQueryTests.java index b46ac4a72952b..dfaadaa8875ca 100644 --- a/server/src/test/java/org/opensearch/search/geo/GeoQueryTests.java +++ b/server/src/test/java/org/opensearch/search/geo/GeoQueryTests.java @@ -82,7 +82,7 @@ protected Collection> getPlugins() { public void testNullShape() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate(defaultIndexName).addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate(defaultIndexName).setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -96,7 +96,7 @@ public void testNullShape() throws Exception { public void testIndexPointsFilterRectangle() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate(defaultIndexName).addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate(defaultIndexName).setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -134,7 +134,7 @@ public void testIndexPointsFilterRectangle() throws Exception { public void testIndexPointsCircle() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate(defaultIndexName).addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate(defaultIndexName).setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -167,7 +167,7 @@ public void testIndexPointsCircle() throws Exception { public void testIndexPointsPolygon() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate(defaultIndexName).addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate(defaultIndexName).setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -203,7 +203,7 @@ public void testIndexPointsPolygon() throws Exception { public void testIndexPointsMultiPolygon() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate(defaultIndexName).addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate(defaultIndexName).setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -257,7 +257,7 @@ public void testIndexPointsMultiPolygon() throws Exception { public void testIndexPointsRectangle() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate(defaultIndexName).addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate(defaultIndexName).setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -285,7 +285,7 @@ public void testIndexPointsRectangle() throws Exception { public void testIndexPointsIndexedRectangle() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate(defaultIndexName).addMapping(defaultIndexName, xcb).get(); + client().admin().indices().prepareCreate(defaultIndexName).setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -310,7 +310,7 @@ public void testIndexPointsIndexedRectangle() throws Exception { .endObject() .endObject() .endObject(); - client().admin().indices().prepareCreate(indexedShapeIndex).addMapping(defaultIndexName, xcb).get(); + client().admin().indices().prepareCreate(indexedShapeIndex).setMapping(xcb).get(); ensureGreen(); client().prepareIndex(indexedShapeIndex) @@ -352,7 +352,7 @@ public void testIndexPointsIndexedRectangle() throws Exception { public void testRectangleSpanningDateline() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -385,7 +385,7 @@ public void testRectangleSpanningDateline() throws Exception { public void testPolygonSpanningDateline() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) @@ -429,7 +429,7 @@ public void testPolygonSpanningDateline() throws Exception { public void testMultiPolygonSpanningDateline() throws Exception { XContentBuilder xcb = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", xcb).get(); + client().admin().indices().prepareCreate("test").setMapping(xcb).get(); ensureGreen(); client().prepareIndex(defaultIndexName) diff --git a/server/src/test/java/org/opensearch/search/geo/GeoShapeQueryTests.java b/server/src/test/java/org/opensearch/search/geo/GeoShapeQueryTests.java index 61458512b84e4..4247a2ccabff2 100644 --- a/server/src/test/java/org/opensearch/search/geo/GeoShapeQueryTests.java +++ b/server/src/test/java/org/opensearch/search/geo/GeoShapeQueryTests.java @@ -262,7 +262,7 @@ public void testRandomGeoCollectionQuery() throws Exception { XContentBuilder mapping = createRandomMapping(); Settings settings = Settings.builder().put("index.number_of_shards", 1).build(); - client().admin().indices().prepareCreate("test").addMapping("_doc", mapping).setSettings(settings).get(); + client().admin().indices().prepareCreate("test").setMapping(mapping).setSettings(settings).get(); ensureGreen(); XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("geo"), null).endObject(); @@ -282,7 +282,7 @@ public void testRandomGeoCollectionQuery() throws Exception { // Test for issue #34418 public void testEnvelopeSpanningDateline() throws Exception { XContentBuilder mapping = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("_doc", mapping).get(); + client().admin().indices().prepareCreate("test").setMapping(mapping).get(); ensureGreen(); String doc1 = "{\"geo\": {\r\n" @@ -488,7 +488,7 @@ public void testEdgeCases() throws Exception { public void testIndexedShapeReferenceSourceDisabled() throws Exception { XContentBuilder mapping = createDefaultMapping(); - client().admin().indices().prepareCreate("test").addMapping("type1", mapping).get(); + client().admin().indices().prepareCreate("test").setMapping(mapping).get(); createIndex("shapes", Settings.EMPTY, "shape_type", "_source", "enabled=false"); ensureGreen(); @@ -612,7 +612,7 @@ public void testExistsQuery() throws Exception { GeometryCollectionBuilder gcb = RandomShapeGenerator.createGeometryCollection(random()); XContentBuilder builder = createRandomMapping(); - client().admin().indices().prepareCreate("test").addMapping("type", builder).execute().actionGet(); + client().admin().indices().prepareCreate("test").setMapping(builder).execute().actionGet(); XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("geo"), null).endObject(); client().prepareIndex("test").setId("1").setSource(docSource).setRefreshPolicy(IMMEDIATE).get(); @@ -748,7 +748,6 @@ public void testIndexedShapeReference() throws Exception { public void testFieldAlias() throws IOException { XContentBuilder mapping = XContentFactory.jsonBuilder() .startObject() - .startObject("type") .startObject("properties") .startObject("location") .field("type", "geo_shape") @@ -759,7 +758,6 @@ public void testFieldAlias() throws IOException { .field("path", "location") .endObject() .endObject() - .endObject() .endObject(); createIndex("test", Settings.EMPTY, "type", mapping); @@ -786,7 +784,7 @@ public void testQueryRandomGeoCollection() throws Exception { gcb.shape(new PolygonBuilder(cb)); XContentBuilder builder = createRandomMapping(); - client().admin().indices().prepareCreate("test").addMapping("type", builder).get(); + client().admin().indices().prepareCreate("test").setMapping(builder).get(); XContentBuilder docSource = gcb.toXContent(jsonBuilder().startObject().field("geo"), null).endObject(); client().prepareIndex("test").setId("1").setSource(docSource).setRefreshPolicy(IMMEDIATE).get(); diff --git a/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java b/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java index b2c54492b66d7..dc6cfdd281980 100644 --- a/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/completion/CategoryContextMappingTests.java @@ -77,7 +77,6 @@ public class CategoryContextMappingTests extends OpenSearchSingleNodeTestCase { public void testIndexingWithNoContexts() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -90,7 +89,6 @@ public void testIndexingWithNoContexts() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -129,7 +127,6 @@ public void testIndexingWithNoContexts() throws Exception { public void testIndexingWithSimpleContexts() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -142,7 +139,6 @@ public void testIndexingWithSimpleContexts() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -176,7 +172,6 @@ public void testIndexingWithSimpleContexts() throws Exception { public void testIndexingWithSimpleNumberContexts() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -189,7 +184,6 @@ public void testIndexingWithSimpleNumberContexts() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -223,7 +217,6 @@ public void testIndexingWithSimpleNumberContexts() throws Exception { public void testIndexingWithSimpleBooleanContexts() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -236,7 +229,6 @@ public void testIndexingWithSimpleBooleanContexts() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -270,7 +262,6 @@ public void testIndexingWithSimpleBooleanContexts() throws Exception { public void testIndexingWithSimpleNULLContexts() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -283,7 +274,6 @@ public void testIndexingWithSimpleNULLContexts() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -314,7 +304,6 @@ public void testIndexingWithSimpleNULLContexts() throws Exception { public void testIndexingWithContextList() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -327,7 +316,6 @@ public void testIndexingWithContextList() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -359,7 +347,6 @@ public void testIndexingWithContextList() throws Exception { public void testIndexingWithMixedTypeContextList() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -372,7 +359,6 @@ public void testIndexingWithMixedTypeContextList() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -404,7 +390,6 @@ public void testIndexingWithMixedTypeContextList() throws Exception { public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -417,7 +402,6 @@ public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -443,7 +427,6 @@ public void testIndexingWithMixedTypeContextListHavingNULL() throws Exception { public void testIndexingWithMultipleContexts() throws Exception { String mapping = Strings.toString( jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -460,7 +443,6 @@ public void testIndexingWithMultipleContexts() throws Exception { .endObject() .endObject() .endObject() - .endObject() ); DocumentMapper defaultMapper = createIndex("test").mapperService() @@ -798,7 +780,6 @@ public void testQueryContextParsingMixedHavingNULL() throws Exception { public void testUnknownQueryContextParsing() throws Exception { XContentBuilder mapping = jsonBuilder().startObject() - .startObject("type1") .startObject("properties") .startObject("completion") .field("type", "completion") @@ -814,7 +795,6 @@ public void testUnknownQueryContextParsing() throws Exception { .endArray() .endObject() .endObject() - .endObject() .endObject(); MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); diff --git a/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java b/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java index 31cc2e73ff2a3..1a1f3b33f0646 100644 --- a/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java +++ b/server/src/test/java/org/opensearch/search/suggest/completion/GeoContextMappingTests.java @@ -245,7 +245,6 @@ public void testIndexingWithMultipleContexts() throws Exception { public void testMalformedGeoField() throws Exception { XContentBuilder mapping = jsonBuilder(); mapping.startObject(); - mapping.startObject("type1"); mapping.startObject("properties"); mapping.startObject("pin"); String type = randomFrom("text", "keyword", "long"); @@ -266,7 +265,6 @@ public void testMalformedGeoField() throws Exception { mapping.endObject(); - mapping.endObject(); mapping.endObject(); mapping.endObject(); @@ -281,7 +279,6 @@ public void testMalformedGeoField() throws Exception { public void testMissingGeoField() throws Exception { XContentBuilder mapping = jsonBuilder(); mapping.startObject(); - mapping.startObject("type1"); mapping.startObject("properties"); mapping.startObject("suggestion"); mapping.field("type", "completion"); @@ -298,7 +295,6 @@ public void testMissingGeoField() throws Exception { mapping.endObject(); - mapping.endObject(); mapping.endObject(); mapping.endObject(); diff --git a/test/framework/src/main/java/org/opensearch/index/RandomCreateIndexGenerator.java b/test/framework/src/main/java/org/opensearch/index/RandomCreateIndexGenerator.java index dbcbb0f65a491..1498a0b7b2d17 100644 --- a/test/framework/src/main/java/org/opensearch/index/RandomCreateIndexGenerator.java +++ b/test/framework/src/main/java/org/opensearch/index/RandomCreateIndexGenerator.java @@ -63,8 +63,7 @@ public static CreateIndexRequest randomCreateIndexRequest() throws IOException { CreateIndexRequest request = new CreateIndexRequest(index); randomAliases(request); if (randomBoolean()) { - String type = randomAlphaOfLength(5); - request.mapping(type, randomMapping(type)); + request.mapping(randomMapping()); } if (randomBoolean()) { request.settings(randomIndexSettings()); @@ -94,16 +93,15 @@ public static Settings randomIndexSettings() { } /** - * Creates a random mapping, with the mapping definition nested - * under the given type name. + * Creates a random mapping */ - public static XContentBuilder randomMapping(String type) throws IOException { + public static XContentBuilder randomMapping() throws IOException { XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); - builder.startObject().startObject(type); + builder.startObject(); randomMappingFields(builder, true); - builder.endObject().endObject(); + builder.endObject(); return builder; } 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 83e59e1edd8c8..fb4831f881092 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchSingleNodeTestCase.java @@ -310,7 +310,7 @@ protected IndexService createIndex(String index, Settings settings) { protected IndexService createIndex(String index, Settings settings, String type, XContentBuilder mappings) { CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings); if (type != null && mappings != null) { - createIndexRequestBuilder.addMapping(type, mappings); + createIndexRequestBuilder.setMapping(mappings); } return createIndex(index, createIndexRequestBuilder); }