diff --git a/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java b/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java index 1568ac288d9..ff99fb80d52 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/IndexScopedSettings.java @@ -135,6 +135,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings { MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING, MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING, MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING, + MapperService.INDEX_MAPPING_SINGLE_TYPE_SETTING, BitsetFilterCache.INDEX_LOAD_RANDOM_ACCESS_FILTERS_EAGERLY_SETTING, IndexModule.INDEX_STORE_TYPE_SETTING, IndexModule.INDEX_STORE_PRE_LOAD_SETTING, diff --git a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java index 55cfebe41c1..b0761d0df11 100755 --- a/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/MapperService.java @@ -25,6 +25,7 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.DelegatingAnalyzerWrapper; import org.elasticsearch.ElasticsearchGenerationException; +import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.Nullable; @@ -32,6 +33,7 @@ import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -94,6 +96,19 @@ public class MapperService extends AbstractIndexComponent implements Closeable { public static final boolean INDEX_MAPPER_DYNAMIC_DEFAULT = true; public static final Setting INDEX_MAPPER_DYNAMIC_SETTING = Setting.boolSetting("index.mapper.dynamic", INDEX_MAPPER_DYNAMIC_DEFAULT, Property.Dynamic, Property.IndexScope); + public static final Setting INDEX_MAPPING_SINGLE_TYPE_SETTING; + static { + Function defValue = settings -> { + // TODO: uncomment this + /*boolean singleType = true; + if (settings.getAsVersion(IndexMetaData.SETTING_VERSION_CREATED, null) != null) { + singleType = Version.indexCreated(settings).onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED); + }*/ + boolean singleType = false; + return Boolean.valueOf(singleType).toString(); + }; + INDEX_MAPPING_SINGLE_TYPE_SETTING = Setting.boolSetting("index.mapping.single_type", defValue, Property.IndexScope, Property.Final); + } private static ObjectHashSet META_FIELDS = ObjectHashSet.from( "_uid", "_id", "_type", "_all", "_parent", "_routing", "_index", "_size", "_timestamp", "_ttl" @@ -457,6 +472,15 @@ public class MapperService extends AbstractIndexComponent implements Closeable { } } + if (indexSettings.getValue(INDEX_MAPPING_SINGLE_TYPE_SETTING)) { + Set actualTypes = new HashSet<>(mappers.keySet()); + actualTypes.remove(DEFAULT_MAPPING); + if (actualTypes.size() > 1) { + throw new IllegalArgumentException( + "Rejecting mapping update to [" + index().getName() + "] as the final mapping would have more than 1 type: " + actualTypes); + } + } + // make structures immutable mappers = Collections.unmodifiableMap(mappers); results = Collections.unmodifiableMap(results); diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java b/core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java index dea04d17106..36c7da7894b 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/create/ShrinkIndexIT.java @@ -143,7 +143,7 @@ public class ShrinkIndexIT extends ESIntegTestCase { .put("index.version.created", version) ).get(); for (int i = 0; i < 20; i++) { - client().prepareIndex("source", randomFrom("t1", "t2", "t3")) + client().prepareIndex("source", "type") .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get(); } ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes() @@ -179,7 +179,7 @@ public class ShrinkIndexIT extends ESIntegTestCase { } for (int i = 20; i < 40; i++) { - client().prepareIndex("target", randomFrom("t1", "t2", "t3")) + client().prepareIndex("target", "type") .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get(); } flushAndRefresh(); @@ -197,7 +197,7 @@ public class ShrinkIndexIT extends ESIntegTestCase { .put("number_of_shards", randomIntBetween(2, 7)) .put("number_of_replicas", 0)).get(); for (int i = 0; i < 20; i++) { - client().prepareIndex("source", randomFrom("t1", "t2", "t3")) + client().prepareIndex("source", "type") .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get(); } ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes() @@ -275,10 +275,10 @@ public class ShrinkIndexIT extends ESIntegTestCase { .put("number_of_shards", 8) .put("number_of_replicas", 0) ) - .addMapping("t1", "id", "type=keyword,doc_values=true") + .addMapping("type", "id", "type=keyword,doc_values=true") .get(); for (int i = 0; i < 20; i++) { - client().prepareIndex("source", "t1", Integer.toString(i)) + client().prepareIndex("source", "type", Integer.toString(i)) .setSource("{\"foo\" : \"bar\", \"id\" : " + i + "}", XContentType.JSON).get(); } ImmutableOpenMap dataNodes = client().admin().cluster().prepareState().get().getState().nodes() @@ -326,7 +326,7 @@ public class ShrinkIndexIT extends ESIntegTestCase { // ... and that the index sort is also applied to updates for (int i = 20; i < 40; i++) { - client().prepareIndex("target", randomFrom("t1", "t2", "t3")) + client().prepareIndex("target", "type") .setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", XContentType.JSON).get(); } flushAndRefresh(); diff --git a/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java b/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java index da16b688340..21930b3763b 100644 --- a/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java +++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java @@ -455,6 +455,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase { */ public void testBulkUpdateDocAsUpsertWithParent() throws Exception { client().admin().indices().prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent", "{\"parent\":{}}", XContentType.JSON) .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON) .execute().actionGet(); @@ -519,6 +520,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase { */ public void testBulkUpdateUpsertWithParent() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent", "{\"parent\":{}}", XContentType.JSON) .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON)); ensureGreen(); @@ -603,8 +605,10 @@ public class BulkWithUpdatesIT extends ESIntegTestCase { * Test for https://github.com/elastic/elasticsearch/issues/8365 */ public void testBulkUpdateChildMissingParentRouting() throws Exception { - assertAcked(prepareCreate("test").addMapping("parent", "{\"parent\":{}}", XContentType.JSON) - .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON)); + assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) + .addMapping("parent", "{\"parent\":{}}", XContentType.JSON) + .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON)); ensureGreen(); BulkRequestBuilder builder = client().prepareBulk(); diff --git a/core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java b/core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java index 6959758b110..fcec3d6b594 100644 --- a/core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java +++ b/core/src/test/java/org/elasticsearch/aliases/IndexAliasesIT.java @@ -826,6 +826,7 @@ public class IndexAliasesIT extends ESIntegTestCase { public void testAliasesFilterWithHasChildQuery() throws Exception { assertAcked(prepareCreate("my-index") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent") ); diff --git a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java index 9fd90e3c314..13f7549973d 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java @@ -54,6 +54,7 @@ public class MetaDataMappingServiceTests extends ESSingleNodeTestCase { // Tests _parent meta field logic, because part of the validation is in MetaDataMappingService public void testAddExtraChildTypePointingToAlreadyParentExistingType() throws Exception { IndexService indexService = createIndex("test", client().admin().indices().prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child1", "_parent", "type=parent") ); diff --git a/core/src/test/java/org/elasticsearch/fieldstats/FieldStatsTests.java b/core/src/test/java/org/elasticsearch/fieldstats/FieldStatsTests.java index a396f4bfa6b..379806a7166 100644 --- a/core/src/test/java/org/elasticsearch/fieldstats/FieldStatsTests.java +++ b/core/src/test/java/org/elasticsearch/fieldstats/FieldStatsTests.java @@ -319,9 +319,9 @@ public class FieldStatsTests extends ESSingleNodeTestCase { public void testNumberFiltering() { createIndex("test1", Settings.EMPTY, "type", "value", "type=long"); - client().prepareIndex("test1", "test").setSource("value", 1L).get(); + client().prepareIndex("test1", "type").setSource("value", 1L).get(); createIndex("test2", Settings.EMPTY, "type", "value", "type=long"); - client().prepareIndex("test2", "test").setSource("value", 3L).get(); + client().prepareIndex("test2", "type").setSource("value", 3L).get(); client().admin().indices().prepareRefresh().get(); FieldStatsResponse response = client().prepareFieldStats() @@ -426,10 +426,10 @@ public class FieldStatsTests extends ESSingleNodeTestCase { String dateTime2Str = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER.parser().print(dateTime2); createIndex("test1", Settings.EMPTY, "type", "value", "type=date", "value2", "type=date,index=false"); - client().prepareIndex("test1", "test") + client().prepareIndex("test1", "type") .setSource("value", dateTime1Str, "value2", dateTime1Str).get(); createIndex("test2", Settings.EMPTY, "type", "value", "type=date"); - client().prepareIndex("test2", "test").setSource("value", dateTime2Str).get(); + client().prepareIndex("test2", "type").setSource("value", dateTime2Str).get(); client().admin().indices().prepareRefresh().get(); FieldStatsResponse response = client().prepareFieldStats() diff --git a/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java b/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java index f957a55bf14..4210f9c32c1 100644 --- a/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java +++ b/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java @@ -318,6 +318,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase { // clean two nodes internalCluster().startNodes(2, Settings.builder().put("gateway.recover_after_nodes", 2).build()); + assertAcked(client().admin().indices().prepareCreate("test").setSettings("index.mapping.single_type", false)); client().prepareIndex("test", "type1", "1").setSource(jsonBuilder().startObject().field("field", "value1").endObject()).execute().actionGet(); client().admin().indices().prepareFlush().execute().actionGet(); client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject().field("field", "value2").endObject()).execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java index 2797ae7fcc8..e6439011cf6 100644 --- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -35,7 +35,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.engine.VersionConflictEngineException; @@ -255,7 +254,7 @@ public class GetActionIT extends ESIntegTestCase { assertAcked(prepareCreate("test") .addMapping("type1", mapping1, XContentType.JSON) .addMapping("type2", mapping2, XContentType.JSON) - .setSettings(Settings.builder().put("index.refresh_interval", -1))); + .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false)); ensureGreen(); GetResponse response = client().prepareGet("test", "type1", "1").get(); @@ -530,7 +529,7 @@ public class GetActionIT extends ESIntegTestCase { .addMapping("parent") .addMapping("my-type1", "_parent", "type=parent", "field1", "type=keyword,store=true") .addAlias(new Alias("alias")) - .setSettings(Settings.builder().put("index.refresh_interval", -1))); + .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false)); client().prepareIndex("test", "my-type1", "1") .setRouting("1") @@ -594,7 +593,7 @@ public class GetActionIT extends ESIntegTestCase { public void testGetFieldsComplexField() throws Exception { assertAcked(prepareCreate("my-index") - .setSettings(Settings.builder().put("index.refresh_interval", -1)) + .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false) .addMapping("my-type2", jsonBuilder().startObject().startObject("my-type2").startObject("properties") .startObject("field1").field("type", "object").startObject("properties") .startObject("field2").field("type", "object").startObject("properties") @@ -726,6 +725,7 @@ public class GetActionIT extends ESIntegTestCase { String createIndexSource = "{\n" + " \"settings\": {\n" + " \"index.translog.flush_threshold_size\": \"1pb\",\n" + + " \"index.mapping.single_type\": false," + " \"refresh_interval\": \"-1\"\n" + " },\n" + " \"mappings\": {\n" + @@ -738,7 +738,8 @@ public class GetActionIT extends ESIntegTestCase { " }\n" + " }\n" + "}"; - assertAcked(prepareCreate("test").addAlias(new Alias("alias")).setSource(createIndexSource, XContentType.JSON)); + assertAcked(prepareCreate("test") + .addAlias(new Alias("alias")).setSource(createIndexSource, XContentType.JSON)); ensureGreen(); client().prepareIndex("test", "doc").setId("1").setSource("{}", XContentType.JSON).setParent("1").get(); diff --git a/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java b/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java index cef6806631f..99aa0816082 100644 --- a/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/fielddata/AbstractFieldDataTestCase.java @@ -31,7 +31,9 @@ import org.apache.lucene.index.LogByteSizeMergePolicy; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.cache.bitset.BitsetFilterCache; import org.elasticsearch.index.fielddata.IndexFieldData.XFieldComparatorSource.Nested; @@ -41,6 +43,7 @@ import org.elasticsearch.index.mapper.GeoPointFieldMapper; import org.elasticsearch.index.mapper.KeywordFieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.Mapper.BuilderContext; +import org.elasticsearch.index.mapper.MapperService.MergeReason; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.NumberFieldMapper; import org.elasticsearch.index.mapper.ParentFieldMapper; @@ -131,7 +134,7 @@ public abstract class AbstractFieldDataTestCase extends ESSingleNodeTestCase { @Before public void setup() throws Exception { - indexService = createIndex("test"); + indexService = createIndex("test", Settings.builder().put("mapping.single_type", false).build()); mapperService = indexService.mapperService(); indicesFieldDataCache = getInstanceFromNode(IndicesService.class).getIndicesFieldDataCache(); ifdService = indexService.fieldData(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java index e6d5769467b..91a498541ed 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java @@ -71,7 +71,7 @@ public class DynamicMappingIT extends ESIntegTestCase { } public void testMappingsPropagatedToMasterNodeImmediately() throws IOException { - createIndex("index"); + assertAcked(prepareCreate("index").setSettings("index.mapping.single_type", false)); // works when the type has been dynamically created client().prepareIndex("index", "type", "1").setSource("foo", 3).get(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java index 71ae77aa55e..daf3d99ad5b 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java @@ -34,6 +34,7 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.BooleanFieldMapper.BooleanFieldType; import org.elasticsearch.index.mapper.DateFieldMapper.DateFieldType; +import org.elasticsearch.index.mapper.MapperService.MergeReason; import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType; import org.elasticsearch.test.ESSingleNodeTestCase; @@ -524,7 +525,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { } public void testMixTemplateMultiFieldAndMappingReuse() throws Exception { - IndexService indexService = createIndex("test"); + IndexService indexService = createIndex("test", Settings.builder().put("mapping.single_type", false).build()); XContentBuilder mappings1 = jsonBuilder().startObject() .startObject("type1") .startArray("dynamic_templates") diff --git a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java index 7141550a44f..4d467d641d9 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.mapper; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; @@ -30,6 +29,7 @@ import org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType; import org.elasticsearch.index.mapper.MapperService.MergeReason; import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.hamcrest.Matchers; import java.io.IOException; import java.io.UncheckedIOException; @@ -74,7 +74,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase { } public void testTypes() throws Exception { - IndexService indexService1 = createIndex("index1"); + IndexService indexService1 = createIndex("index1", Settings.builder().put("index.mapping.single_type", false).build()); MapperService mapperService = indexService1.mapperService(); assertEquals(Collections.emptySet(), mapperService.types()); @@ -207,7 +207,7 @@ public class MapperServiceTests extends ESSingleNodeTestCase { } public void testOtherDocumentMappersOnlyUpdatedWhenChangingFieldType() throws IOException { - IndexService indexService = createIndex("test"); + IndexService indexService = createIndex("test", Settings.builder().put("index.mapping.single_type", false).build()); CompressedXContent simpleMapping = new CompressedXContent(XContentFactory.jsonBuilder().startObject() .startObject("properties") @@ -309,4 +309,16 @@ public class MapperServiceTests extends ESSingleNodeTestCase { assertThat(invalidNestedException.getMessage(), containsString("cannot have nested fields when index sort is activated")); } + + @AwaitsFix(bugUrl="https://github.com/elastic/elasticsearch/pull/24317#issuecomment-297624290") + public void testForbidMultipleTypes() throws IOException { + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); + MapperService mapperService = createIndex("test").mapperService(); + mapperService.merge("type", new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE, randomBoolean()); + + String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type2").endObject().endObject().string(); + IllegalArgumentException e = expectThrows(IllegalArgumentException.class, + () -> mapperService.merge("type2", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, randomBoolean())); + assertThat(e.getMessage(), Matchers.startsWith("Rejecting mapping update to [test] as the final mapping would have more than 1 type: ")); + } } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java index 91cf8fdde85..f4a8ce11c56 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/NestedObjectMapperTests.java @@ -382,8 +382,9 @@ public class NestedObjectMapperTests extends ESSingleNodeTestCase { .mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false)); assertThat(e.getMessage(), containsString("Limit of nested fields [1] in index [test3] has been exceeded")); - MapperService mapperService = createIndex("test4", Settings.builder().put(MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING.getKey(), 2) - .build()).mapperService(); + MapperService mapperService = createIndex("test4", Settings.builder() + .put("mapping.single_type", false) + .put(MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING.getKey(), 2).build()).mapperService(); mapperService.merge("type1", new CompressedXContent(mapping.apply("type1")), MergeReason.MAPPING_UPDATE, false); // merging same fields, but different type is ok mapperService.merge("type2", new CompressedXContent(mapping.apply("type2")), MergeReason.MAPPING_UPDATE, false); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java index af5061e62ae..7ef1b751eeb 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ParentFieldMapperTests.java @@ -67,7 +67,7 @@ public class ParentFieldMapperTests extends ESSingleNodeTestCase { String childMapping = XContentFactory.jsonBuilder().startObject().startObject("child_type") .startObject("_parent").field("type", "parent_type").endObject() .endObject().endObject().string(); - IndexService indexService = createIndex("test"); + IndexService indexService = createIndex("test", Settings.builder().put("mapping.single_type", false).build()); indexService.mapperService().merge("parent_type", new CompressedXContent(parentMapping), MergeReason.MAPPING_UPDATE, false); indexService.mapperService().merge("child_type", new CompressedXContent(childMapping), MergeReason.MAPPING_UPDATE, false); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingTests.java index 9321801d1f4..7c18d9cb1a6 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/UpdateMappingTests.java @@ -42,15 +42,6 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { return pluginList(InternalSettingsPlugin.class); } - private void testNoConflictWhileMergingAndMappingChanged(XContentBuilder mapping, XContentBuilder mappingUpdate, XContentBuilder expectedMapping) throws IOException { - IndexService indexService = createIndex("test", Settings.builder().build(), "type", mapping); - // simulate like in MetaDataMappingService#putMapping - indexService.mapperService().merge("type", new CompressedXContent(mappingUpdate.bytes()), MapperService.MergeReason.MAPPING_UPDATE, false); - // make sure mappings applied - CompressedXContent mappingAfterUpdate = indexService.mapperService().documentMapper("type").mappingSource(); - assertThat(mappingAfterUpdate.toString(), equalTo(expectedMapping.string())); - } - public void testConflictFieldsMapping(String fieldName) throws Exception { //test store, ... all the parameters that are not to be changed just like in other fields XContentBuilder mapping = XContentFactory.jsonBuilder() @@ -159,7 +150,7 @@ public class UpdateMappingTests extends ESSingleNodeTestCase { .startObject("properties").startObject("foo").field("type", "long").endObject() .endObject().endObject().endObject(); XContentBuilder mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type2").endObject().endObject(); - MapperService mapperService = createIndex("test", Settings.builder().build()).mapperService(); + MapperService mapperService = createIndex("test", Settings.builder().put("mapping.single_type", false).build()).mapperService(); mapperService.merge("type1", new CompressedXContent(mapping1.string()), MapperService.MergeReason.MAPPING_UPDATE, false); mapperService.merge("type2", new CompressedXContent(mapping2.string()), MapperService.MergeReason.MAPPING_UPDATE, false); diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java index 2734fd78284..ce2b5088ac9 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java @@ -547,7 +547,9 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase { verify(client().admin().indices().preparePutMapping("foo").setType("type1").setSource("field", "type=text"), true); verify(client().admin().indices().preparePutMapping("_all").setType("type1").setSource("field", "type=text"), true); - createIndex("foo", "foobar", "bar", "barbaz"); + for (String index : Arrays.asList("foo", "foobar", "bar", "barbaz")) { + assertAcked(prepareCreate(index).setSettings("index.mapping.single_type", false)); + } verify(client().admin().indices().preparePutMapping("foo").setType("type1").setSource("field", "type=text"), false); assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo").get("type1"), notNullValue()); diff --git a/core/src/test/java/org/elasticsearch/indices/exists/types/TypesExistsIT.java b/core/src/test/java/org/elasticsearch/indices/exists/types/TypesExistsIT.java index ffe44b3e1c1..31e3ca82326 100644 --- a/core/src/test/java/org/elasticsearch/indices/exists/types/TypesExistsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/exists/types/TypesExistsIT.java @@ -40,6 +40,7 @@ public class TypesExistsIT extends ESIntegTestCase { public void testSimple() throws Exception { Client client = client(); CreateIndexResponse response1 = client.admin().indices().prepareCreate("test1") + .setSettings("index.mapping.single_type", false) .addMapping("type1", jsonBuilder().startObject().startObject("type1").endObject().endObject()) .addMapping("type2", jsonBuilder().startObject().startObject("type2").endObject().endObject()) .execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java b/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java index f654dfe19f6..57f3ec29e32 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java @@ -67,9 +67,11 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase { public void testSimpleGetFieldMappings() throws Exception { assertAcked(prepareCreate("indexa") + .setSettings("index.mapping.single_type", false) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB"))); assertAcked(client().admin().indices().prepareCreate("indexb") + .setSettings("index.mapping.single_type", false) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB"))); @@ -184,6 +186,7 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase { public void testGetFieldMappingsWithBlocks() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB"))); diff --git a/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java b/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java index 6b96e4e102d..89b0d48ef22 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java @@ -56,12 +56,14 @@ public class SimpleGetMappingsIT extends ESIntegTestCase { public void testSimpleGetMappings() throws Exception { client().admin().indices().prepareCreate("indexa") + .setSettings("index.mapping.single_type", false) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB")) .addMapping("Atype", getMappingForType("Atype")) .addMapping("Btype", getMappingForType("Btype")) .execute().actionGet(); client().admin().indices().prepareCreate("indexb") + .setSettings("index.mapping.single_type", false) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB")) .addMapping("Atype", getMappingForType("Atype")) @@ -143,6 +145,7 @@ public class SimpleGetMappingsIT extends ESIntegTestCase { public void testGetMappingsWithBlocks() throws IOException { client().admin().indices().prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB")) .execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java index 5b62c99d242..d41ef16d771 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -69,6 +69,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase { .put("index.number_of_shards", 1) .put("index.number_of_replicas", 0) .put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), Long.MAX_VALUE) + .put("index.mapping.single_type", false) ).execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); @@ -281,7 +282,7 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase { Client client1 = clientArray.get(i % clientArray.size()); Client client2 = clientArray.get((i + 1) % clientArray.size()); String indexName = i % 2 == 0 ? "test2" : "test1"; - String typeName = "type" + (i % 10); + String typeName = "type"; String fieldName = Thread.currentThread().getName() + "_" + i; PutMappingResponse response = client1.admin().indices().preparePutMapping(indexName).setType(typeName).setSource( @@ -341,7 +342,9 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase { } public void testUpdateMappingOnAllTypes() throws IOException { - assertAcked(prepareCreate("index").addMapping("type1", "f", "type=keyword").addMapping("type2", "f", "type=keyword")); + assertAcked(prepareCreate("index") + .setSettings("index.mapping.single_type", false) + .addMapping("type1", "f", "type=keyword").addMapping("type2", "f", "type=keyword")); assertAcked(client().admin().indices().preparePutMapping("index") .setType("type1") diff --git a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java index 312ad78e6ca..f8cf9bd7a3c 100644 --- a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java @@ -383,7 +383,8 @@ public class IndexStatsIT extends ESIntegTestCase { } public void testSimpleStats() throws Exception { - createIndex("test1", "test2"); + assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false)); + createIndex("test2"); ensureGreen(); client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet(); @@ -512,7 +513,7 @@ public class IndexStatsIT extends ESIntegTestCase { } public void testMergeStats() { - createIndex("test1"); + assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false)); ensureGreen(); @@ -548,7 +549,8 @@ public class IndexStatsIT extends ESIntegTestCase { } public void testSegmentsStats() { - assertAcked(prepareCreate("test1", 2, settingsBuilder().put(SETTING_NUMBER_OF_REPLICAS, between(0, 1)))); + assertAcked(prepareCreate("test1") + .setSettings(SETTING_NUMBER_OF_REPLICAS, between(0, 1), "index.mapping.single_type", false)); ensureGreen(); NumShards test1 = getNumShards("test1"); @@ -573,7 +575,7 @@ public class IndexStatsIT extends ESIntegTestCase { public void testAllFlags() throws Exception { // rely on 1 replica for this tests - createIndex("test1"); + assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false)); createIndex("test2"); ensureGreen(); @@ -695,7 +697,7 @@ public class IndexStatsIT extends ESIntegTestCase { } public void testMultiIndex() throws Exception { - createIndex("test1"); + assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false)); createIndex("test2"); ensureGreen(); @@ -735,6 +737,7 @@ public class IndexStatsIT extends ESIntegTestCase { public void testFieldDataFieldsParam() throws Exception { assertAcked(client().admin().indices().prepareCreate("test1") + .setSettings("index.mapping.single_type", false) .addMapping("type", "bar", "type=text,fielddata=true", "baz", "type=text,fielddata=true").get()); @@ -782,6 +785,7 @@ public class IndexStatsIT extends ESIntegTestCase { public void testCompletionFieldsParam() throws Exception { assertAcked(prepareCreate("test1") + .setSettings("index.mapping.single_type", false) .addMapping( "bar", "{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}", XContentType.JSON)); diff --git a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java index 10ccc4f0025..017026844f1 100644 --- a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java +++ b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java @@ -383,7 +383,8 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase { .get(); assertAcked(prepareCreate("test_index") - .addMapping("type1").addMapping("type2").addMapping("typeX").addMapping("typeY").addMapping("typeZ")); + .setSettings("index.mapping.single_type", false) + .addMapping("type1").addMapping("type2").addMapping("typeX").addMapping("typeY").addMapping("typeZ")); ensureGreen(); client().prepareIndex("test_index", "type1", "1").setSource("field", "A value").get(); @@ -439,7 +440,9 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase { "}"), XContentType.JSON).get(); - assertAcked(prepareCreate("test_index").addMapping("type1").addMapping("type2")); + assertAcked(prepareCreate("test_index") + .setSettings("index.mapping.single_type", false) + .addMapping("type1").addMapping("type2")); ensureGreen(); GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get(); @@ -474,7 +477,9 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase { " \"alias3\" : { \"routing\" : \"1\" }" + " }\n").get(); - assertAcked(prepareCreate("test_index").addMapping("type1").addMapping("type2")); + assertAcked(prepareCreate("test_index") + .setSettings("index.mapping.single_type", false) + .addMapping("type1").addMapping("type2")); ensureGreen(); GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get(); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java index 9075f7b8735..bfe483ca890 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ChildrenIT.java @@ -68,6 +68,7 @@ public class ChildrenIT extends ESIntegTestCase { public void setupSuiteScopeCluster() throws Exception { assertAcked( prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("article", "category", "type=keyword") .addMapping("comment", "_parent", "type=article", "commenter", "type=keyword") ); @@ -238,6 +239,7 @@ public class ChildrenIT extends ESIntegTestCase { String indexName = "xyz"; assertAcked( prepareCreate(indexName) + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent", "count", "type=long") ); @@ -296,6 +298,7 @@ children("non-existing", "xyz") String childType = "variantsku"; assertAcked( prepareCreate(indexName) + .setSettings("index.mapping.single_type", false) .addMapping(masterType, "brand", "type=text", "name", "type=keyword", "material", "type=text") .addMapping(childType, "_parent", "type=masterprod", "color", "type=keyword", "size", "type=keyword") ); @@ -359,6 +362,7 @@ children("non-existing", "xyz") .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) ) + .setSettings("index.mapping.single_type", false) .addMapping(grandParentType, "name", "type=keyword") .addMapping(parentType, "_parent", "type=" + grandParentType) .addMapping(childType, "_parent", "type=" + parentType) @@ -402,6 +406,7 @@ children("non-existing", "xyz") assertAcked( prepareCreate("index") + .setSettings("index.mapping.single_type", false) .addMapping("parentType", "name", "type=keyword", "town", "type=keyword") .addMapping("childType", "_parent", "type=parentType", "name", "type=keyword", "age", "type=integer") ); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DoubleTermsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DoubleTermsIT.java index 816ef980a3e..cf28541121c 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DoubleTermsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/DoubleTermsIT.java @@ -139,7 +139,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } for (int i = 0; i < 100; i++) { - builders.add(client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder() + builders.add(client().prepareIndex("high_card_idx", "type").setSource(jsonBuilder() .startObject() .field(SINGLE_VALUED_FIELD_NAME, (double) i) .startArray(MULTI_VALUED_FIELD_NAME).value((double)i).value(i + 1d).endArray() @@ -279,14 +279,14 @@ public class DoubleTermsIT extends AbstractTermsTestCase { public void testSizeIsZero() { IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> client() - .prepareSearch("idx").setTypes("high_card_type").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME) + .prepareSearch("high_card_idx").addAggregation(terms("terms").field(SINGLE_VALUED_FIELD_NAME) .minDocCount(randomInt(1)).size(0).collectMode(randomFrom(SubAggCollectionMode.values()))) .execute().actionGet()); assertThat(exception.getMessage(), containsString("[size] must be greater than 0. Found [0] in [terms]")); } public void testSingleValueField() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values()))) @@ -310,7 +310,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testSingleValueFieldWithMaxSize() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") + SearchResponse response = client().prepareSearch("high_card_idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .size(20) @@ -345,7 +345,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } private void testIncludeExcludeResults(double[] includes, double[] excludes, double[] expecteds) { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .includeExclude(new IncludeExclude(includes, excludes)) @@ -374,7 +374,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { private void runTestFieldWithPartitionedFiltering(String field) throws Exception { // Find total number of unique terms - SearchResponse allResponse = client().prepareSearch("idx").setTypes("type") + SearchResponse allResponse = client().prepareSearch("idx") .addAggregation(terms("terms").field(field).size(10000).collectMode(randomFrom(SubAggCollectionMode.values()))) .execute().actionGet(); assertSearchResponse(allResponse); @@ -387,7 +387,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { final int numPartitions = randomIntBetween(2, 4); Set foundTerms = new HashSet<>(); for (int partition = 0; partition < numPartitions; partition++) { - SearchResponse response = client().prepareSearch("idx").setTypes("type").addAggregation(terms("terms").field(field) + SearchResponse response = client().prepareSearch("idx").addAggregation(terms("terms").field(field) .includeExclude(new IncludeExclude(partition, numPartitions)).collectMode(randomFrom(SubAggCollectionMode.values()))) .execute().actionGet(); assertSearchResponse(response); @@ -402,7 +402,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testSingleValueFieldOrderedByTermAsc() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -428,7 +428,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testSingleValueFieldOrderedByTermDesc() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -454,7 +454,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testSingleValuedFieldWithSubAggregation() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -489,7 +489,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testSingleValuedFieldWithValueScript() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -514,7 +514,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testMultiValuedField() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(MULTI_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values()))) @@ -542,7 +542,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testMultiValuedFieldWithValueScript() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(MULTI_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -571,7 +571,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testMultiValuedFieldWithValueScriptNotUnique() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(MULTI_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -614,7 +614,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { public void testScriptSingleValue() throws Exception { SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("terms") .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -641,7 +640,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { public void testScriptMultiValued() throws Exception { SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("terms") .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -670,7 +668,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testUnmapped() throws Exception { - SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type") + SearchResponse response = client().prepareSearch("idx_unmapped") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .size(randomIntBetween(1, 5)) @@ -687,7 +685,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testPartiallyUnmapped() throws Exception { - SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx_unmapped", "idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values()))) @@ -711,7 +709,7 @@ public class DoubleTermsIT extends AbstractTermsTestCase { } public void testPartiallyUnmappedWithFormat() throws Exception { - SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx_unmapped", "idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -759,7 +757,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { boolean asc = true; SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("avg_i", asc)).subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))) @@ -788,7 +785,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { boolean asc = true; SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("terms") .field(SINGLE_VALUED_FIELD_NAME) @@ -833,7 +829,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { boolean asc = randomBoolean(); SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("num_tags").field("num_tag").collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("filter", asc)) @@ -870,7 +865,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { boolean asc = randomBoolean(); SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("tags") .field("num_tag") @@ -927,7 +921,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { for (String index : Arrays.asList("idx", "idx_unmapped")) { try { client().prepareSearch(index) - .setTypes("type") .addAggregation( terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("avg_i", true))).execute().actionGet(); @@ -944,7 +937,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { for (String index : Arrays.asList("idx", "idx_unmapped")) { try { client().prepareSearch(index) - .setTypes("type") .addAggregation( terms("terms") .field(SINGLE_VALUED_FIELD_NAME) @@ -966,7 +958,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { for (String index : Arrays.asList("idx", "idx_unmapped")) { try { client().prepareSearch(index) - .setTypes("type") .addAggregation( terms("terms").field(SINGLE_VALUED_FIELD_NAME + "2").collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("stats.foo", true)) @@ -985,7 +976,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { for (String index : Arrays.asList("idx", "idx_unmapped")) { try { client().prepareSearch(index) - .setTypes("type") .addAggregation( terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("stats", true)) @@ -1004,7 +994,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { boolean asc = false; SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("avg_i", asc)).subAggregation(avg("avg_i").field(SINGLE_VALUED_FIELD_NAME))) @@ -1035,7 +1024,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { boolean asc = true; SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("stats.avg", asc)) @@ -1064,7 +1052,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { boolean asc = false; SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("stats.avg", asc)) @@ -1093,7 +1080,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { boolean asc = true; SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation( terms("terms").field(SINGLE_VALUED_FIELD_NAME).collectMode(randomFrom(SubAggCollectionMode.values())) .order(Terms.Order.aggregation("stats.variance", asc)) @@ -1128,7 +1114,6 @@ public class DoubleTermsIT extends AbstractTermsTestCase { SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .setQuery(functionScoreQuery(scriptFunction(scoringScript))) .addAggregation( terms("terms") diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/LongTermsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/LongTermsIT.java index f010d505897..6793768a91f 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/LongTermsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/LongTermsIT.java @@ -113,7 +113,7 @@ public class LongTermsIT extends AbstractTermsTestCase { @Override public void setupSuiteScopeCluster() throws Exception { - createIndex("idx"); + createIndex("idx", "high_card_idx"); IndexRequestBuilder[] lowCardBuilders = new IndexRequestBuilder[NUM_DOCS]; for (int i = 0; i < lowCardBuilders.length; i++) { lowCardBuilders[i] = client().prepareIndex("idx", "type").setSource(jsonBuilder() @@ -123,10 +123,10 @@ public class LongTermsIT extends AbstractTermsTestCase { .field("num_tag", i < lowCardBuilders.length / 2 + 1 ? 1 : 0) // used to test order by single-bucket sub agg .endObject()); } - indexRandom(randomBoolean(), lowCardBuilders); + indexRandom(true, lowCardBuilders); IndexRequestBuilder[] highCardBuilders = new IndexRequestBuilder[100]; // TODO randomize the size? for (int i = 0; i < highCardBuilders.length; i++) { - highCardBuilders[i] = client().prepareIndex("idx", "high_card_type").setSource(jsonBuilder() + highCardBuilders[i] = client().prepareIndex("high_card_idx", "type").setSource(jsonBuilder() .startObject() .field(SINGLE_VALUED_FIELD_NAME, i) .startArray(MULTI_VALUED_FIELD_NAME).value(i).value(i + 1).endArray() @@ -268,7 +268,7 @@ public class LongTermsIT extends AbstractTermsTestCase { // the main purpose of this test is to make sure we're not allocating 2GB of memory per shard public void testSizeIsZero() { IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> client().prepareSearch("idx").setTypes("high_card_type") + () -> client().prepareSearch("high_card_idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -279,7 +279,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testSingleValueField() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values()))) @@ -317,7 +317,8 @@ public class LongTermsIT extends AbstractTermsTestCase { private void testIncludeExcludeResults(int minDocCount, long[] includes, long[] excludes, long[] expectedWithCounts, long[] expectedZeroCounts) { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx", "high_card_idx") + .setQuery(QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery("_index", "high_card_idx"))) .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .includeExclude(new IncludeExclude(includes, excludes)) @@ -355,7 +356,7 @@ public class LongTermsIT extends AbstractTermsTestCase { private void runTestFieldWithPartitionedFiltering(String field) throws Exception { // Find total number of unique terms - SearchResponse allResponse = client().prepareSearch("idx").setTypes("type") + SearchResponse allResponse = client().prepareSearch("idx") .addAggregation(terms("terms").field(field).collectMode(randomFrom(SubAggCollectionMode.values()))).execute().actionGet(); assertSearchResponse(allResponse); Terms terms = allResponse.getAggregations().get("terms"); @@ -367,7 +368,7 @@ public class LongTermsIT extends AbstractTermsTestCase { final int numPartitions = randomIntBetween(2, 4); Set foundTerms = new HashSet<>(); for (int partition = 0; partition < numPartitions; partition++) { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation( terms("terms").field(field).includeExclude(new IncludeExclude(partition, numPartitions)) .collectMode(randomFrom(SubAggCollectionMode.values()))) @@ -386,7 +387,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValueFieldWithMaxSize() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("high_card_type") + SearchResponse response = client().prepareSearch("high_card_idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .size(20) @@ -412,7 +413,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testSingleValueFieldOrderedByTermAsc() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -436,7 +437,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testSingleValueFieldOrderedByTermDesc() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -462,7 +463,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testSingleValuedFieldWithSubAggregation() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -496,7 +497,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testSingleValuedFieldWithValueScript() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -521,7 +522,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testMultiValuedField() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(MULTI_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values()))) @@ -549,7 +550,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testMultiValuedFieldWithValueScript() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(MULTI_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -578,7 +579,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testMultiValuedFieldWithValueScriptNotUnique() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(MULTI_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -622,7 +623,7 @@ public class LongTermsIT extends AbstractTermsTestCase { Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + SINGLE_VALUED_FIELD_NAME + "'].value", Collections.emptyMap()); - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .collectMode(randomFrom(SubAggCollectionMode.values())) .script(script)) @@ -649,7 +650,7 @@ public class LongTermsIT extends AbstractTermsTestCase { Script script = new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "doc['" + MULTI_VALUED_FIELD_NAME + "']", Collections.emptyMap()); - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .collectMode(randomFrom(SubAggCollectionMode.values())) .script(script)) @@ -677,7 +678,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testUnmapped() throws Exception { - SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type") + SearchResponse response = client().prepareSearch("idx_unmapped") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .size(randomIntBetween(1, 5)) @@ -694,7 +695,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testPartiallyUnmapped() throws Exception { - SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx_unmapped", "idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values()))) @@ -718,7 +719,7 @@ public class LongTermsIT extends AbstractTermsTestCase { } public void testPartiallyUnmappedWithFormat() throws Exception { - SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx_unmapped", "idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -764,7 +765,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedBySingleValueSubAggregationAsc() throws Exception { boolean asc = true; - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -793,7 +794,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedBySingleValueSubAggregationAscWithTermsSubAgg() throws Exception { boolean asc = true; - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -837,7 +838,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedBySingleBucketSubAggregationAsc() throws Exception { boolean asc = randomBoolean(); - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("num_tags") .field("num_tag") .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -874,7 +875,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedBySubAggregationAscMultiHierarchyLevels() throws Exception { boolean asc = randomBoolean(); - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("tags") .field("num_tag") .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -929,7 +930,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByMissingSubAggregation() throws Exception { for (String index : Arrays.asList("idx", "idx_unmapped")) { try { - client().prepareSearch(index).setTypes("type") + client().prepareSearch(index) .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -947,7 +948,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByNonMetricsOrMultiBucketSubAggregation() throws Exception { for (String index : Arrays.asList("idx", "idx_unmapped")) { try { - client().prepareSearch(index).setTypes("type") + client().prepareSearch(index) .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -967,7 +968,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByMultiValuedSubAggregationWithUknownMetric() throws Exception { for (String index : Arrays.asList("idx", "idx_unmapped")) { try { - client().prepareSearch(index).setTypes("type") + client().prepareSearch(index) .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -987,7 +988,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByMultiValuedSubAggregationWithoutMetric() throws Exception { for (String index : Arrays.asList("idx", "idx_unmapped")) { try { - client().prepareSearch(index).setTypes("type") + client().prepareSearch(index) .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -1006,7 +1007,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedBySingleValueSubAggregationDesc() throws Exception { boolean asc = false; - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -1038,7 +1039,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByMultiValueSubAggregationAsc() throws Exception { boolean asc = true; - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -1068,7 +1069,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByMultiValueSubAggregationDesc() throws Exception { boolean asc = false; - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -1098,7 +1099,7 @@ public class LongTermsIT extends AbstractTermsTestCase { public void testSingleValuedFieldOrderedByMultiValueExtendedStatsAsc() throws Exception { boolean asc = true; - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ReverseNestedIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ReverseNestedIT.java index 3fdd32d22bb..6118cb69ee7 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ReverseNestedIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/ReverseNestedIT.java @@ -60,18 +60,19 @@ public class ReverseNestedIT extends ESIntegTestCase { @Override public void setupSuiteScopeCluster() throws Exception { - assertAcked(prepareCreate("idx") + assertAcked(prepareCreate("idx1") .addMapping( - "type1", + "type", jsonBuilder().startObject().startObject("properties") .startObject("field1").field("type", "keyword").endObject() .startObject("nested1").field("type", "nested").startObject("properties") .startObject("field2").field("type", "keyword").endObject() .endObject().endObject() .endObject().endObject() - ) + )); + assertAcked(prepareCreate("idx2") .addMapping( - "type2", + "type", jsonBuilder().startObject().startObject("properties") .startObject("nested1").field("type", "nested").startObject("properties") .startObject("field1").field("type", "keyword").endObject() @@ -83,31 +84,31 @@ public class ReverseNestedIT extends ESIntegTestCase { ) ); - insertType1(Arrays.asList("a", "b", "c"), Arrays.asList("1", "2", "3", "4")); - insertType1(Arrays.asList("b", "c", "d"), Arrays.asList("4", "5", "6", "7")); - insertType1(Arrays.asList("c", "d", "e"), Arrays.asList("7", "8", "9", "1")); + insertIdx1(Arrays.asList("a", "b", "c"), Arrays.asList("1", "2", "3", "4")); + insertIdx1(Arrays.asList("b", "c", "d"), Arrays.asList("4", "5", "6", "7")); + insertIdx1(Arrays.asList("c", "d", "e"), Arrays.asList("7", "8", "9", "1")); refresh(); - insertType1(Arrays.asList("a", "e"), Arrays.asList("7", "4", "1", "1")); - insertType1(Arrays.asList("a", "c"), Arrays.asList("2", "1")); - insertType1(Arrays.asList("a"), Arrays.asList("3", "4")); + insertIdx1(Arrays.asList("a", "e"), Arrays.asList("7", "4", "1", "1")); + insertIdx1(Arrays.asList("a", "c"), Arrays.asList("2", "1")); + insertIdx1(Arrays.asList("a"), Arrays.asList("3", "4")); refresh(); - insertType1(Arrays.asList("x", "c"), Arrays.asList("1", "8")); - insertType1(Arrays.asList("y", "c"), Arrays.asList("6")); - insertType1(Arrays.asList("z"), Arrays.asList("5", "9")); + insertIdx1(Arrays.asList("x", "c"), Arrays.asList("1", "8")); + insertIdx1(Arrays.asList("y", "c"), Arrays.asList("6")); + insertIdx1(Arrays.asList("z"), Arrays.asList("5", "9")); refresh(); - insertType2(new String[][]{new String[]{"a", "0", "0", "1", "2"}, new String[]{"b", "0", "1", "1", "2"}, new String[]{"a", "0"}}); - insertType2(new String[][]{new String[]{"c", "1", "1", "2", "2"}, new String[]{"d", "3", "4"}}); + insertIdx2(new String[][]{new String[]{"a", "0", "0", "1", "2"}, new String[]{"b", "0", "1", "1", "2"}, new String[]{"a", "0"}}); + insertIdx2(new String[][]{new String[]{"c", "1", "1", "2", "2"}, new String[]{"d", "3", "4"}}); refresh(); - insertType2(new String[][]{new String[]{"a", "0", "0", "0", "0"}, new String[]{"b", "0", "0", "0", "0"}}); - insertType2(new String[][]{new String[]{"e", "1", "2"}, new String[]{"f", "3", "4"}}); + insertIdx2(new String[][]{new String[]{"a", "0", "0", "0", "0"}, new String[]{"b", "0", "0", "0", "0"}}); + insertIdx2(new String[][]{new String[]{"e", "1", "2"}, new String[]{"f", "3", "4"}}); refresh(); ensureSearchable(); } - private void insertType1(List values1, List values2) throws Exception { + private void insertIdx1(List values1, List values2) throws Exception { XContentBuilder source = jsonBuilder() .startObject() .array("field1", values1.toArray()) @@ -116,10 +117,10 @@ public class ReverseNestedIT extends ESIntegTestCase { source.startObject().field("field2", value1).endObject(); } source.endArray().endObject(); - indexRandom(false, client().prepareIndex("idx", "type1").setRouting("1").setSource(source)); + indexRandom(false, client().prepareIndex("idx1", "type").setRouting("1").setSource(source)); } - private void insertType2(String[][] values) throws Exception { + private void insertIdx2(String[][] values) throws Exception { XContentBuilder source = jsonBuilder() .startObject() .startArray("nested1"); @@ -131,11 +132,11 @@ public class ReverseNestedIT extends ESIntegTestCase { source.endArray().endObject(); } source.endArray().endObject(); - indexRandom(false, client().prepareIndex("idx", "type2").setRouting("1").setSource(source)); + indexRandom(false, client().prepareIndex("idx2", "type").setRouting("1").setSource(source)); } public void testSimpleReverseNestedToRoot() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type1") + SearchResponse response = client().prepareSearch("idx1") .addAggregation(nested("nested1", "nested1") .subAggregation( terms("field2").field("nested1.field2") @@ -323,7 +324,7 @@ public class ReverseNestedIT extends ESIntegTestCase { } public void testSimpleNested1ToRootToNested2() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type2") + SearchResponse response = client().prepareSearch("idx2") .addAggregation(nested("nested1", "nested1") .subAggregation( reverseNested("nested1_to_root") @@ -345,7 +346,7 @@ public class ReverseNestedIT extends ESIntegTestCase { } public void testSimpleReverseNestedToNested1() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type2") + SearchResponse response = client().prepareSearch("idx2") .addAggregation(nested("nested1", "nested1.nested2") .subAggregation( terms("field2").field("nested1.nested2.field2").order(Terms.Order.term(true)) @@ -448,7 +449,7 @@ public class ReverseNestedIT extends ESIntegTestCase { public void testReverseNestedAggWithoutNestedAgg() { try { - client().prepareSearch("idx") + client().prepareSearch("idx2") .addAggregation(terms("field2").field("nested1.nested2.field2") .collectMode(randomFrom(SubAggCollectionMode.values())) .subAggregation( @@ -466,7 +467,7 @@ public class ReverseNestedIT extends ESIntegTestCase { } public void testNonExistingNestedField() throws Exception { - SearchResponse searchResponse = client().prepareSearch("idx") + SearchResponse searchResponse = client().prepareSearch("idx2") .setQuery(matchAllQuery()) .addAggregation(nested("nested2", "nested1.nested2").subAggregation(reverseNested("incorrect").path("nested3"))) .get(); @@ -479,7 +480,7 @@ public class ReverseNestedIT extends ESIntegTestCase { assertThat(reverseNested.getDocCount(), is(0L)); // Test that parsing the reverse_nested agg doesn't fail, because the parent nested agg is unmapped: - searchResponse = client().prepareSearch("idx") + searchResponse = client().prepareSearch("idx1") .setQuery(matchAllQuery()) .addAggregation(nested("incorrect1", "incorrect1").subAggregation(reverseNested("incorrect2").path("incorrect2"))) .get(); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/StringTermsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/StringTermsIT.java index deda92dc353..b5dbcd9085a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/bucket/StringTermsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/bucket/StringTermsIT.java @@ -136,8 +136,12 @@ public class StringTermsIT extends AbstractTermsTestCase { getMultiSortDocs(builders); + assertAcked(client().admin().indices().prepareCreate("high_card_idx") + .addMapping("type", SINGLE_VALUED_FIELD_NAME, "type=keyword", + MULTI_VALUED_FIELD_NAME, "type=keyword", + "tag", "type=keyword").get()); for (int i = 0; i < 100; i++) { - builders.add(client().prepareIndex("idx", "high_card_type").setSource( + builders.add(client().prepareIndex("high_card_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val" + Strings.padStart(i + "", 3, '0')) .startArray(MULTI_VALUED_FIELD_NAME).value("val" + Strings.padStart(i + "", 3, '0')) .value("val" + Strings.padStart((i + 1) + "", 3, '0')).endArray().endObject())); @@ -203,26 +207,26 @@ public class StringTermsIT extends AbstractTermsTestCase { MULTI_VALUED_FIELD_NAME, "type=keyword", "tag", "type=keyword").get()); for (int i = 1; i <= 3; i++) { - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val1").field("l", 1).field("d", i).endObject())); - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val2").field("l", 2).field("d", i).endObject())); } - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val3").field("l", 3).field("d", 1).endObject())); - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val3").field("l", 3).field("d", 2).endObject())); - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val4").field("l", 3).field("d", 1).endObject())); - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val4").field("l", 3).field("d", 3).endObject())); - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val5").field("l", 5).field("d", 1).endObject())); - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val5").field("l", 5).field("d", 2).endObject())); - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val6").field("l", 5).field("d", 1).endObject())); - builders.add(client().prepareIndex("sort_idx", "multi_sort_type").setSource( + builders.add(client().prepareIndex("sort_idx", "type").setSource( jsonBuilder().startObject().field(SINGLE_VALUED_FIELD_NAME, "val7").field("l", 5).field("d", 1).endObject())); } @@ -234,8 +238,7 @@ public class StringTermsIT extends AbstractTermsTestCase { public void testSizeIsZero() { final int minDocCount = randomInt(1); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> client() - .prepareSearch("idx") - .setTypes("high_card_type") + .prepareSearch("high_card_idx") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())).minDocCount(minDocCount).size(0)).execute() @@ -302,8 +305,7 @@ public class StringTermsIT extends AbstractTermsTestCase { // we should be left with: val000, val001, val002, val003, val004, val005, val006, val007, val008, val009 SearchResponse response = client() - .prepareSearch("idx") - .setTypes("high_card_type") + .prepareSearch("high_card_idx") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())).includeExclude(new IncludeExclude("val00.+", null))) @@ -327,8 +329,7 @@ public class StringTermsIT extends AbstractTermsTestCase { // we should be left with: val002, val003, val004, val005, val006, val007, val008, val009 response = client() - .prepareSearch("idx") - .setTypes("high_card_type") + .prepareSearch("high_card_idx") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -353,8 +354,7 @@ public class StringTermsIT extends AbstractTermsTestCase { // we should be left with: val000, val001, val002, val003, val004, val005, val006, val007, val008, val009 response = client() - .prepareSearch("idx") - .setTypes("high_card_type") + .prepareSearch("high_card_idx") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())) @@ -380,8 +380,7 @@ public class StringTermsIT extends AbstractTermsTestCase { // include without exclude String incVals[] = { "val000", "val001", "val002", "val003", "val004", "val005", "val006", "val007", "val008", "val009" }; SearchResponse response = client() - .prepareSearch("idx") - .setTypes("high_card_type") + .prepareSearch("high_card_idx") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())).includeExclude(new IncludeExclude(incVals, null))) @@ -408,8 +407,7 @@ public class StringTermsIT extends AbstractTermsTestCase { String excVals[] = { "val000", "val001" }; response = client() - .prepareSearch("idx") - .setTypes("high_card_type") + .prepareSearch("high_card_idx") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())).includeExclude(new IncludeExclude(incVals, excVals))) @@ -432,8 +430,7 @@ public class StringTermsIT extends AbstractTermsTestCase { // Check case with only exact term exclude clauses response = client() - .prepareSearch("idx") - .setTypes("high_card_type") + .prepareSearch("high_card_idx") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())).includeExclude(new IncludeExclude(null, excVals))) @@ -500,8 +497,7 @@ public class StringTermsIT extends AbstractTermsTestCase { public void testSingleValueFieldWithMaxSize() throws Exception { SearchResponse response = client() - .prepareSearch("idx") - .setTypes("high_card_type") + .prepareSearch("high_card_idx") .addAggregation( terms("terms") .executionHint(randomExecutionHint()) @@ -1505,7 +1501,6 @@ public class StringTermsIT extends AbstractTermsTestCase { private void assertMultiSortResponse(String[] expectedKeys, Terms.Order... order) { SearchResponse response = client() .prepareSearch("sort_idx") - .setTypes("multi_sort_type") .addAggregation( terms("terms").executionHint(randomExecutionHint()).field(SINGLE_VALUED_FIELD_NAME) .collectMode(randomFrom(SubAggCollectionMode.values())).order(Terms.Order.compound(order)) diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java index a3cfac728ce..aeef44d6272 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java @@ -115,7 +115,8 @@ public class TopHitsIT extends ESIntegTestCase { @Override public void setupSuiteScopeCluster() throws Exception { - assertAcked(prepareCreate("idx").addMapping("type", TERMS_AGGS_FIELD, "type=keyword", "group", "type=keyword")); + assertAcked(prepareCreate("idx").addMapping("type", TERMS_AGGS_FIELD, "type=keyword")); + assertAcked(prepareCreate("field-collapsing").addMapping("type", "group", "type=keyword")); createIndex("empty"); assertAcked(prepareCreate("articles").addMapping("article", jsonBuilder().startObject().startObject("article").startObject("properties") .startObject(TERMS_AGGS_FIELD) @@ -160,49 +161,49 @@ public class TopHitsIT extends ESIntegTestCase { .endObject())); } - builders.add(client().prepareIndex("idx", "field-collapsing", "1").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "1").setSource(jsonBuilder() .startObject() .field("group", "a") .field("text", "term x y z b") .endObject())); - builders.add(client().prepareIndex("idx", "field-collapsing", "2").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "2").setSource(jsonBuilder() .startObject() .field("group", "a") .field("text", "term x y z n rare") .field("value", 1) .endObject())); - builders.add(client().prepareIndex("idx", "field-collapsing", "3").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "3").setSource(jsonBuilder() .startObject() .field("group", "b") .field("text", "x y z term") .endObject())); - builders.add(client().prepareIndex("idx", "field-collapsing", "4").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "4").setSource(jsonBuilder() .startObject() .field("group", "b") .field("text", "x y term") .endObject())); - builders.add(client().prepareIndex("idx", "field-collapsing", "5").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "5").setSource(jsonBuilder() .startObject() .field("group", "b") .field("text", "x term") .endObject())); - builders.add(client().prepareIndex("idx", "field-collapsing", "6").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "6").setSource(jsonBuilder() .startObject() .field("group", "b") .field("text", "term rare") .field("value", 3) .endObject())); - builders.add(client().prepareIndex("idx", "field-collapsing", "7").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "7").setSource(jsonBuilder() .startObject() .field("group", "c") .field("text", "x y z term") .endObject())); - builders.add(client().prepareIndex("idx", "field-collapsing", "8").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "8").setSource(jsonBuilder() .startObject() .field("group", "c") .field("text", "x y term b") .endObject())); - builders.add(client().prepareIndex("idx", "field-collapsing", "9").setSource(jsonBuilder() + builders.add(client().prepareIndex("field-collapsing", "type", "9").setSource(jsonBuilder() .startObject() .field("group", "c") .field("text", "rare x term") @@ -270,7 +271,6 @@ public class TopHitsIT extends ESIntegTestCase { public void testBasics() throws Exception { SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation(terms("terms") .executionHint(randomExecutionHint()) .field(TERMS_AGGS_FIELD) @@ -309,8 +309,7 @@ public class TopHitsIT extends ESIntegTestCase { public void testIssue11119() throws Exception { // Test that top_hits aggregation is fed scores if query results size=0 SearchResponse response = client() - .prepareSearch("idx") - .setTypes("field-collapsing") + .prepareSearch("field-collapsing") .setSize(0) .setQuery(matchQuery("text", "x y z")) .addAggregation(terms("terms").executionHint(randomExecutionHint()).field("group").subAggregation(topHits("hits"))) @@ -344,8 +343,7 @@ public class TopHitsIT extends ESIntegTestCase { // tied up with the need to feed scores into the agg tree even when // users don't want ranked set of query results.) response = client() - .prepareSearch("idx") - .setTypes("field-collapsing") + .prepareSearch("field-collapsing") .setSize(0) .setMinScore(0.0001f) .setQuery(matchQuery("text", "x y z")) @@ -365,7 +363,7 @@ public class TopHitsIT extends ESIntegTestCase { public void testBreadthFirstWithScoreNeeded() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .executionHint(randomExecutionHint()) .collectMode(SubAggCollectionMode.BREADTH_FIRST) @@ -395,7 +393,7 @@ public class TopHitsIT extends ESIntegTestCase { } public void testBreadthFirstWithAggOrderAndScoreNeeded() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .executionHint(randomExecutionHint()) .collectMode(SubAggCollectionMode.BREADTH_FIRST) @@ -448,7 +446,7 @@ public class TopHitsIT extends ESIntegTestCase { public void testPagination() throws Exception { int size = randomIntBetween(1, 10); int from = randomIntBetween(0, 10); - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .executionHint(randomExecutionHint()) .field(TERMS_AGGS_FIELD) @@ -463,7 +461,6 @@ public class TopHitsIT extends ESIntegTestCase { assertSearchResponse(response); SearchResponse control = client().prepareSearch("idx") - .setTypes("type") .setFrom(from) .setSize(size) .setPostFilter(QueryBuilders.termQuery(TERMS_AGGS_FIELD, "val0")) @@ -493,7 +490,7 @@ public class TopHitsIT extends ESIntegTestCase { } public void testSortByBucket() throws Exception { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .addAggregation(terms("terms") .executionHint(randomExecutionHint()) .field(TERMS_AGGS_FIELD) @@ -533,8 +530,7 @@ public class TopHitsIT extends ESIntegTestCase { public void testFieldCollapsing() throws Exception { SearchResponse response = client() - .prepareSearch("idx") - .setTypes("field-collapsing") + .prepareSearch("field-collapsing") .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) .setQuery(matchQuery("text", "term rare")) .addAggregation( @@ -575,7 +571,7 @@ public class TopHitsIT extends ESIntegTestCase { } public void testFetchFeatures() { - SearchResponse response = client().prepareSearch("idx").setTypes("type") + SearchResponse response = client().prepareSearch("idx") .setQuery(matchQuery("text", "text").queryName("test")) .addAggregation(terms("terms") .executionHint(randomExecutionHint()) @@ -633,7 +629,7 @@ public class TopHitsIT extends ESIntegTestCase { public void testInvalidSortField() throws Exception { try { - client().prepareSearch("idx").setTypes("type") + client().prepareSearch("idx") .addAggregation(terms("terms") .executionHint(randomExecutionHint()) .field(TERMS_AGGS_FIELD) @@ -648,7 +644,7 @@ public class TopHitsIT extends ESIntegTestCase { } public void testEmptyIndex() throws Exception { - SearchResponse response = client().prepareSearch("empty").setTypes("type") + SearchResponse response = client().prepareSearch("empty") .addAggregation(topHits("hits")) .get(); assertSearchResponse(response); @@ -663,7 +659,7 @@ public class TopHitsIT extends ESIntegTestCase { boolean[] trackScores = new boolean[]{true, false}; for (boolean trackScore : trackScores) { logger.info("Track score={}", trackScore); - SearchResponse response = client().prepareSearch("idx").setTypes("field-collapsing") + SearchResponse response = client().prepareSearch("field-collapsing") .setQuery(matchQuery("text", "term rare")) .addAggregation(terms("terms") .field("group") @@ -949,7 +945,6 @@ public class TopHitsIT extends ESIntegTestCase { public void testDontExplode() throws Exception { SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation(terms("terms") .executionHint(randomExecutionHint()) .field(TERMS_AGGS_FIELD) @@ -964,7 +959,6 @@ public class TopHitsIT extends ESIntegTestCase { public void testNoStoredFields() throws Exception { SearchResponse response = client() .prepareSearch("idx") - .setTypes("type") .addAggregation(terms("terms") .executionHint(randomExecutionHint()) .field(TERMS_AGGS_FIELD) @@ -1062,7 +1056,6 @@ public class TopHitsIT extends ESIntegTestCase { .addRescorer( RescoreBuilder.queryRescorer(new MatchAllQueryBuilder().boost(3.0f)) ) - .setTypes("type") .addAggregation(terms("terms") .field(TERMS_AGGS_FIELD) .subAggregation( @@ -1085,7 +1078,6 @@ public class TopHitsIT extends ESIntegTestCase { .addRescorer( RescoreBuilder.queryRescorer(new MatchAllQueryBuilder().boost(3.0f)) ) - .setTypes("type") .addAggregation(terms("terms") .field(TERMS_AGGS_FIELD) .subAggregation( @@ -1109,7 +1101,6 @@ public class TopHitsIT extends ESIntegTestCase { .addRescorer( RescoreBuilder.queryRescorer(new MatchAllQueryBuilder().boost(3.0f)) ) - .setTypes("type") .addAggregation(terms("terms") .field(TERMS_AGGS_FIELD) .subAggregation( @@ -1132,7 +1123,6 @@ public class TopHitsIT extends ESIntegTestCase { .addRescorer( RescoreBuilder.queryRescorer(new MatchAllQueryBuilder().boost(3.0f)) ) - .setTypes("type") .addAggregation(terms("terms") .field(TERMS_AGGS_FIELD) .subAggregation( diff --git a/core/src/test/java/org/elasticsearch/search/basic/TransportSearchFailuresIT.java b/core/src/test/java/org/elasticsearch/search/basic/TransportSearchFailuresIT.java index 8e81a3a852e..9384847b2ac 100644 --- a/core/src/test/java/org/elasticsearch/search/basic/TransportSearchFailuresIT.java +++ b/core/src/test/java/org/elasticsearch/search/basic/TransportSearchFailuresIT.java @@ -117,7 +117,7 @@ public class TransportSearchFailuresIT extends ESIntegTestCase { } private void index(Client client, String id, String nameValue, int age) throws IOException { - client.index(Requests.indexRequest("test").type("type1").id(id).source(source(id, nameValue, age))).actionGet(); + client.index(Requests.indexRequest("test").type("type").id(id).source(source(id, nameValue, age))).actionGet(); } private XContentBuilder source(String id, String nameValue, int age) throws IOException { diff --git a/core/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java b/core/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java index 3c16ff7188c..ed70aa119f6 100644 --- a/core/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/basic/TransportTwoNodesSearchIT.java @@ -97,7 +97,7 @@ public class TransportTwoNodesSearchIT extends ESIntegTestCase { } private void index(String id, String nameValue, int age) throws IOException { - client().index(Requests.indexRequest("test").type("type1").id(id).source(source(id, nameValue, age))).actionGet(); + client().index(Requests.indexRequest("test").type("type").id(id).source(source(id, nameValue, age))).actionGet(); } private XContentBuilder source(String id, String nameValue, int age) throws IOException { diff --git a/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java b/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java index efeabc93a0e..697352c5edc 100644 --- a/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/child/ChildQuerySearchIT.java @@ -118,6 +118,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testMultiLevelChild() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent") .addMapping("grandchild", "_parent", "type=child")); @@ -173,6 +174,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { // see #2744 public void test2744() throws IOException { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("foo") .addMapping("test", "_parent", "type=foo")); ensureGreen(); @@ -192,6 +194,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testSimpleChildQuery() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -265,6 +268,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { // Issue #3290 public void testCachingBugWithFqueryFilter() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -304,6 +308,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testHasParentFilter() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -353,6 +358,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testSimpleChildQueryWithFlush() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -422,6 +428,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testScopedFacet() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent", "c_field", "type=keyword")); ensureGreen(); @@ -459,6 +466,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testDeletedParent() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -494,6 +502,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testDfsSearchType() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -521,6 +530,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testHasChildAndHasParentFailWhenSomeSegmentsDontContainAnyParentOrChildDocs() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -545,6 +555,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testCountApiUsage() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -575,6 +586,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testExplainUsage() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -663,6 +675,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testScoreForParentChildQueriesWithFunctionScore() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent") .addMapping("child1", "_parent", "type=parent")); @@ -750,6 +763,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { // Issue #2536 public void testParentChildQueriesCanHandleNoRelevantTypesInIndex() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -784,6 +798,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testHasChildAndHasParentFilter_withFilter() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -811,6 +826,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testHasChildInnerHitsHighlighting() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -836,6 +852,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testHasChildAndHasParentWrappedInAQueryFilter() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -867,6 +884,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testSimpleQueryRewrite() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent", "p_field", "type=keyword") .addMapping("child", "_parent", "type=parent", "c_field", "type=keyword")); ensureGreen(); @@ -915,6 +933,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { // Issue #3144 public void testReIndexingParentAndChildDocuments() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -976,6 +995,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { // Issue #3203 public void testHasChildQueryWithMinimumScore() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1000,8 +1020,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testParentFieldQuery() throws Exception { assertAcked(prepareCreate("test") - .setSettings(Settings.builder().put(indexSettings()) - .put("index.refresh_interval", -1)) + .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1034,8 +1053,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testParentIdQuery() throws Exception { assertAcked(prepareCreate("test") - .setSettings(Settings.builder().put(indexSettings()) - .put("index.refresh_interval", -1)) + .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1059,6 +1077,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testHasChildNotBeingCached() throws IOException { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1121,6 +1140,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { // Issue #3818 public void testHasChildQueryOnlyReturnsSingleChildType() { assertAcked(prepareCreate("grandissue") + .setSettings("index.mapping.single_type", false) .addMapping("grandparent", "name", "type=text") .addMapping("parent", "_parent", "type=grandparent") .addMapping("child_type_one", "_parent", "type=parent") @@ -1173,6 +1193,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testIndexChildDocWithNoParentMapping() throws IOException { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child1")); ensureGreen(); @@ -1220,6 +1241,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testHasChildQueryWithNestedInnerObjects() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent", "objects", "type=nested") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1261,6 +1283,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testNamedFilters() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1354,11 +1377,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testParentChildCaching() throws Exception { assertAcked(prepareCreate("test") - .setSettings( - Settings.builder() - .put(indexSettings()) - .put("index.refresh_interval", -1) - ) + .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1402,6 +1421,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testParentChildQueriesViaScrollApi() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1446,6 +1466,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { // Issue #5783 public void testQueryBeforeChildType() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("features") .addMapping("posts", "_parent", "type=features") .addMapping("specials")); @@ -1465,6 +1486,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { // Issue #6256 public void testParentFieldInMultiMatchField() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("type1") .addMapping("type2", "_parent", "type=type1") ); @@ -1483,6 +1505,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testTypeIsAppliedInHasParentInnerQuery() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1570,6 +1593,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testMinMaxChildren() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent", "id", "type=long") .addMapping("child", "_parent", "type=parent")); ensureGreen(); @@ -1883,7 +1907,9 @@ public class ChildQuerySearchIT extends ESIntegTestCase { } public void testParentFieldToNonExistingType() { - assertAcked(prepareCreate("test").addMapping("parent").addMapping("child", "_parent", "type=parent2")); + assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) + .addMapping("parent").addMapping("child", "_parent", "type=parent2")); client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get(); client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get(); refresh(); @@ -1898,7 +1924,9 @@ public class ChildQuerySearchIT extends ESIntegTestCase { } public void testHasParentInnerQueryType() { - assertAcked(prepareCreate("test").addMapping("parent-type").addMapping("child-type", "_parent", "type=parent-type")); + assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) + .addMapping("parent-type").addMapping("child-type", "_parent", "type=parent-type")); client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("{}", XContentType.JSON).get(); client().prepareIndex("test", "parent-type", "parent-id").setSource("{}", XContentType.JSON).get(); refresh(); @@ -1909,7 +1937,9 @@ public class ChildQuerySearchIT extends ESIntegTestCase { } public void testHasChildInnerQueryType() { - assertAcked(prepareCreate("test").addMapping("parent-type").addMapping("child-type", "_parent", "type=parent-type")); + assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) + .addMapping("parent-type").addMapping("child-type", "_parent", "type=parent-type")); client().prepareIndex("test", "child-type", "child-id").setParent("parent-id").setSource("{}", XContentType.JSON).get(); client().prepareIndex("test", "parent-type", "parent-id").setSource("{}", XContentType.JSON).get(); refresh(); @@ -1921,6 +1951,7 @@ public class ChildQuerySearchIT extends ESIntegTestCase { public void testHighlightersIgnoreParentChild() { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent-type", "searchText", "type=text,term_vector=with_positions_offsets,index_options=offsets") .addMapping("child-type", "_parent", "type=parent-type", "searchText", "type=text,term_vector=with_positions_offsets,index_options=offsets")); diff --git a/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java b/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java index 44b01b3a4b9..d3a8946571b 100644 --- a/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java +++ b/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java @@ -60,6 +60,7 @@ public class ParentFieldLoadingIT extends ESIntegTestCase { .put(IndexSettings.INDEX_REFRESH_INTERVAL_SETTING.getKey(), -1) // We never want merges in this test to ensure we have two segments for the last validation .put(MergePolicyConfig.INDEX_MERGE_ENABLED, false) + .put("index.mapping.single_type", false) .build(); public void testEagerParentFieldLoading() throws Exception { diff --git a/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java b/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java index 7d5b57b8ca1..f93fbabdf26 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/subphase/InnerHitsIT.java @@ -245,6 +245,7 @@ public class InnerHitsIT extends ESIntegTestCase { public void testSimpleParentChild() throws Exception { assertAcked(prepareCreate("articles") + .setSettings("index.mapping.single_type", false) .addMapping("article", "title", "type=text") .addMapping("comment", "_parent", "type=article", "message", "type=text,fielddata=true") ); @@ -319,6 +320,7 @@ public class InnerHitsIT extends ESIntegTestCase { public void testRandomParentChild() throws Exception { assertAcked(prepareCreate("idx") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("child1", "_parent", "type=parent") .addMapping("child2", "_parent", "type=parent") @@ -402,6 +404,7 @@ public class InnerHitsIT extends ESIntegTestCase { public void testInnerHitsOnHasParent() throws Exception { assertAcked(prepareCreate("stack") + .setSettings("index.mapping.single_type", false) .addMapping("question", "body", "type=text") .addMapping("answer", "_parent", "type=question", "body", "type=text") ); @@ -444,9 +447,10 @@ public class InnerHitsIT extends ESIntegTestCase { public void testParentChildMultipleLayers() throws Exception { assertAcked(prepareCreate("articles") - .addMapping("article", "title", "type=text") - .addMapping("comment", "_parent", "type=article", "message", "type=text") - .addMapping("remark", "_parent", "type=comment", "message", "type=text") + .setSettings("index.mapping.single_type", false) + .addMapping("article", "title", "type=text") + .addMapping("comment", "_parent", "type=article", "message", "type=text") + .addMapping("remark", "_parent", "type=comment", "message", "type=text") ); List requests = new ArrayList<>(); @@ -720,6 +724,7 @@ public class InnerHitsIT extends ESIntegTestCase { public void testRoyals() throws Exception { assertAcked( prepareCreate("royals") + .setSettings("index.mapping.single_type", false) .addMapping("king") .addMapping("prince", "_parent", "type=king") .addMapping("duke", "_parent", "type=prince") @@ -907,7 +912,9 @@ public class InnerHitsIT extends ESIntegTestCase { } public void testMatchesQueriesParentChildInnerHits() throws Exception { - assertAcked(prepareCreate("index").addMapping("child", "_parent", "type=parent")); + assertAcked(prepareCreate("index") + .setSettings("index.mapping.single_type", false) + .addMapping("child", "_parent", "type=parent")); List requests = new ArrayList<>(); requests.add(client().prepareIndex("index", "parent", "1").setSource("{}", XContentType.JSON)); requests.add(client().prepareIndex("index", "child", "1").setParent("1").setSource("field", "value1")); @@ -946,7 +953,9 @@ public class InnerHitsIT extends ESIntegTestCase { } public void testDontExplode() throws Exception { - assertAcked(prepareCreate("index1").addMapping("child", "_parent", "type=parent")); + assertAcked(prepareCreate("index1") + .setSettings("index.mapping.single_type", false) + .addMapping("child", "_parent", "type=parent")); List requests = new ArrayList<>(); requests.add(client().prepareIndex("index1", "parent", "1").setSource("{}", XContentType.JSON)); requests.add(client().prepareIndex("index1", "child", "1").setParent("1").setSource("field", "value1")); @@ -1012,7 +1021,9 @@ public class InnerHitsIT extends ESIntegTestCase { } public void testNestedInnerHitWrappedInParentChildInnerhit() throws Exception { - assertAcked(prepareCreate("test").addMapping("child_type", "_parent", "type=parent_type", "nested_type", "type=nested")); + assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) + .addMapping("child_type", "_parent", "type=parent_type", "nested_type", "type=nested")); client().prepareIndex("test", "parent_type", "1").setSource("key", "value").get(); client().prepareIndex("test", "child_type", "2").setParent("1").setSource("nested_type", Collections.singletonMap("key", "value")) .get(); @@ -1030,6 +1041,7 @@ public class InnerHitsIT extends ESIntegTestCase { public void testInnerHitsWithIgnoreUnmapped() throws Exception { assertAcked(prepareCreate("index1") + .setSettings("index.mapping.single_type", false) .addMapping("parent_type", "nested_type", "type=nested") .addMapping("child_type", "_parent", "type=parent_type") ); diff --git a/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java b/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java index 819b2c7d644..01cc605393b 100644 --- a/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java @@ -1433,6 +1433,7 @@ public class HighlighterSearchIT extends ESIntegTestCase { public void testPhrasePrefix() throws IOException { Builder builder = Settings.builder() .put(indexSettings()) + .put("index.mapping.single_type", false) .put("index.analysis.analyzer.synonym.tokenizer", "whitespace") .putArray("index.analysis.analyzer.synonym.filter", "synonym", "lowercase") .put("index.analysis.filter.synonym.type", "synonym") diff --git a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java index 428ac63eaef..b33196cf005 100644 --- a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java +++ b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java @@ -639,7 +639,8 @@ public class SearchFieldsIT extends ESIntegTestCase { public void testGetFieldsComplexField() throws Exception { client().admin().indices().prepareCreate("my-index") - .setSettings(Settings.builder().put("index.refresh_interval", -1)) + .setSettings("index.refresh_interval", -1) + .setSettings("index.mapping.single_type", false) .addMapping("my-type2", jsonBuilder() .startObject() .startObject("my-type2") @@ -871,6 +872,7 @@ public class SearchFieldsIT extends ESIntegTestCase { public void testLoadMetadata() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("parent") .addMapping("my-type1", "_parent", "type=parent")); diff --git a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java index 81a3fc0d6b5..0d2c5cf1bdc 100644 --- a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -81,7 +81,9 @@ public class MoreLikeThisIT extends ESIntegTestCase { public void testSimpleMoreLikeOnLongField() throws Exception { logger.info("Creating index test"); - assertAcked(prepareCreate("test").addMapping("type1", "some_long", "type=long")); + assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) + .addMapping("type1", "some_long", "type=long")); logger.info("Running Cluster Health"); assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); @@ -357,7 +359,8 @@ public class MoreLikeThisIT extends ESIntegTestCase { public void testSimpleMoreLikeThisIdsMultipleTypes() throws Exception { logger.info("Creating index test"); int numOfTypes = randomIntBetween(2, 10); - CreateIndexRequestBuilder createRequestBuilder = prepareCreate("test"); + CreateIndexRequestBuilder createRequestBuilder = prepareCreate("test") + .setSettings("index.mapping.single_type", false); for (int i = 0; i < numOfTypes; i++) { createRequestBuilder.addMapping("type" + i, jsonBuilder().startObject().startObject("type" + i).startObject("properties") .startObject("text").field("type", "text").endObject() diff --git a/core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java b/core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java index 47164688ea5..316e83ad1bb 100644 --- a/core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java +++ b/core/src/test/java/org/elasticsearch/search/nested/SimpleNestedIT.java @@ -57,6 +57,7 @@ import static org.hamcrest.Matchers.startsWith; public class SimpleNestedIT extends ESIntegTestCase { public void testSimpleNested() throws Exception { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("type1", "nested1", "type=nested") .addMapping("type2", "nested1", "type=nested")); ensureGreen(); diff --git a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index a30049c70d5..d920c6a67b4 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -544,7 +544,7 @@ public class SearchQueryIT extends ESIntegTestCase { } public void testTypeFilter() throws Exception { - assertAcked(prepareCreate("test")); + assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false)); indexRandom(true, client().prepareIndex("test", "type1", "1").setSource("field1", "value1"), client().prepareIndex("test", "type2", "1").setSource("field1", "value1"), client().prepareIndex("test", "type1", "2").setSource("field1", "value1"), @@ -1180,7 +1180,7 @@ public class SearchQueryIT extends ESIntegTestCase { } public void testBasicQueryById() throws Exception { - createIndex("test"); + assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false)); client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get(); client().prepareIndex("test", "type2", "2").setSource("field1", "value2").get(); @@ -1447,6 +1447,7 @@ public class SearchQueryIT extends ESIntegTestCase { public void testSimpleDFSQuery() throws IOException { assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("s", jsonBuilder() .startObject() .startObject("s") @@ -1642,7 +1643,7 @@ public class SearchQueryIT extends ESIntegTestCase { } public void testQueryStringWithSlopAndFields() { - createIndex("test"); + assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false)); client().prepareIndex("test", "customer", "1").setSource("desc", "one two three").get(); client().prepareIndex("test", "product", "2").setSource("desc", "one two three").get(); diff --git a/core/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java b/core/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java index aa166f6e1a2..2f89c5b2306 100644 --- a/core/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java +++ b/core/src/test/java/org/elasticsearch/search/slice/SearchSliceIT.java @@ -88,7 +88,7 @@ public class SearchSliceIT extends ESIntegTestCase { builder.field("static_int", 0); builder.field("invalid_random_int", randomInt()); builder.endObject(); - requests.add(client().prepareIndex("test", "test").setSource(builder)); + requests.add(client().prepareIndex("test", "type").setSource(builder)); } indexRandom(true, requests); return numberOfShards; diff --git a/core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java b/core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java index a8911afe1fa..4bddc1c556a 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java +++ b/core/src/test/java/org/elasticsearch/search/sort/FieldSortIT.java @@ -176,7 +176,7 @@ public class FieldSortIT extends ESIntegTestCase { public void testTrackScores() throws Exception { assertAcked(client().admin().indices().prepareCreate("test") - .addMapping("type", "svalue", "type=keyword").get()); + .addMapping("type1", "svalue", "type=keyword").get()); ensureGreen(); index("test", "type1", jsonBuilder().startObject() .field("id", "1") @@ -421,7 +421,7 @@ public class FieldSortIT extends ESIntegTestCase { public void testIssue2986() { assertAcked(client().admin().indices().prepareCreate("test") - .addMapping("type", "field1", "type=keyword").get()); + .addMapping("post", "field1", "type=keyword").get()); client().prepareIndex("test", "post", "1").setSource("{\"field1\":\"value1\"}", XContentType.JSON).execute().actionGet(); client().prepareIndex("test", "post", "2").setSource("{\"field1\":\"value2\"}", XContentType.JSON).execute().actionGet(); diff --git a/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java b/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java index 82f06441ef6..92fb2cd2777 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/SuggestSearchIT.java @@ -881,8 +881,8 @@ public class SuggestSearchIT extends ESIntegTestCase { .put("index.analysis.filter.shingler.output_unigrams", true)).addMapping("type1", mappingBuilder)); ensureGreen(); - index("test", "type2", "1", "foo", "bar"); - index("test", "type2", "2", "foo", "bar"); + index("test", "type1", "11", "foo", "bar"); + index("test", "type1", "12", "foo", "bar"); index("test", "type1", "1", "name", "Just testing the suggestions api"); index("test", "type1", "2", "name", "An other title about equal length"); refresh(); diff --git a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java index c3f801f77fb..d8a0036a45c 100644 --- a/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java +++ b/core/src/test/java/org/elasticsearch/snapshots/SharedClusterSnapshotRestoreIT.java @@ -505,9 +505,9 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas assertThat(client.admin().indices() .preparePutTemplate("test-template") .setPatterns(Collections.singletonList("te*")) - .addMapping("test-mapping", XContentFactory.jsonBuilder() + .addMapping("doc", XContentFactory.jsonBuilder() .startObject() - .startObject("test-mapping") + .startObject("doc") .startObject("properties") .startObject("field1") .field("type", "text") diff --git a/core/src/test/java/org/elasticsearch/tribe/TribeIT.java b/core/src/test/java/org/elasticsearch/tribe/TribeIT.java index 7c58622e5cc..f678d4528fe 100644 --- a/core/src/test/java/org/elasticsearch/tribe/TribeIT.java +++ b/core/src/test/java/org/elasticsearch/tribe/TribeIT.java @@ -386,10 +386,10 @@ public class TribeIT extends ESIntegTestCase { public void testTribeOnOneCluster() throws Exception { try (Releasable tribeNode = startTribeNode()) { // Creates 2 indices, test1 on cluster1 and test2 on cluster2 - assertAcked(cluster1.client().admin().indices().prepareCreate("test1")); + assertAcked(cluster1.client().admin().indices().prepareCreate("test1").setSettings("index.mapping.single_type", false)); ensureGreen(cluster1.client()); - assertAcked(cluster2.client().admin().indices().prepareCreate("test2")); + assertAcked(cluster2.client().admin().indices().prepareCreate("test2").setSettings("index.mapping.single_type", false)); ensureGreen(cluster2.client()); // Wait for the tribe node to retrieve the indices into its cluster state diff --git a/core/src/test/java/org/elasticsearch/update/UpdateIT.java b/core/src/test/java/org/elasticsearch/update/UpdateIT.java index 75c3feb038a..893bbbd6115 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateIT.java @@ -728,7 +728,9 @@ public class UpdateIT extends ESIntegTestCase { } public void testContextVariables() throws Exception { - assertAcked(prepareCreate("test").addAlias(new Alias("alias")) + assertAcked(prepareCreate("test") + .setSettings("index.mapping.single_type", false) + .addAlias(new Alias("alias")) .addMapping("type1", XContentFactory.jsonBuilder() .startObject() .startObject("type1") diff --git a/docs/build.gradle b/docs/build.gradle index a587cec658f..2648fad3cc0 100644 --- a/docs/build.gradle +++ b/docs/build.gradle @@ -207,7 +207,7 @@ buildRestTests.setups['ledger'] = ''' - do: bulk: index: ledger - type: item + type: sale refresh: true body: | {"index":{}} diff --git a/docs/reference/aggregations/bucket/children-aggregation.asciidoc b/docs/reference/aggregations/bucket/children-aggregation.asciidoc index 9c3b2926dac..57ea9ce56cc 100644 --- a/docs/reference/aggregations/bucket/children-aggregation.asciidoc +++ b/docs/reference/aggregations/bucket/children-aggregation.asciidoc @@ -12,6 +12,9 @@ For example, let's say we have an index of questions and answers. The answer typ -------------------------------------------------- PUT child_example { + "settings": { + "mapping.single_type": false + }, "mappings": { "answer" : { "_parent" : { diff --git a/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc b/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc index 6f21f4521d3..e674f8bf0e7 100644 --- a/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc +++ b/docs/reference/analysis/charfilters/pattern-replace-charfilter.asciidoc @@ -205,7 +205,7 @@ the length of the original text: [source,js] ---------------------------- -PUT my_index/my_doc/1?refresh +PUT my_index/my_type/1?refresh { "text": "The fooBarBaz method" } @@ -245,7 +245,7 @@ The output from the above is: "hits": [ { "_index": "my_index", - "_type": "my_doc", + "_type": "my_type", "_id": "1", "_score": 0.2824934, "_source": { diff --git a/docs/reference/docs/index_.asciidoc b/docs/reference/docs/index_.asciidoc index bcbcee2f907..2f042aec132 100644 --- a/docs/reference/docs/index_.asciidoc +++ b/docs/reference/docs/index_.asciidoc @@ -279,6 +279,9 @@ For example: -------------------------------------------------- PUT blogs { + "settings": { + "mapping.single_type": false + }, "mappings": { "tag_parent": {}, "blog_tag": { diff --git a/docs/reference/indices/put-mapping.asciidoc b/docs/reference/indices/put-mapping.asciidoc index 6bc623b95e2..0dd2ffc3d8a 100644 --- a/docs/reference/indices/put-mapping.asciidoc +++ b/docs/reference/indices/put-mapping.asciidoc @@ -8,6 +8,9 @@ fields to an existing type: -------------------------------------------------- PUT twitter <1> { + "settings": { + "mapping.single_type": false + }, "mappings": { "tweet": { "properties": { @@ -147,6 +150,9 @@ For example, this fails: ----------------------------------- PUT my_index { + "settings": { + "mapping.single_type": false + }, "mappings": { "type_one": { "properties": { diff --git a/docs/reference/mapping.asciidoc b/docs/reference/mapping.asciidoc index be77e29d7de..59e49c317af 100644 --- a/docs/reference/mapping.asciidoc +++ b/docs/reference/mapping.asciidoc @@ -153,6 +153,9 @@ index, as follows: --------------------------------------- PUT my_index <1> { + "settings": { + "mapping.single_type": false + }, "mappings": { "user": { <2> "properties": { <3> diff --git a/docs/reference/mapping/dynamic/default-mapping.asciidoc b/docs/reference/mapping/dynamic/default-mapping.asciidoc index 926c66ced51..14836727440 100644 --- a/docs/reference/mapping/dynamic/default-mapping.asciidoc +++ b/docs/reference/mapping/dynamic/default-mapping.asciidoc @@ -12,6 +12,9 @@ mapping types, can be customised by adding a mapping type with the name -------------------------------------------------- PUT my_index { + "settings": { + "mapping.single_type": false + }, "mappings": { "_default_": { <1> "_source": { diff --git a/docs/reference/mapping/fields/parent-field.asciidoc b/docs/reference/mapping/fields/parent-field.asciidoc index 82343b1a908..7edaa3949d9 100644 --- a/docs/reference/mapping/fields/parent-field.asciidoc +++ b/docs/reference/mapping/fields/parent-field.asciidoc @@ -8,6 +8,9 @@ index by making one mapping type the parent of another: -------------------------------------------------- PUT my_index { + "settings": { + "mapping.single_type": false + }, "mappings": { "my_parent": {}, "my_child": { @@ -137,6 +140,9 @@ make sense to disable eager loading: -------------------------------------------------- PUT my_index { + "settings": { + "mapping.single_type": false + }, "mappings": { "my_parent": {}, "my_child": { diff --git a/docs/reference/mapping/fields/type-field.asciidoc b/docs/reference/mapping/fields/type-field.asciidoc index 07f62e016e9..fb577b5a03f 100644 --- a/docs/reference/mapping/fields/type-field.asciidoc +++ b/docs/reference/mapping/fields/type-field.asciidoc @@ -11,6 +11,13 @@ scripts, and when sorting: [source,js] -------------------------- # Example documents +PUT my_index +{ + "settings": { + "mapping.single_type": false + } +} + PUT my_index/type_1/1 { "text": "Document with type 1" diff --git a/docs/reference/query-dsl/parent-id-query.asciidoc b/docs/reference/query-dsl/parent-id-query.asciidoc index c35f5111103..4fdfa70312e 100644 --- a/docs/reference/query-dsl/parent-id-query.asciidoc +++ b/docs/reference/query-dsl/parent-id-query.asciidoc @@ -10,6 +10,9 @@ Given the following mapping definition: -------------------------------------------- PUT /my_index { + "settings": { + "mapping.single_type": false + }, "mappings": { "blog_post": { "properties": { diff --git a/docs/reference/query-dsl/percolate-query.asciidoc b/docs/reference/query-dsl/percolate-query.asciidoc index 1d43bff06a1..296255d2ded 100644 --- a/docs/reference/query-dsl/percolate-query.asciidoc +++ b/docs/reference/query-dsl/percolate-query.asciidoc @@ -9,22 +9,18 @@ to match with the stored queries. [float] === Sample Usage -Create an index with two mappings: +Create an index with two fields: [source,js] -------------------------------------------------- PUT /my-index { "mappings": { - "doctype": { + "doc": { "properties": { "message": { "type": "text" - } - } - }, - "queries": { - "properties": { + }, "query": { "type": "percolator" } @@ -35,23 +31,20 @@ PUT /my-index -------------------------------------------------- // CONSOLE -The `doctype` mapping is the mapping used to preprocess -the document defined in the `percolator` query before it -gets indexed into a temporary index. +The `message` field is the field used to preprocess the document defined in +the `percolator` query before it gets indexed into a temporary index. -The `queries` mapping is the mapping used for indexing -the query documents. The `query` field will hold a json -object that represents an actual Elasticsearch query. The -`query` field has been configured to use the -<>. This field type understands -the query dsl and stored the query in such a way that it -can be used later on to match documents defined on the `percolate` query. +The `query` field is used for indexing the query documents. It will hold a +json object that represents an actual Elasticsearch query. The `query` field +has been configured to use the <>. This field +type understands the query dsl and stored the query in such a way that it can be +used later on to match documents defined on the `percolate` query. Register a query in the percolator: [source,js] -------------------------------------------------- -PUT /my-index/queries/1?refresh +PUT /my-index/doc/1?refresh { "query" : { "match" : { @@ -72,7 +65,7 @@ GET /my-index/_search "query" : { "percolate" : { "field" : "query", - "document_type" : "doctype", + "document_type" : "doc", "document" : { "message" : "A new bonsai tree in the office" } @@ -101,7 +94,7 @@ The above request will yield the following response: "hits": [ { <1> "_index": "my-index", - "_type": "queries", + "_type": "doc", "_id": "1", "_score": 0.5716521, "_source": { @@ -159,7 +152,7 @@ Index the document we want to percolate: [source,js] -------------------------------------------------- -PUT /my-index/message/1 +PUT /my-index/doc/2 { "message" : "A new bonsai tree in the office" } @@ -172,8 +165,8 @@ Index response: -------------------------------------------------- { "_index": "my-index", - "_type": "message", - "_id": "1", + "_type": "doc", + "_id": "2", "_version": 1, "_shards": { "total": 2, @@ -182,7 +175,7 @@ Index response: }, "created": true, "result": "created", - "_seq_no" : 1, + "_seq_no" : 0, "_primary_term" : 1 } -------------------------------------------------- @@ -197,10 +190,10 @@ GET /my-index/_search "query" : { "percolate" : { "field": "query", - "document_type" : "doctype", + "document_type" : "doc", "index" : "my-index", - "type" : "message", - "id" : "1", + "type" : "doc", + "id" : "2", "version" : 1 <1> } } @@ -231,7 +224,7 @@ Save a query: [source,js] -------------------------------------------------- -PUT /my-index/queries/1?refresh +PUT /my-index/doc/3?refresh { "query" : { "match" : { @@ -247,7 +240,7 @@ Save another query: [source,js] -------------------------------------------------- -PUT /my-index/queries/2?refresh +PUT /my-index/doc/4?refresh { "query" : { "match" : { @@ -268,7 +261,7 @@ GET /my-index/_search "query" : { "percolate" : { "field": "query", - "document_type" : "doctype", + "document_type" : "doc", "document" : { "message" : "The quick brown fox jumps over the lazy dog" } @@ -302,8 +295,8 @@ This will yield the following response. "hits": [ { "_index": "my-index", - "_type": "queries", - "_id": "2", + "_type": "doc", + "_id": "4", "_score": 0.5446649, "_source": { "query": { @@ -320,8 +313,8 @@ This will yield the following response. }, { "_index": "my-index", - "_type": "queries", - "_id": "1", + "_type": "doc", + "_id": "3", "_score": 0.5446649, "_source": { "query": { diff --git a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java index b0cbc70a676..190a7745add 100644 --- a/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java +++ b/modules/lang-expression/src/test/java/org/elasticsearch/script/expression/MoreExpressionTests.java @@ -670,10 +670,10 @@ public class MoreExpressionTests extends ESIntegTestCase { } public void testBoolean() throws Exception { - XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("type1") + XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().startObject().startObject("doc") .startObject("properties").startObject("vip").field("type", "boolean"); xContentBuilder.endObject().endObject().endObject().endObject(); - assertAcked(prepareCreate("test").addMapping("type1", xContentBuilder)); + assertAcked(prepareCreate("test").addMapping("doc", xContentBuilder)); ensureGreen(); indexRandom(true, client().prepareIndex("test", "doc", "1").setSource("price", 1.0, "vip", true), diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java index d123b2f307e..15065d441ad 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/SearchTemplateIT.java @@ -56,10 +56,10 @@ public class SearchTemplateIT extends ESSingleNodeTestCase { @Before public void setup() throws IOException { createIndex("test"); - client().prepareIndex("test", "testtype", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("text", "value1").endObject()) .get(); - client().prepareIndex("test", "testtype", "2") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("text", "value2").endObject()) .get(); client().admin().indices().prepareRefresh().get(); diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/CandidateQueryTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/CandidateQueryTests.java index 8c594a0545f..05c8889f323 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/CandidateQueryTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/CandidateQueryTests.java @@ -127,12 +127,11 @@ public class CandidateQueryTests extends ESSingleNodeTestCase { documentMapper = mapperService.merge("type", new CompressedXContent(mapper), MapperService.MergeReason.MAPPING_UPDATE, true); String queryField = "query_field"; - String mappingType = "query"; - String percolatorMapper = XContentFactory.jsonBuilder().startObject().startObject(mappingType) + String percolatorMapper = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject(queryField).field("type", "percolator").endObject().endObject() .endObject().endObject().string(); - mapperService.merge(mappingType, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true); - fieldMapper = (PercolatorFieldMapper) mapperService.documentMapper(mappingType).mappers().getMapper(queryField); + mapperService.merge("type", new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true); + fieldMapper = (PercolatorFieldMapper) mapperService.documentMapper("type").mappers().getMapper(queryField); fieldType = (PercolatorFieldMapper.FieldType) fieldMapper.fieldType(); queries = new ArrayList<>(); diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java index d8f246b74ef..ae585dc9dc7 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java @@ -52,6 +52,7 @@ import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.SourceToParse; +import org.elasticsearch.index.mapper.MapperService.MergeReason; import org.elasticsearch.index.query.BoolQueryBuilder; import org.elasticsearch.index.query.BoostingQueryBuilder; import org.elasticsearch.index.query.ConstantScoreQueryBuilder; @@ -113,7 +114,7 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase { @Before public void init() throws Exception { - indexService = createIndex("test", Settings.EMPTY); + indexService = createIndex("test", Settings.builder().put("mapping.single_type", false).build()); mapperService = indexService.mapperService(); String mapper = XContentFactory.jsonBuilder().startObject().startObject("type") diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java index 5760b260b01..382fbcb3cf7 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java @@ -113,17 +113,16 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testPercolatorQuery() throws Exception { createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "field1", "type=keyword", "field2", "type=keyword") - .addMapping("queries", "query", "type=percolator") + .addMapping("type", "field1", "type=keyword", "field2", "type=keyword", "query", "type=percolator") ); - client().prepareIndex("test", "queries", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) .get(); - client().prepareIndex("test", "queries", "2") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "value")).endObject()) .get(); - client().prepareIndex("test", "queries", "3") + client().prepareIndex("test", "type", "3") .setSource(jsonBuilder().startObject().field("query", boolQuery() .must(matchQuery("field1", "value")) .must(matchQuery("field2", "value")) @@ -162,45 +161,44 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testPercolatorRangeQueries() throws Exception { createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "field1", "type=long", "field2", "type=double", "field3", "type=ip") - .addMapping("queries", "query", "type=percolator") + .addMapping("type", "field1", "type=long", "field2", "type=double", "field3", "type=ip", "query", "type=percolator") ); - client().prepareIndex("test", "queries", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("query", rangeQuery("field1").from(10).to(12)).endObject()) .get(); - client().prepareIndex("test", "queries", "2") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", rangeQuery("field1").from(20).to(22)).endObject()) .get(); - client().prepareIndex("test", "queries", "3") + client().prepareIndex("test", "type", "3") .setSource(jsonBuilder().startObject().field("query", boolQuery() .must(rangeQuery("field1").from(10).to(12)) .must(rangeQuery("field1").from(12).to(14)) ).endObject()).get(); client().admin().indices().prepareRefresh().get(); - client().prepareIndex("test", "queries", "4") + client().prepareIndex("test", "type", "4") .setSource(jsonBuilder().startObject().field("query", rangeQuery("field2").from(10).to(12)).endObject()) .get(); - client().prepareIndex("test", "queries", "5") + client().prepareIndex("test", "type", "5") .setSource(jsonBuilder().startObject().field("query", rangeQuery("field2").from(20).to(22)).endObject()) .get(); - client().prepareIndex("test", "queries", "6") + client().prepareIndex("test", "type", "6") .setSource(jsonBuilder().startObject().field("query", boolQuery() .must(rangeQuery("field2").from(10).to(12)) .must(rangeQuery("field2").from(12).to(14)) ).endObject()).get(); client().admin().indices().prepareRefresh().get(); - client().prepareIndex("test", "queries", "7") + client().prepareIndex("test", "type", "7") .setSource(jsonBuilder().startObject() .field("query", rangeQuery("field3").from("192.168.1.0").to("192.168.1.5")) .endObject()) .get(); - client().prepareIndex("test", "queries", "8") + client().prepareIndex("test", "type", "8") .setSource(jsonBuilder().startObject() .field("query", rangeQuery("field3").from("192.168.1.20").to("192.168.1.30")) .endObject()) .get(); - client().prepareIndex("test", "queries", "9") + client().prepareIndex("test", "type", "9") .setSource(jsonBuilder().startObject().field("query", boolQuery() .must(rangeQuery("field3").from("192.168.1.0").to("192.168.1.5")) .must(rangeQuery("field3").from("192.168.1.5").to("192.168.1.10")) @@ -258,25 +256,24 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testPercolatorQueryExistingDocument() throws Exception { createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "field1", "type=keyword", "field2", "type=keyword") - .addMapping("queries", "query", "type=percolator") + .addMapping("type", "field1", "type=keyword", "field2", "type=keyword", "query", "type=percolator") ); - client().prepareIndex("test", "queries", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) .get(); - client().prepareIndex("test", "queries", "2") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "value")).endObject()) .get(); - client().prepareIndex("test", "queries", "3") + client().prepareIndex("test", "type", "3") .setSource(jsonBuilder().startObject().field("query", boolQuery() .must(matchQuery("field1", "value")) .must(matchQuery("field2", "value")) ).endObject()).get(); - client().prepareIndex("test", "type", "1").setSource("{}", XContentType.JSON).get(); - client().prepareIndex("test", "type", "2").setSource("field1", "value").get(); - client().prepareIndex("test", "type", "3").setSource("field1", "value", "field2", "value").get(); + client().prepareIndex("test", "type", "4").setSource("{}", XContentType.JSON).get(); + client().prepareIndex("test", "type", "5").setSource("field1", "value").get(); + client().prepareIndex("test", "type", "6").setSource("field1", "value", "field2", "value").get(); client().admin().indices().prepareRefresh().get(); logger.info("percolating empty doc"); @@ -288,7 +285,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { logger.info("percolating doc with 1 field"); response = client().prepareSearch() - .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "2", null, null, null)) + .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "5", null, null, null)) .addSort("_uid", SortOrder.ASC) .get(); assertHitCount(response, 2); @@ -297,7 +294,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { logger.info("percolating doc with 2 fields"); response = client().prepareSearch() - .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "3", null, null, null)) + .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "6", null, null, null)) .addSort("_uid", SortOrder.ASC) .get(); assertHitCount(response, 3); @@ -308,15 +305,14 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testPercolatorQueryExistingDocumentSourceDisabled() throws Exception { createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "_source", "enabled=false", "field1", "type=keyword") - .addMapping("queries", "query", "type=percolator") + .addMapping("type", "_source", "enabled=false", "field1", "type=keyword", "query", "type=percolator") ); - client().prepareIndex("test", "queries", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) .get(); - client().prepareIndex("test", "type", "1").setSource("{}", XContentType.JSON).get(); + client().prepareIndex("test", "type", "2").setSource("{}", XContentType.JSON).get(); client().admin().indices().prepareRefresh().get(); logger.info("percolating empty doc with source disabled"); @@ -331,18 +327,17 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testPercolatorSpecificQueries() throws Exception { createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "field1", "type=text", "field2", "type=text") - .addMapping("queries", "query", "type=percolator") + .addMapping("type", "field1", "type=text", "field2", "type=text", "query", "type=percolator") ); - client().prepareIndex("test", "queries", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("query", commonTermsQuery("field1", "quick brown fox")).endObject()) .get(); - client().prepareIndex("test", "queries", "2") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", multiMatchQuery("quick brown fox", "field1", "field2") .type(MultiMatchQueryBuilder.Type.CROSS_FIELDS)).endObject()) .get(); - client().prepareIndex("test", "queries", "3") + client().prepareIndex("test", "type", "3") .setSource(jsonBuilder().startObject().field("query", spanNearQuery(spanTermQuery("field1", "quick"), 0) .addClause(spanTermQuery("field1", "brown")) @@ -352,7 +347,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { .get(); client().admin().indices().prepareRefresh().get(); - client().prepareIndex("test", "queries", "4") + client().prepareIndex("test", "type", "4") .setSource(jsonBuilder().startObject().field("query", spanNotQuery( spanNearQuery(spanTermQuery("field1", "quick"), 0) @@ -367,7 +362,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { .get(); // doesn't match - client().prepareIndex("test", "queries", "5") + client().prepareIndex("test", "type", "5") .setSource(jsonBuilder().startObject().field("query", spanNotQuery( spanNearQuery(spanTermQuery("field1", "quick"), 0) @@ -410,22 +405,21 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { fieldMapping.append(",index_options=offsets"); } createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "field1", fieldMapping) - .addMapping("queries", "query", "type=percolator") + .addMapping("type", "field1", fieldMapping, "query", "type=percolator") ); - client().prepareIndex("test", "queries", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "brown fox")).endObject()) .execute().actionGet(); - client().prepareIndex("test", "queries", "2") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "lazy dog")).endObject()) .execute().actionGet(); - client().prepareIndex("test", "queries", "3") + client().prepareIndex("test", "type", "3") .setSource(jsonBuilder().startObject().field("query", termQuery("field1", "jumps")).endObject()) .execute().actionGet(); - client().prepareIndex("test", "queries", "4") + client().prepareIndex("test", "type", "4") .setSource(jsonBuilder().startObject().field("query", termQuery("field1", "dog")).endObject()) .execute().actionGet(); - client().prepareIndex("test", "queries", "5") + client().prepareIndex("test", "type", "5") .setSource(jsonBuilder().startObject().field("query", termQuery("field1", "fox")).endObject()) .execute().actionGet(); client().admin().indices().prepareRefresh().get(); @@ -454,14 +448,13 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testTakePositionOffsetGapIntoAccount() throws Exception { createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "field", "type=text,position_increment_gap=5") - .addMapping("queries", "query", "type=percolator") + .addMapping("type", "field", "type=text,position_increment_gap=5", "query", "type=percolator") ); - client().prepareIndex("test", "queries", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("query", new MatchPhraseQueryBuilder("field", "brown fox").slop(4)).endObject()) .get(); - client().prepareIndex("test", "queries", "2") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", new MatchPhraseQueryBuilder("field", "brown fox").slop(5)).endObject()) .get(); @@ -478,6 +471,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testManyPercolatorFields() throws Exception { String queryFieldName = randomAlphaOfLength(8); createIndex("test", client().admin().indices().prepareCreate("test") + .setSettings("index.mapping.single_type", false) .addMapping("doc_type", "field", "type=keyword") .addMapping("query_type1", queryFieldName, "type=percolator") .addMapping("query_type2", queryFieldName, "type=percolator", "second_query_field", "type=percolator") @@ -498,9 +492,11 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testWithMultiplePercolatorFields() throws Exception { String queryFieldName = randomAlphaOfLength(8); createIndex("test1", client().admin().indices().prepareCreate("test1") + .setSettings("index.mapping.single_type", false) .addMapping("doc_type", "field", "type=keyword") .addMapping("query_type", queryFieldName, "type=percolator")); createIndex("test2", client().admin().indices().prepareCreate("test2") + .setSettings("index.mapping.single_type", false) .addMapping("doc_type", "field", "type=keyword") .addMapping("query_type", jsonBuilder().startObject().startObject("query_type").startObject("properties") .startObject("object_field") @@ -560,21 +556,20 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testPercolateQueryWithNestedDocuments() throws Exception { XContentBuilder mapping = XContentFactory.jsonBuilder(); - mapping.startObject().startObject("properties").startObject("companyname").field("type", "text").endObject() - .startObject("employee").field("type", "nested").startObject("properties") - .startObject("name").field("type", "text").endObject().endObject().endObject().endObject() + mapping.startObject().startObject("properties").startObject("query").field("type", "percolator").endObject() + .startObject("companyname").field("type", "text").endObject().startObject("employee").field("type", "nested") + .startObject("properties").startObject("name").field("type", "text").endObject().endObject().endObject().endObject() .endObject(); createIndex("test", client().admin().indices().prepareCreate("test") .addMapping("employee", mapping) - .addMapping("queries", "query", "type=percolator") ); - client().prepareIndex("test", "queries", "q1").setSource(jsonBuilder().startObject() + client().prepareIndex("test", "employee", "q1").setSource(jsonBuilder().startObject() .field("query", QueryBuilders.nestedQuery("employee", QueryBuilders.matchQuery("employee.name", "virginia potts").operator(Operator.AND), ScoreMode.Avg) ).endObject()) .get(); // this query should never match as it doesn't use nested query: - client().prepareIndex("test", "queries", "q2").setSource(jsonBuilder().startObject() + client().prepareIndex("test", "employee", "q2").setSource(jsonBuilder().startObject() .field("query", QueryBuilders.matchQuery("employee.name", "virginia")).endObject()) .get(); client().admin().indices().prepareRefresh().get(); @@ -730,26 +725,25 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { public void testPercolatorQueryViaMultiSearch() throws Exception { createIndex("test", client().admin().indices().prepareCreate("test") - .addMapping("type", "field1", "type=text") - .addMapping("queries", "query", "type=percolator") + .addMapping("type", "field1", "type=text", "query", "type=percolator") ); - client().prepareIndex("test", "queries", "1") + client().prepareIndex("test", "type", "1") .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "b")).field("a", "b").endObject()) .execute().actionGet(); - client().prepareIndex("test", "queries", "2") + client().prepareIndex("test", "type", "2") .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "c")).endObject()) .execute().actionGet(); - client().prepareIndex("test", "queries", "3") + client().prepareIndex("test", "type", "3") .setSource(jsonBuilder().startObject().field("query", boolQuery() .must(matchQuery("field1", "b")) .must(matchQuery("field1", "c")) ).endObject()) .execute().actionGet(); - client().prepareIndex("test", "queries", "4") + client().prepareIndex("test", "type", "4") .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) .execute().actionGet(); - client().prepareIndex("test", "type", "1") + client().prepareIndex("test", "type", "5") .setSource(jsonBuilder().startObject().field("field1", "c").endObject()) .execute().actionGet(); client().admin().indices().prepareRefresh().get(); @@ -768,9 +762,9 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { .setQuery(new PercolateQueryBuilder("query", "type", jsonBuilder().startObject().field("field1", "d").endObject().bytes(), XContentType.JSON))) .add(client().prepareSearch("test") - .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "1", null, null, null))) + .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "5", null, null, null))) .add(client().prepareSearch("test") // non existing doc, so error element - .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "2", null, null, null))) + .setQuery(new PercolateQueryBuilder("query", "type", "test", "type", "6", null, null, null))) .get(); MultiSearchResponse.Item item = response.getResponses()[0]; @@ -803,7 +797,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { assertThat(item.getFailureMessage(), notNullValue()); assertThat(item.getFailureMessage(), equalTo("all shards failed")); assertThat(ExceptionsHelper.unwrapCause(item.getFailure().getCause()).getMessage(), - containsString("[test/type/2] couldn't be found")); + containsString("[test/type/6] couldn't be found")); } } diff --git a/modules/percolator/src/test/resources/rest-api-spec/test/10_basic.yaml b/modules/percolator/src/test/resources/rest-api-spec/test/10_basic.yaml index d8f2b3264e8..2ef653f117d 100644 --- a/modules/percolator/src/test/resources/rest-api-spec/test/10_basic.yaml +++ b/modules/percolator/src/test/resources/rest-api-spec/test/10_basic.yaml @@ -5,19 +5,17 @@ index: queries_index body: mappings: - queries: + type: properties: query: type: percolator - test_type: - properties: foo: type: keyword - do: index: index: queries_index - type: queries + type: type id: test_percolator body: query: @@ -31,7 +29,7 @@ body: - query: percolate: - document_type: test_type + document_type: type field: query document: foo: bar @@ -43,7 +41,7 @@ - index: queries_index - query: percolate: - document_type: test_type + document_type: type field: query document: foo: bar diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java index e7f9994b904..c26984e09b6 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexBasicTests.java @@ -40,24 +40,25 @@ public class ReindexBasicTests extends ReindexTestCase { assertHitCount(client().prepareSearch("source").setSize(0).get(), 4); // Copy all the docs - ReindexRequestBuilder copy = reindex().source("source").destination("dest", "all").refresh(true); + ReindexRequestBuilder copy = reindex().source("source").destination("dest", "type").refresh(true); assertThat(copy.get(), matcher().created(4)); - assertHitCount(client().prepareSearch("dest").setTypes("all").setSize(0).get(), 4); + assertHitCount(client().prepareSearch("dest").setSize(0).get(), 4); // Now none of them - copy = reindex().source("source").destination("all", "none").filter(termQuery("foo", "no_match")).refresh(true); + createIndex("none"); + copy = reindex().source("source").destination("none", "type").filter(termQuery("foo", "no_match")).refresh(true); assertThat(copy.get(), matcher().created(0)); - assertHitCount(client().prepareSearch("dest").setTypes("none").setSize(0).get(), 0); + assertHitCount(client().prepareSearch("none").setSize(0).get(), 0); // Now half of them - copy = reindex().source("source").destination("dest", "half").filter(termQuery("foo", "a")).refresh(true); + copy = reindex().source("source").destination("dest_half", "type").filter(termQuery("foo", "a")).refresh(true); assertThat(copy.get(), matcher().created(2)); - assertHitCount(client().prepareSearch("dest").setTypes("half").setSize(0).get(), 2); + assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), 2); // Limit with size - copy = reindex().source("source").destination("dest", "size_one").size(1).refresh(true); + copy = reindex().source("source").destination("dest_size_one", "type").size(1).refresh(true); assertThat(copy.get(), matcher().created(1)); - assertHitCount(client().prepareSearch("dest").setTypes("size_one").setSize(0).get(), 1); + assertHitCount(client().prepareSearch("dest_size_one").setSize(0).get(), 1); } public void testCopyMany() throws Exception { @@ -71,20 +72,20 @@ public class ReindexBasicTests extends ReindexTestCase { assertHitCount(client().prepareSearch("source").setSize(0).get(), max); // Copy all the docs - ReindexRequestBuilder copy = reindex().source("source").destination("dest", "all").refresh(true); + ReindexRequestBuilder copy = reindex().source("source").destination("dest", "type").refresh(true); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); assertThat(copy.get(), matcher().created(max).batches(max, 5)); - assertHitCount(client().prepareSearch("dest").setTypes("all").setSize(0).get(), max); + assertHitCount(client().prepareSearch("dest").setSize(0).get(), max); // Copy some of the docs int half = max / 2; - copy = reindex().source("source").destination("dest", "half").refresh(true); + copy = reindex().source("source").destination("dest_half", "type").refresh(true); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); copy.size(half); // The real "size" of the request. assertThat(copy.get(), matcher().created(half).batches(half, 5)); - assertHitCount(client().prepareSearch("dest").setTypes("half").setSize(0).get(), half); + assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), half); } public void testCopyManyWithSlices() throws Exception { @@ -100,20 +101,20 @@ public class ReindexBasicTests extends ReindexTestCase { assertHitCount(client().prepareSearch("source").setSize(0).get(), max); // Copy all the docs - ReindexRequestBuilder copy = reindex().source("source").destination("dest", "all").refresh(true).setSlices(workers); + ReindexRequestBuilder copy = reindex().source("source").destination("dest", "type").refresh(true).setSlices(workers); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); assertThat(copy.get(), matcher().created(max).batches(greaterThanOrEqualTo(max / 5)).slices(hasSize(workers))); - assertHitCount(client().prepareSearch("dest").setTypes("all").setSize(0).get(), max); + assertHitCount(client().prepareSearch("dest").setTypes("type").setSize(0).get(), max); // Copy some of the docs int half = max / 2; - copy = reindex().source("source").destination("dest", "half").refresh(true).setSlices(workers); + copy = reindex().source("source").destination("dest_half", "type").refresh(true).setSlices(workers); // Use a small batch size so we have to use more than one batch copy.source().setSize(5); copy.size(half); // The real "size" of the request. BulkByScrollResponse response = copy.get(); assertThat(response, matcher().created(lessThanOrEqualTo((long) half)).slices(hasSize(workers))); - assertHitCount(client().prepareSearch("dest").setTypes("half").setSize(0).get(), response.getCreated()); + assertHitCount(client().prepareSearch("dest_half").setSize(0).get(), response.getCreated()); } } diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexParentChildTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexParentChildTests.java index c528de7694b..17769eeb4ea 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexParentChildTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/ReindexParentChildTests.java @@ -93,6 +93,7 @@ public class ReindexParentChildTests extends ReindexTestCase { */ private void createParentChildIndex(String indexName) throws Exception { CreateIndexRequestBuilder create = client().admin().indices().prepareCreate(indexName); + create.setSettings("index.mapping.single_type", false); create.addMapping("city", "{\"_parent\": {\"type\": \"country\"}}", XContentType.JSON); create.addMapping("neighborhood", "{\"_parent\": {\"type\": \"city\"}}", XContentType.JSON); assertAcked(create); diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/30_by_type.yaml b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/30_by_type.yaml index 1ee249fc6bb..4ed279a0165 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/30_by_type.yaml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/delete_by_query/30_by_type.yaml @@ -1,5 +1,12 @@ --- "Delete by type": + - do: + indices.create: + index: test + body: + settings: + mapping.single_type: false + - do: index: index: test diff --git a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yaml b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yaml index 8690d329d38..b30f263e869 100644 --- a/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yaml +++ b/modules/reindex/src/test/resources/rest-api-spec/test/reindex/90_remote.yaml @@ -164,6 +164,8 @@ indices.create: index: source body: + settings: + mapping.single_type: false mappings: foo: {} bar: @@ -173,6 +175,8 @@ indices.create: index: dest body: + settings: + mapping.single_type: false mappings: foo: {} bar: diff --git a/qa/smoke-test-reindex-with-painless/src/test/resources/rest-api-spec/test/reindex/10_script.yaml b/qa/smoke-test-reindex-with-painless/src/test/resources/rest-api-spec/test/reindex/10_script.yaml index a56eb036c6d..766e5ff3e7f 100644 --- a/qa/smoke-test-reindex-with-painless/src/test/resources/rest-api-spec/test/reindex/10_script.yaml +++ b/qa/smoke-test-reindex-with-painless/src/test/resources/rest-api-spec/test/reindex/10_script.yaml @@ -87,6 +87,8 @@ indices.create: index: new_twitter body: + settings: + mapping.single_type: false mappings: tweet: _parent: { type: "user" } @@ -186,6 +188,8 @@ indices.create: index: new_twitter body: + settings: + mapping.single_type: false mappings: tweet: _parent: { type: "user" } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.exists_type/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.exists_type/10_basic.yaml index fb0dad56798..92fe2776669 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.exists_type/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.exists_type/10_basic.yaml @@ -1,9 +1,15 @@ --- "Exists type": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.create: index: test_1 body: + settings: + mapping.single_type: false mappings: type_1: {} type_2: {} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_mapping/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_mapping/10_basic.yaml index 0881b03f744..37acc10a482 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_mapping/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_mapping/10_basic.yaml @@ -4,6 +4,8 @@ setup: indices.create: index: test_1 body: + settings: + mapping.single_type: false mappings: type_1: {} type_2: {} @@ -11,6 +13,8 @@ setup: indices.create: index: test_2 body: + settings: + mapping.single_type: false mappings: type_2: {} type_3: {} @@ -18,6 +22,10 @@ setup: --- "Get /_mapping": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: {} @@ -29,6 +37,10 @@ setup: --- "Get /{index}/_mapping": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: test_1 @@ -41,6 +53,10 @@ setup: --- "Get /{index}/_mapping/_all": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: test_1 @@ -53,6 +69,10 @@ setup: --- "Get /{index}/_mapping/*": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: test_1 @@ -65,6 +85,10 @@ setup: --- "Get /{index}/_mapping/{type}": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: test_1 @@ -77,6 +101,10 @@ setup: --- "Get /{index}/_mapping/{type,type}": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: test_1 @@ -89,6 +117,10 @@ setup: --- "Get /{index}/_mapping/{type*}": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: test_1 @@ -101,6 +133,10 @@ setup: --- "Get /_mapping/{type}": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: type: type_2 @@ -113,6 +149,10 @@ setup: --- "Get /_all/_mapping/{type}": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: _all @@ -126,6 +166,10 @@ setup: --- "Get /*/_mapping/{type}": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: '*' @@ -139,6 +183,10 @@ setup: --- "Get /index,index/_mapping/{type}": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: test_1,test_2 @@ -151,6 +199,10 @@ setup: --- "Get /index*/_mapping/{type}": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: indices.get_mapping: index: '*2' diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.sort/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.sort/10_basic.yaml index 705c2d6f2cb..679b4f4e535 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.sort/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.sort/10_basic.yaml @@ -14,7 +14,7 @@ number_of_replicas: 1 index.sort.field: rank mappings: - t: + test: properties: rank: type: integer diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/mget/15_ids.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/mget/15_ids.yaml index 87c08a3f616..17e6d5b57fd 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/mget/15_ids.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/mget/15_ids.yaml @@ -1,5 +1,16 @@ --- "IDs": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + + - do: + indices.create: + index: test_1 + body: + settings: + mapping.single_type: false + - do: index: index: test_1 diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/50_filter.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/50_filter.yaml index 63cca00509c..2bef1b6aa23 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/50_filter.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/50_filter.yaml @@ -7,12 +7,10 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: - post: + test: properties: mentions: type: keyword - user: - properties: notifications: type: keyword diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/70_adjacency_matrix.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/70_adjacency_matrix.yaml index 143ff9e3d13..dc018363bf4 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/70_adjacency_matrix.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.aggregation/70_adjacency_matrix.yaml @@ -7,7 +7,7 @@ setup: number_of_shards: 1 number_of_replicas: 0 mappings: - post: + test: properties: num: type: integer diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yaml index 100b44dcb04..d50c3dcb574 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search.inner_hits/10_basic.yaml @@ -4,6 +4,8 @@ setup: indices.create: index: test body: + settings: + mapping.single_type: false mappings: type_1: properties: @@ -16,6 +18,10 @@ setup: --- "Nested inner hits": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: index: index: test @@ -43,6 +49,10 @@ setup: --- "Parent/child inner hits": + - skip: + version: " - 5.99.99" + reason: mapping.single_type was added in 6.0 + - do: index: index: test diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java index cb271b25b3c..4cd321b4fb8 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractQueryTestCase.java @@ -181,7 +181,8 @@ public abstract class AbstractQueryTestCase> .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false) .build(); indexSettings = Settings.builder() - .put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated).build(); + .put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated) + .put("index.mapping.single_type", false).build(); index = new Index(randomAlphaOfLengthBetween(1, 10), "_na_");