diff --git a/modules/analysis-common/src/test/java/org/opensearch/analysis/common/DisableGraphQueryTests.java b/modules/analysis-common/src/test/java/org/opensearch/analysis/common/DisableGraphQueryTests.java index 738c81c13cb6c..261c1bfafd2ba 100644 --- a/modules/analysis-common/src/test/java/org/opensearch/analysis/common/DisableGraphQueryTests.java +++ b/modules/analysis-common/src/test/java/org/opensearch/analysis/common/DisableGraphQueryTests.java @@ -93,10 +93,9 @@ public void setup() { .put("index.analysis.analyzer.text_shingle_unigram.tokenizer", "whitespace") .put("index.analysis.analyzer.text_shingle_unigram.filter", "lowercase, shingle_unigram") .build(); - indexService = createIndex( + indexService = createIndexWithSimpleMappings( "test", settings, - "t", "text_shingle", "type=text,analyzer=text_shingle", "text_shingle_unigram", diff --git a/modules/lang-painless/src/test/java/org/opensearch/painless/NeedsScoreTests.java b/modules/lang-painless/src/test/java/org/opensearch/painless/NeedsScoreTests.java index 9f87fbedb2a8f..f036968d96658 100644 --- a/modules/lang-painless/src/test/java/org/opensearch/painless/NeedsScoreTests.java +++ b/modules/lang-painless/src/test/java/org/opensearch/painless/NeedsScoreTests.java @@ -52,7 +52,7 @@ public class NeedsScoreTests extends OpenSearchSingleNodeTestCase { public void testNeedsScores() { - IndexService index = createIndex("test", Settings.EMPTY, "type", "d", "type=double"); + IndexService index = createIndexWithSimpleMappings("test", Settings.EMPTY, "d", "type=double"); Map, List> contexts = new HashMap<>(); contexts.put(NumberSortScript.CONTEXT, Allowlist.BASE_ALLOWLISTS); diff --git a/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteApiTests.java b/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteApiTests.java index d1ab998c314b0..ccc7fa1c99332 100644 --- a/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteApiTests.java +++ b/modules/lang-painless/src/test/java/org/opensearch/painless/action/PainlessExecuteApiTests.java @@ -89,7 +89,7 @@ public void testDefaults() throws IOException { public void testFilterExecutionContext() throws IOException { ScriptService scriptService = getInstanceFromNode(ScriptService.class); - IndexService indexService = createIndex("index", Settings.EMPTY, "doc", "field", "type=long"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "field", "type=long"); Request.ContextSetup contextSetup = new Request.ContextSetup("index", new BytesArray("{\"field\": 3}"), null); contextSetup.setXContentType(MediaTypeRegistry.JSON); @@ -120,7 +120,7 @@ public void testFilterExecutionContext() throws IOException { public void testScoreExecutionContext() throws IOException { ScriptService scriptService = getInstanceFromNode(ScriptService.class); - IndexService indexService = createIndex("index", Settings.EMPTY, "doc", "rank", "type=long", "text", "type=text"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "rank", "type=long", "text", "type=text"); Request.ContextSetup contextSetup = new Request.ContextSetup( "index", 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 97e80c66e3f4e..5f4925a4ae577 100644 --- a/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java +++ b/modules/percolator/src/test/java/org/opensearch/percolator/PercolatorQuerySearchTests.java @@ -281,7 +281,7 @@ public void testPercolateQueryWithNestedDocuments_doLeakFieldDataCacheEntries() public void testMapUnmappedFieldAsText() throws IOException { Settings.Builder settings = Settings.builder().put("index.percolator.map_unmapped_fields_as_text", true); - createIndex("test", settings.build(), "query", "query", "type=percolator"); + createIndexWithSimpleMappings("test", settings.build(), "query", "type=percolator"); client().prepareIndex("test") .setId("1") .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "value")).endObject()) @@ -302,10 +302,9 @@ public void testMapUnmappedFieldAsText() throws IOException { } public void testRangeQueriesWithNow() throws Exception { - IndexService indexService = createIndex( + IndexService indexService = createIndexWithSimpleMappings( "test", Settings.builder().put("index.number_of_shards", 1).build(), - "_doc", "field1", "type=keyword", "field2", diff --git a/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java b/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java index e7e8d92cee65a..49aab68be416b 100644 --- a/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java +++ b/plugins/mapper-size/src/internalClusterTest/java/org/opensearch/index/mapper/size/SizeMappingTests.java @@ -60,7 +60,7 @@ protected Collection> getPlugins() { } public void testSizeEnabled() throws Exception { - IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=true"); + IndexService service = createIndexWithSimpleMappings("test", Settings.EMPTY, "_size", "enabled=true"); DocumentMapper docMapper = service.mapperService().documentMapper(); BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); @@ -77,7 +77,7 @@ public void testSizeEnabled() throws Exception { } public void testSizeDisabled() throws Exception { - IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=false"); + IndexService service = createIndexWithSimpleMappings("test", Settings.EMPTY, "_size", "enabled=false"); DocumentMapper docMapper = service.mapperService().documentMapper(); BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); @@ -87,7 +87,7 @@ public void testSizeDisabled() throws Exception { } public void testSizeNotSet() throws Exception { - IndexService service = createIndex("test", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME); + IndexService service = createIndexWithSimpleMappings("test", Settings.EMPTY); DocumentMapper docMapper = service.mapperService().documentMapper(); BytesReference source = BytesReference.bytes(XContentFactory.jsonBuilder().startObject().field("field", "value").endObject()); @@ -97,7 +97,7 @@ public void testSizeNotSet() throws Exception { } public void testThatDisablingWorksWhenMerging() throws Exception { - IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=true"); + IndexService service = createIndexWithSimpleMappings("test", Settings.EMPTY, "_size", "enabled=true"); DocumentMapper docMapper = service.mapperService().documentMapper(); assertThat(docMapper.metadataMapper(SizeFieldMapper.class).enabled(), is(true)); diff --git a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java index 2ce50c8b5a768..8cd6fb7ed5aa6 100644 --- a/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/index/shard/IndexShardIT.java @@ -77,7 +77,6 @@ import org.opensearch.index.engine.MergedSegmentWarmerFactory; import org.opensearch.index.engine.NoOpEngine; import org.opensearch.index.flush.FlushStats; -import org.opensearch.index.mapper.MapperService; import org.opensearch.index.mapper.SourceToParse; import org.opensearch.index.seqno.RetentionLeaseSyncer; import org.opensearch.index.seqno.SequenceNumbers; @@ -477,7 +476,7 @@ public void testMaybeRollTranslogGeneration() throws Exception { .put("index.number_of_shards", 1) .put("index.translog.generation_threshold_size", generationThreshold + "b") .build(); - createIndex("test", settings, MapperService.SINGLE_MAPPING_NAME); + createIndexWithSimpleMappings("test", settings); ensureGreen("test"); final IndicesService indicesService = getInstanceFromNode(IndicesService.class); final IndexService test = indicesService.indexService(resolveIndex("test")); @@ -813,7 +812,7 @@ public void testShardChangesWithDefaultDocType() throws Exception { .put("index.translog.flush_threshold_size", "512mb") // do not flush .put("index.soft_deletes.enabled", true) .build(); - IndexService indexService = createIndex("index", settings, "user_doc", "title", "type=keyword"); + IndexService indexService = createIndexWithSimpleMappings("index", settings, "title", "type=keyword"); int numOps = between(1, 10); for (int i = 0; i < numOps; i++) { if (randomBoolean()) { diff --git a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java index b8d1d3cad77b4..c6ca4d36a86d7 100644 --- a/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/search/aggregations/FiltersAggsRewriteIT.java @@ -51,7 +51,7 @@ public class FiltersAggsRewriteIT extends OpenSearchSingleNodeTestCase { public void testWrapperQueryIsRewritten() throws IOException { - createIndex("test", Settings.EMPTY, "test", "title", "type=text"); + createIndexWithSimpleMappings("test", Settings.EMPTY, "title", "type=text"); client().prepareIndex("test").setId("1").setSource("title", "foo bar baz").get(); client().prepareIndex("test").setId("2").setSource("title", "foo foo foo").get(); client().prepareIndex("test").setId("3").setSource("title", "bar baz bax").get(); 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 7dd73966bb079..88ecd0f94e1a2 100644 --- a/server/src/test/java/org/opensearch/action/termvectors/GetTermVectorsTests.java +++ b/server/src/test/java/org/opensearch/action/termvectors/GetTermVectorsTests.java @@ -184,7 +184,7 @@ public void testRandomPayloadWithDelimitedPayloadTokenFilter() throws IOExceptio .put("index.analysis.filter.my_delimited_payload.encoding", encodingString) .put("index.analysis.filter.my_delimited_payload.type", "mock_payload_filter") .build(); - createIndex("test", setting, "type1", mapping); + createIndex("test", setting, mapping); client().prepareIndex("test") .setId(Integer.toString(1)) 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 6f9a662caff46..d8fb8603484b6 100644 --- a/server/src/test/java/org/opensearch/index/analysis/PreBuiltAnalyzerTests.java +++ b/server/src/test/java/org/opensearch/index/analysis/PreBuiltAnalyzerTests.java @@ -127,7 +127,7 @@ public void testThatAnalyzersAreUsedInMapping() throws IOException { .endObject() .endObject() .endObject(); - MapperService mapperService = createIndex("test", indexSettings, "type", mapping).mapperService(); + MapperService mapperService = createIndex("test", indexSettings, mapping).mapperService(); MappedFieldType fieldType = mapperService.fieldType("field"); assertThat(fieldType.getTextSearchInfo().getSearchAnalyzer(), instanceOf(NamedAnalyzer.class)); diff --git a/server/src/test/java/org/opensearch/index/mapper/ConstantKeywordFieldMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/ConstantKeywordFieldMapperTests.java index ec670ec969bad..9fcadcfb36b69 100644 --- a/server/src/test/java/org/opensearch/index/mapper/ConstantKeywordFieldMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/ConstantKeywordFieldMapperTests.java @@ -156,7 +156,7 @@ public void testDerivedValueFetching() throws IOException { } private ConstantKeywordFieldMapper getMapper(FieldMapper.CopyTo copyTo) { - indexService = createIndex("test-index", Settings.EMPTY, "constant_keyword", "field", "type=constant_keyword,value=default_value"); + indexService = createIndexWithSimpleMappings("test-index", Settings.EMPTY, "field", "type=constant_keyword,value=default_value"); ConstantKeywordFieldMapper mapper = (ConstantKeywordFieldMapper) indexService.mapperService() .documentMapper() .mappers() diff --git a/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java b/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java index bc0fa4e96d011..24f9f7c78372c 100644 --- a/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java @@ -235,10 +235,10 @@ public void testIndexSortWithNestedFieldsWithOlderVersion() throws IOException { Settings settings = settings(Version.V_3_0_0).put("index.sort.field", "foo").build(); IllegalArgumentException invalidNestedException = expectThrows( IllegalArgumentException.class, - () -> createIndex("test", settings, "t", "nested_field", "type=nested", "foo", "type=keyword") + () -> createIndexWithSimpleMappings("test", settings, "nested_field", "type=nested", "foo", "type=keyword") ); assertThat(invalidNestedException.getMessage(), containsString("cannot have nested fields when index sort is activated")); - IndexService indexService = createIndex("test", settings, "t", "foo", "type=keyword"); + IndexService indexService = createIndexWithSimpleMappings("test", settings, "foo", "type=keyword"); CompressedXContent nestedFieldMapping = new CompressedXContent( BytesReference.bytes( XContentFactory.jsonBuilder() diff --git a/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java b/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java index 9a0d34c916f5c..cf668178b3df0 100644 --- a/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/NestedObjectMapperTests.java @@ -881,7 +881,6 @@ public void testParentObjectMapperAreNested() throws Exception { MapperService mapperService = createIndex( "index1", Settings.EMPTY, - "_doc", jsonBuilder().startObject() .startObject("properties") .startObject("comments") @@ -901,7 +900,6 @@ public void testParentObjectMapperAreNested() throws Exception { mapperService = createIndex( "index2", Settings.EMPTY, - "_doc", jsonBuilder().startObject() .startObject("properties") .startObject("comments") @@ -1107,7 +1105,6 @@ public void testMergeNestedMappings() throws IOException { MapperService mapperService = createIndex( "index1", Settings.EMPTY, - MapperService.SINGLE_MAPPING_NAME, jsonBuilder().startObject() .startObject("properties") .startObject("nested1") diff --git a/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java b/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java index 7e40354eb7f29..b5d6922a12fcc 100644 --- a/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java +++ b/server/src/test/java/org/opensearch/index/mapper/UpdateMappingTests.java @@ -83,7 +83,7 @@ public void testConflictFieldsMapping(String fieldName) throws Exception { } protected void testConflictWhileMergingAndMappingUnchanged(XContentBuilder mapping, XContentBuilder mappingUpdate) throws IOException { - IndexService indexService = createIndex("test", Settings.builder().build(), MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("test", Settings.builder().build(), mapping); CompressedXContent mappingBeforeUpdate = indexService.mapperService().documentMapper().mappingSource(); // simulate like in MetadataMappingService#putMapping try { @@ -111,8 +111,7 @@ public void testConflictSameType() throws Exception { .endObject() .endObject() .endObject(); - MapperService mapperService = createIndex("test", Settings.builder().build(), MapperService.SINGLE_MAPPING_NAME, mapping) - .mapperService(); + MapperService mapperService = createIndex("test", Settings.builder().build(), mapping).mapperService(); XContentBuilder update = XContentFactory.jsonBuilder() .startObject() @@ -158,8 +157,7 @@ public void testConflictNewType() throws Exception { .endObject() .endObject() .endObject(); - MapperService mapperService = createIndex("test", Settings.builder().build(), MapperService.SINGLE_MAPPING_NAME, mapping) - .mapperService(); + MapperService mapperService = createIndex("test", Settings.builder().build(), mapping).mapperService(); XContentBuilder update = XContentFactory.jsonBuilder() .startObject() 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 cc77a19755f5d..5d8469241831b 100644 --- a/server/src/test/java/org/opensearch/index/search/NestedHelperTests.java +++ b/server/src/test/java/org/opensearch/index/search/NestedHelperTests.java @@ -117,7 +117,7 @@ public void setUp() throws Exception { .endObject() .endObject() .endObject(); - indexService = createIndex("index", Settings.EMPTY, "type", mapping); + indexService = createIndex("index", Settings.EMPTY, mapping); mapperService = indexService.mapperService(); } diff --git a/server/src/test/java/org/opensearch/index/search/nested/NestedSortingTests.java b/server/src/test/java/org/opensearch/index/search/nested/NestedSortingTests.java index f50dcfde112f2..b66fcf55b5e4d 100644 --- a/server/src/test/java/org/opensearch/index/search/nested/NestedSortingTests.java +++ b/server/src/test/java/org/opensearch/index/search/nested/NestedSortingTests.java @@ -466,7 +466,7 @@ public void testMultiLevelNestedSorting() throws IOException { mapping.endObject(); } mapping.endObject(); - IndexService indexService = createIndex("nested_sorting", Settings.EMPTY, "_doc", mapping); + IndexService indexService = createIndex("nested_sorting", Settings.EMPTY, mapping); List> books = new ArrayList<>(); { 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 1fafa4739b8b4..ccaeeef190684 100644 --- a/server/src/test/java/org/opensearch/index/similarity/SimilarityTests.java +++ b/server/src/test/java/org/opensearch/index/similarity/SimilarityTests.java @@ -102,7 +102,7 @@ public void testResolveLegacySimilarity() throws IOException { .endObject() .endObject(); - MapperService mapperService = createIndex("foo", settings, "type", mapping).mapperService(); + MapperService mapperService = createIndex("foo", settings, mapping).mapperService(); assertThat(mapperService.fieldType("dummy").getTextSearchInfo().getSimilarity().get(), instanceOf(LegacyBM25Similarity.class)); } @@ -136,7 +136,7 @@ public void testResolveSimilaritiesFromMapping_bm25() throws IOException { .put("index.similarity.my_similarity.b", 0.5f) .put("index.similarity.my_similarity.discount_overlaps", false) .build(); - MapperService mapperService = createIndex("foo", indexSettings, "type", mapping).mapperService(); + MapperService mapperService = createIndex("foo", indexSettings, mapping).mapperService(); assertThat(mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(), instanceOf(BM25Similarity.class)); BM25Similarity similarity = (BM25Similarity) mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(); @@ -156,7 +156,7 @@ public void testResolveSimilaritiesFromMapping_boolean() throws IOException { .endObject() .endObject(); - MapperService mapperService = createIndex("foo", Settings.EMPTY, "type", mapping).mapperService(); + MapperService mapperService = createIndex("foo", Settings.EMPTY, mapping).mapperService(); assertThat(mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(), instanceOf(BooleanSimilarity.class)); } @@ -178,7 +178,7 @@ public void testResolveSimilaritiesFromMapping_DFR() throws IOException { .put("index.similarity.my_similarity.normalization", "h2") .put("index.similarity.my_similarity.normalization.h2.c", 3f) .build(); - MapperService mapperService = createIndex("foo", indexSettings, "type", mapping).mapperService(); + MapperService mapperService = createIndex("foo", indexSettings, mapping).mapperService(); assertThat(mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(), instanceOf(DFRSimilarity.class)); DFRSimilarity similarity = (DFRSimilarity) mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(); @@ -206,7 +206,7 @@ public void testResolveSimilaritiesFromMapping_IB() throws IOException { .put("index.similarity.my_similarity.normalization", "h2") .put("index.similarity.my_similarity.normalization.h2.c", 3f) .build(); - MapperService mapperService = createIndex("foo", indexSettings, "type", mapping).mapperService(); + MapperService mapperService = createIndex("foo", indexSettings, mapping).mapperService(); assertThat(mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(), instanceOf(IBSimilarity.class)); IBSimilarity similarity = (IBSimilarity) mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(); @@ -231,7 +231,7 @@ public void testResolveSimilaritiesFromMapping_DFI() throws IOException { .put("index.similarity.my_similarity.type", "DFI") .put("index.similarity.my_similarity.independence_measure", "chisquared") .build(); - MapperService mapperService = createIndex("foo", indexSettings, "type", mapping).mapperService(); + MapperService mapperService = createIndex("foo", indexSettings, mapping).mapperService(); MappedFieldType fieldType = mapperService.fieldType("field1"); assertThat(fieldType.getTextSearchInfo().getSimilarity().get(), instanceOf(DFISimilarity.class)); @@ -255,7 +255,7 @@ public void testResolveSimilaritiesFromMapping_LMDirichlet() throws IOException .put("index.similarity.my_similarity.mu", 3000f) .build(); - MapperService mapperService = createIndex("foo", indexSettings, "type", mapping).mapperService(); + MapperService mapperService = createIndex("foo", indexSettings, mapping).mapperService(); assertThat(mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(), instanceOf(LMDirichletSimilarity.class)); LMDirichletSimilarity similarity = (LMDirichletSimilarity) mapperService.fieldType("field1") @@ -280,7 +280,7 @@ public void testResolveSimilaritiesFromMapping_LMJelinekMercer() throws IOExcept .put("index.similarity.my_similarity.type", "LMJelinekMercer") .put("index.similarity.my_similarity.lambda", 0.7f) .build(); - MapperService mapperService = createIndex("foo", indexSettings, "type", mapping).mapperService(); + MapperService mapperService = createIndex("foo", indexSettings, mapping).mapperService(); assertThat( mapperService.fieldType("field1").getTextSearchInfo().getSimilarity().get(), instanceOf(LMJelinekMercerSimilarity.class) 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 37b672dc064c4..f6f50d6cdf2a2 100644 --- a/server/src/test/java/org/opensearch/index/termvectors/TermVectorsServiceTests.java +++ b/server/src/test/java/org/opensearch/index/termvectors/TermVectorsServiceTests.java @@ -67,7 +67,7 @@ public void testTook() throws Exception { .endObject() .endObject() .endObject(); - createIndex("test", Settings.EMPTY, "type1", mapping); + createIndex("test", Settings.EMPTY, mapping); ensureGreen(); client().prepareIndex("test").setId("0").setSource("field", "foo bar").setRefreshPolicy(IMMEDIATE).get(); @@ -96,7 +96,7 @@ public void testDocFreqs() throws IOException { .endObject() .endObject(); Settings settings = Settings.builder().put("number_of_shards", 1).build(); - createIndex("test", settings, "_doc", mapping); + createIndex("test", settings, mapping); ensureGreen(); int max = between(3, 10); @@ -135,7 +135,7 @@ public void testWithIndexedPhrases() throws IOException { .endObject() .endObject(); Settings settings = Settings.builder().put("number_of_shards", 1).build(); - createIndex("test", settings, "_doc", mapping); + createIndex("test", settings, mapping); ensureGreen(); int max = between(3, 10); diff --git a/server/src/test/java/org/opensearch/search/aggregations/AggregatorBaseTests.java b/server/src/test/java/org/opensearch/search/aggregations/AggregatorBaseTests.java index ce96623ea06df..34c1f5ab7f218 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/AggregatorBaseTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/AggregatorBaseTests.java @@ -144,7 +144,7 @@ private ValuesSourceConfig getVSConfig( } public void testShortcutIsApplicable() throws IOException { - IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bytes", "type=keyword"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "bytes", "type=keyword"); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { QueryShardContext context = indexService.newQueryShardContext(0, searcher, () -> 42L, null); diff --git a/server/src/test/java/org/opensearch/search/aggregations/support/ValuesSourceConfigTests.java b/server/src/test/java/org/opensearch/search/aggregations/support/ValuesSourceConfigTests.java index 568c3c950f588..bcd35d6418652 100644 --- a/server/src/test/java/org/opensearch/search/aggregations/support/ValuesSourceConfigTests.java +++ b/server/src/test/java/org/opensearch/search/aggregations/support/ValuesSourceConfigTests.java @@ -42,7 +42,6 @@ import org.opensearch.index.IndexService; import org.opensearch.index.engine.Engine; import org.opensearch.index.fielddata.SortedBinaryDocValues; -import org.opensearch.index.mapper.MapperService; import org.opensearch.index.query.QueryShardContext; import org.opensearch.test.OpenSearchSingleNodeTestCase; @@ -50,7 +49,7 @@ public class ValuesSourceConfigTests extends OpenSearchSingleNodeTestCase { public void testKeyword() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bytes", "type=keyword"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "bytes", "type=keyword"); client().prepareIndex("index").setId("1").setSource("bytes", "abc").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -76,7 +75,7 @@ public void testKeyword() throws Exception { } public void testEmptyKeyword() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bytes", "type=keyword"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "bytes", "type=keyword"); client().prepareIndex("index").setId("1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -107,7 +106,7 @@ public void testEmptyKeyword() throws Exception { } public void testUnmappedKeyword() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type"); + IndexService indexService = createIndex("index", Settings.EMPTY); client().prepareIndex("index").setId("1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -137,7 +136,7 @@ public void testUnmappedKeyword() throws Exception { } public void testLong() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type", "long", "type=long"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "long", "type=long"); client().prepareIndex("index").setId("1").setSource("long", 42).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -163,7 +162,7 @@ public void testLong() throws Exception { } public void testEmptyLong() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type", "long", "type=long"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "long", "type=long"); client().prepareIndex("index").setId("1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -194,7 +193,7 @@ public void testEmptyLong() throws Exception { } public void testUnmappedLong() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type"); + IndexService indexService = createIndex("index", Settings.EMPTY); client().prepareIndex("index").setId("1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -225,7 +224,7 @@ public void testUnmappedLong() throws Exception { } public void testBoolean() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bool", "type=boolean"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "bool", "type=boolean"); client().prepareIndex("index").setId("1").setSource("bool", true).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -251,7 +250,7 @@ public void testBoolean() throws Exception { } public void testEmptyBoolean() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type", "bool", "type=boolean"); + IndexService indexService = createIndexWithSimpleMappings("index", Settings.EMPTY, "bool", "type=boolean"); client().prepareIndex("index").setId("1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -282,7 +281,7 @@ public void testEmptyBoolean() throws Exception { } public void testUnmappedBoolean() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type"); + IndexService indexService = createIndex("index", Settings.EMPTY); client().prepareIndex("index").setId("1").setSource().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -313,7 +312,14 @@ public void testUnmappedBoolean() throws Exception { } public void testFieldAlias() throws Exception { - IndexService indexService = createIndex("index", Settings.EMPTY, "type", "field", "type=keyword", "alias", "type=alias,path=field"); + IndexService indexService = createIndexWithSimpleMappings( + "index", + Settings.EMPTY, + "field", + "type=keyword", + "alias", + "type=alias,path=field" + ); client().prepareIndex("index").setId("1").setSource("field", "value").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { @@ -354,7 +360,7 @@ public void testDerivedField() throws Exception { .endObject() .endObject() .endObject(); - IndexService indexService = createIndex("index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("index", Settings.EMPTY, mapping); client().prepareIndex("index").setId("1").setSource("field", "value").setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get(); try (Engine.Searcher searcher = indexService.getShard(0).acquireSearcher("test")) { diff --git a/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java b/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java index 1c8a93f6483ae..a738b386f277e 100644 --- a/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java +++ b/server/src/test/java/org/opensearch/search/fetch/subphase/FieldFetcherTests.java @@ -277,7 +277,7 @@ public void testIgnoreAbove() throws IOException { .endObject() .endObject(); - IndexService indexService = createIndex("index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("index", Settings.EMPTY, mapping); MapperService mapperService = indexService.mapperService(); XContentBuilder source = XContentFactory.jsonBuilder() @@ -307,7 +307,7 @@ public void testFieldAliases() throws IOException { .endObject() .endObject(); - IndexService indexService = createIndex("index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("index", Settings.EMPTY, mapping); MapperService mapperService = indexService.mapperService(); XContentBuilder source = XContentFactory.jsonBuilder().startObject().field("field", "value").endObject(); @@ -341,7 +341,7 @@ public void testMultiFields() throws IOException { .endObject() .endObject(); - IndexService indexService = createIndex("index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("index", Settings.EMPTY, mapping); MapperService mapperService = indexService.mapperService(); XContentBuilder source = XContentFactory.jsonBuilder().startObject().field("field", 42).endObject(); @@ -374,7 +374,7 @@ public void testCopyTo() throws IOException { .endObject() .endObject(); - IndexService indexService = createIndex("index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("index", Settings.EMPTY, mapping); MapperService mapperService = indexService.mapperService(); XContentBuilder source = XContentFactory.jsonBuilder() @@ -420,7 +420,7 @@ public void testTextSubFields() throws IOException { .endObject() .endObject(); - IndexService indexService = createIndex("index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("index", Settings.EMPTY, mapping); MapperService mapperService = indexService.mapperService(); XContentBuilder source = XContentFactory.jsonBuilder().startObject().array("field", "some text").endObject(); @@ -484,7 +484,7 @@ public MapperService createMapperService() throws IOException { .endObject() .endObject(); - IndexService indexService = createIndex("index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("index", Settings.EMPTY, mapping); return indexService.mapperService(); } diff --git a/server/src/test/java/org/opensearch/search/fetch/subphase/highlight/DerivedFieldFetchAndHighlightTests.java b/server/src/test/java/org/opensearch/search/fetch/subphase/highlight/DerivedFieldFetchAndHighlightTests.java index f106aaa13dc48..409f123d6e108 100644 --- a/server/src/test/java/org/opensearch/search/fetch/subphase/highlight/DerivedFieldFetchAndHighlightTests.java +++ b/server/src/test/java/org/opensearch/search/fetch/subphase/highlight/DerivedFieldFetchAndHighlightTests.java @@ -124,7 +124,7 @@ public void testDerivedFieldFromIndexMapping() throws IOException { .endObject(); int docId = 0; - IndexService indexService = createIndex("test_index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("test_index", Settings.EMPTY, mapping); MapperService mapperService = indexService.mapperService(); try ( @@ -260,7 +260,7 @@ public void testDerivedFieldFromSearchMapping() throws IOException { // Create index and mapper service // We are not defining derived fields in index mapping here XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().endObject(); - IndexService indexService = createIndex("test_index", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping); + IndexService indexService = createIndex("test_index", Settings.EMPTY, mapping); MapperService mapperService = indexService.mapperService(); try ( 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 4f78d9166b414..3fb6fef08452f 100644 --- a/server/src/test/java/org/opensearch/search/geo/GeoShapeQueryTests.java +++ b/server/src/test/java/org/opensearch/search/geo/GeoShapeQueryTests.java @@ -365,7 +365,7 @@ public void testEnvelopeSpanningDateline() throws Exception { public void testGeometryCollectionRelations() throws Exception { XContentBuilder mapping = createDefaultMapping(); - createIndex("test", Settings.builder().put("index.number_of_shards", 1).build(), "doc", mapping); + createIndex("test", Settings.builder().put("index.number_of_shards", 1).build(), mapping); EnvelopeBuilder envelopeBuilder = new EnvelopeBuilder(new Coordinate(-10, 10), new Coordinate(10, -10)); @@ -490,7 +490,7 @@ public void testEdgeCases() throws Exception { public void testIndexedShapeReferenceSourceDisabled() throws Exception { XContentBuilder mapping = createDefaultMapping(); client().admin().indices().prepareCreate("test").setMapping(mapping).get(); - createIndex("shapes", Settings.EMPTY, "shape_type", "_source", "enabled=false"); + createIndexWithSimpleMappings("shapes", Settings.EMPTY, "_source", "enabled=false"); ensureGreen(); EnvelopeBuilder shape = new EnvelopeBuilder(new Coordinate(-45, 45), new Coordinate(45, -45)); @@ -749,7 +749,7 @@ public void testFieldAlias() throws IOException { .endObject() .endObject(); - createIndex("test", Settings.EMPTY, "type", mapping); + createIndex("test", Settings.EMPTY, mapping); ShapeBuilder shape = RandomShapeGenerator.createShape(random(), RandomShapeGenerator.ShapeType.MULTIPOINT); client().prepareIndex("test") 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 09a66a2cfcd91..57be372b81359 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 @@ -787,7 +787,7 @@ public void testUnknownQueryContextParsing() throws Exception { .endObject() .endObject(); - MapperService mapperService = createIndex("test", Settings.EMPTY, "type1", mapping).mapperService(); + MapperService mapperService = createIndex("test", Settings.EMPTY, mapping).mapperService(); CompletionFieldType completionFieldType = (CompletionFieldType) mapperService.fieldType("completion"); Exception e = expectThrows(IllegalArgumentException.class, () -> completionFieldType.getContextMappings().get("brand")); 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 07f3526dd2bb0..88898fb8cf963 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 @@ -77,7 +77,7 @@ public void testIndexingWithNoContexts() throws Exception { .endObject() .endObject(); - MapperService mapperService = createIndex("test", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping).mapperService(); + MapperService mapperService = createIndex("test", Settings.EMPTY, mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fieldType("completion"); ParsedDocument parsedDocument = mapperService.documentMapper() .parse( @@ -124,7 +124,7 @@ public void testIndexingWithSimpleContexts() throws Exception { .endObject() .endObject(); - MapperService mapperService = createIndex("test", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping).mapperService(); + MapperService mapperService = createIndex("test", Settings.EMPTY, mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fieldType("completion"); ParsedDocument parsedDocument = mapperService.documentMapper() .parse( @@ -169,7 +169,7 @@ public void testIndexingWithContextList() throws Exception { .endObject() .endObject(); - MapperService mapperService = createIndex("test", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping).mapperService(); + MapperService mapperService = createIndex("test", Settings.EMPTY, mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fieldType("completion"); ParsedDocument parsedDocument = mapperService.documentMapper() .parse( @@ -222,7 +222,7 @@ public void testIndexingWithMultipleContexts() throws Exception { .endObject() .endObject(); - MapperService mapperService = createIndex("test", Settings.EMPTY, MapperService.SINGLE_MAPPING_NAME, mapping).mapperService(); + MapperService mapperService = createIndex("test", Settings.EMPTY, mapping).mapperService(); MappedFieldType completionFieldType = mapperService.fieldType("completion"); XContentBuilder builder = jsonBuilder().startObject() .startArray("completion") @@ -268,10 +268,7 @@ public void testMalformedGeoField() throws Exception { mapping.endObject(); mapping.endObject(); - OpenSearchParseException ex = expectThrows( - OpenSearchParseException.class, - () -> createIndex("test", Settings.EMPTY, "type1", mapping) - ); + OpenSearchParseException ex = expectThrows(OpenSearchParseException.class, () -> createIndex("test", Settings.EMPTY, mapping)); assertThat(ex.getMessage(), equalTo("field [pin] referenced in context [st] must be mapped to geo_point, found [" + type + "]")); } @@ -298,10 +295,7 @@ public void testMissingGeoField() throws Exception { mapping.endObject(); mapping.endObject(); - OpenSearchParseException ex = expectThrows( - OpenSearchParseException.class, - () -> createIndex("test", Settings.EMPTY, "type1", mapping) - ); + OpenSearchParseException ex = expectThrows(OpenSearchParseException.class, () -> createIndex("test", Settings.EMPTY, mapping)); assertThat(ex.getMessage(), equalTo("field [pin] referenced in context [st] is not defined in the mapping")); } 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 1d84eeca9c6c2..48a5184349658 100644 --- a/test/framework/src/main/java/org/opensearch/test/OpenSearchSingleNodeTestCase.java +++ b/test/framework/src/main/java/org/opensearch/test/OpenSearchSingleNodeTestCase.java @@ -339,17 +339,15 @@ protected IndexService createIndex(String index) { * Create a new index on the singleton node with the provided index settings. */ protected IndexService createIndex(String index, Settings settings) { - return createIndex(index, settings, null, (XContentBuilder) null); + return createIndex(index, settings, null); } /** - * Create a new index on the singleton node with the provided index settings. - * @deprecated types are being removed + * Create a new index on the singleton node with the provided index settings and mappings. */ - @Deprecated - protected IndexService createIndex(String index, Settings settings, String type, XContentBuilder mappings) { + protected IndexService createIndex(String index, Settings settings, XContentBuilder mappings) { CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings); - if (type != null && mappings != null) { + if (mappings != null) { createIndexRequestBuilder.setMapping(mappings); } return createIndex(index, createIndexRequestBuilder); @@ -357,15 +355,20 @@ protected IndexService createIndex(String index, Settings settings, String type, /** * Create a new index on the singleton node with the provided index settings. - * @deprecated types are being removed + * @deprecated types have been removed + */ + @Deprecated + protected IndexService createIndex(String index, Settings settings, String type, XContentBuilder mappings) { + return createIndex(index, settings, mappings); + } + + /** + * Create a new index on the singleton node with the provided index settings. + * @deprecated types have been removed */ @Deprecated protected IndexService createIndex(String index, Settings settings, String type, String... mappings) { - CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings); - if (mappings != null) { - createIndexRequestBuilder.setMapping(mappings); - } - return createIndex(index, createIndexRequestBuilder); + return createIndexWithSimpleMappings(index, settings, mappings); } /**