From e97651e77783c9789d83a48bf5320e25774f5954 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 21 Jun 2017 12:12:41 +0200 Subject: [PATCH 1/4] Remove `index.mapping.single_type=false` from core/tests This change cleans up core tests to not use `index.mapping.single_type=false` but instead where applicable use a single type or markt the index as created with a pre 6.x version. Relates to #24961 --- .../action/bulk/BulkWithUpdatesIT.java | 8 +- .../metadata/MetaDataMappingServiceTests.java | 11 ++- .../gateway/RecoveryFromGatewayIT.java | 8 +- .../org/elasticsearch/get/GetActionIT.java | 15 +++- .../index/mapper/DocumentParserTests.java | 7 +- .../index/mapper/DynamicMappingIT.java | 25 +++++- .../index/mapper/IdFieldMapperTests.java | 7 +- .../index/mapper/IdFieldTypeTests.java | 8 +- .../index/mapper/MapperServiceTests.java | 15 +++- .../index/mapper/TypeFieldMapperTests.java | 7 +- .../index/mapper/TypeFieldTypeTests.java | 7 +- .../index/mapper/UidFieldMapperTests.java | 15 +++- .../index/mapper/UidFieldTypeTests.java | 7 +- .../indices/IndicesOptionsIntegrationIT.java | 6 +- .../indices/exists/types/TypesExistsIT.java | 13 ++- .../mapping/SimpleGetFieldMappingsIT.java | 23 +++-- .../indices/mapping/SimpleGetMappingsIT.java | 21 +++-- .../mapping/UpdateMappingIntegrationIT.java | 14 ++- .../indices/stats/IndexStatsIT.java | 25 ++++-- .../template/SimpleIndexTemplateIT.java | 37 ++++---- .../search/child/ParentFieldLoadingIT.java | 3 +- .../search/fetch/subphase/InnerHitsIT.java | 7 +- .../highlight/HighlighterSearchIT.java | 27 +++--- .../search/fields/SearchFieldsIT.java | 22 ++--- .../search/morelikethis/MoreLikeThisIT.java | 16 +++- .../search/query/SearchQueryIT.java | 85 ++++++++++++++----- .../java/org/elasticsearch/tribe/TribeIT.java | 19 +---- .../org/elasticsearch/update/UpdateIT.java | 5 +- 28 files changed, 309 insertions(+), 154 deletions(-) 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 cf41042ab8c78..615ed7db5db5b 100644 --- a/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java +++ b/core/src/test/java/org/elasticsearch/action/bulk/BulkWithUpdatesIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.bulk; +import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.delete.DeleteRequest; @@ -42,6 +43,7 @@ import org.elasticsearch.test.ESIntegTestCase; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -53,6 +55,8 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; import org.elasticsearch.script.ScriptType; +import org.elasticsearch.test.InternalSettingsPlugin; + import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; @@ -66,7 +70,7 @@ public class BulkWithUpdatesIT extends ESIntegTestCase { @Override protected Collection> nodePlugins() { - return Collections.singleton(CustomScriptPlugin.class); + return Arrays.asList(InternalSettingsPlugin.class, CustomScriptPlugin.class); } public static class CustomScriptPlugin extends MockScriptPlugin { @@ -457,7 +461,7 @@ public void testBulkIndexingWhileInitializing() throws Exception { */ public void testBulkUpdateChildMissingParentRouting() throws Exception { assertAcked(prepareCreate("test") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) // allows for multiple types .addMapping("parent", "{\"parent\":{}}", XContentType.JSON) .addMapping("child", "{\"child\": {\"_parent\": {\"type\": \"parent\"}}}", XContentType.JSON)); ensureGreen(); 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 13f7549973dbc..3cce782a898d8 100644 --- a/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/metadata/MetaDataMappingServiceTests.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.cluster.metadata; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.service.ClusterService; @@ -27,8 +28,11 @@ import org.elasticsearch.index.IndexService; import org.elasticsearch.index.mapper.DocumentMapper; import org.elasticsearch.index.mapper.MapperParsingException; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; +import java.util.Collection; import java.util.Collections; import static org.hamcrest.Matchers.equalTo; @@ -36,6 +40,11 @@ public class MetaDataMappingServiceTests extends ESSingleNodeTestCase { + @Override + protected Collection> getPlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + // Tests _parent meta field logic, because part of the validation is in MetaDataMappingService public void testAddChildTypePointingToAlreadyExistingType() throws Exception { createIndex("test", Settings.EMPTY, "type", "field", "type=keyword"); @@ -54,7 +63,7 @@ public void testAddChildTypePointingToAlreadyExistingType() throws Exception { // 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) + .setSettings("index.version.created", Version.V_5_6_0.id) .addMapping("parent") .addMapping("child1", "_parent", "type=parent") ); diff --git a/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java b/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java index 4210f9c32c17f..d2f5f943ff1c9 100644 --- a/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java +++ b/core/src/test/java/org/elasticsearch/gateway/RecoveryFromGatewayIT.java @@ -318,7 +318,7 @@ public void testLatestVersionLoaded() throws Exception { // 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)); + assertAcked(client().admin().indices().prepareCreate("test")); 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(); @@ -350,10 +350,7 @@ public void testLatestVersionLoaded() throws Exception { assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 3); } - logger.info("--> add some metadata, additional type and template"); - client().admin().indices().preparePutMapping("test").setType("type2") - .setSource(jsonBuilder().startObject().startObject("type2").endObject().endObject()) - .execute().actionGet(); + logger.info("--> add some metadata and additional template"); client().admin().indices().preparePutTemplate("template_1") .setTemplate("te*") .setOrder(0) @@ -381,7 +378,6 @@ public void testLatestVersionLoaded() throws Exception { } ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState(); - assertThat(state.metaData().index("test").mapping("type2"), notNullValue()); assertThat(state.metaData().templates().get("template_1").patterns(), equalTo(Collections.singletonList("te*"))); assertThat(state.metaData().index("test").getAliases().get("test_alias"), notNullValue()); assertThat(state.metaData().index("test").getAliases().get("test_alias").filter(), notNullValue()); diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java index e6439011cf6ee..7e5180f864143 100644 --- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -20,6 +20,7 @@ package org.elasticsearch.get; import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.indices.alias.Alias; @@ -38,9 +39,12 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.engine.VersionConflictEngineException; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Set; @@ -58,6 +62,11 @@ public class GetActionIT extends ESIntegTestCase { + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testSimpleGet() { assertAcked(prepareCreate("test") .addMapping("type1", "field1", "type=keyword,store=true", "field2", "type=keyword,store=true") @@ -254,7 +263,7 @@ public void testGetDocWithMultivaluedFields() throws Exception { assertAcked(prepareCreate("test") .addMapping("type1", mapping1, XContentType.JSON) .addMapping("type2", mapping2, XContentType.JSON) - .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false)); + .setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id)); // multi types in 5.6 ensureGreen(); GetResponse response = client().prepareGet("test", "type1", "1").get(); @@ -529,7 +538,7 @@ public void testGetFieldsMetaData() throws Exception { .addMapping("parent") .addMapping("my-type1", "_parent", "type=parent", "field1", "type=keyword,store=true") .addAlias(new Alias("alias")) - .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false)); + .setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id)); // multi types in 5.6 client().prepareIndex("test", "my-type1", "1") .setRouting("1") @@ -593,7 +602,7 @@ public void testGetFieldsNonLeafField() throws Exception { public void testGetFieldsComplexField() throws Exception { assertAcked(prepareCreate("my-index") - .setSettings("index.refresh_interval", -1, "index.mapping.single_type", false) + .setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id) // multi types in 5.6 .addMapping("my-type2", jsonBuilder().startObject().startObject("my-type2").startObject("properties") .startObject("field1").field("type", "object").startObject("properties") .startObject("field2").field("type", "object").startObject("properties") diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index d3d099672bac3..366b5db92d2e4 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -151,11 +151,10 @@ public void testDotsWithDynamicNestedMapper() throws Exception { public void testNestedHaveIdAndTypeFields() throws Exception { DocumentMapperParser mapperParser1 = createIndex("index1", Settings.builder() - .put("index.mapping.single_type", false).build() - ).mapperService().documentMapperParser(); - DocumentMapperParser mapperParser2 = createIndex("index2", Settings.builder() - .put("index.mapping.single_type", true).build() + .put("index.version.created", Version.V_5_6_0) // allows for multiple types + .build() ).mapperService().documentMapperParser(); + DocumentMapperParser mapperParser2 = createIndex("index2").mapperService().documentMapperParser(); XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties"); { 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 084f5f19bd1f4..d183242ee19fe 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.index.mapper; +import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; @@ -28,9 +29,12 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.TypeMissingException; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; +import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.concurrent.CountDownLatch; @@ -42,6 +46,11 @@ public class DynamicMappingIT extends ESIntegTestCase { + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testConflictingDynamicMappings() { // we don't use indexRandom because the order of requests is important here createIndex("index"); @@ -75,7 +84,21 @@ private static void assertMappingsHaveField(GetMappingsResponse mappings, String } public void testMappingsPropagatedToMasterNodeImmediately() throws IOException { - assertAcked(prepareCreate("index").setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate("index")); + + // works when the type has been dynamically created + client().prepareIndex("index", "type", "1").setSource("foo", 3).get(); + GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get(); + assertMappingsHaveField(mappings, "index", "type", "foo"); + + // works if the type already existed + client().prepareIndex("index", "type", "1").setSource("bar", "baz").get(); + mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get(); + assertMappingsHaveField(mappings, "index", "type", "bar"); + } + + public void testMappingsPropagatedToMasterNodeImmediatelyMultiType() throws IOException { + assertAcked(prepareCreate("index").setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types // 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/IdFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java index 185f1c51d2e91..a4bf903ef6411 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java @@ -22,6 +22,7 @@ import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; +import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.settings.Settings; @@ -51,7 +52,7 @@ public void testIncludeInObjectNotAllowed() throws Exception { public void testDefaultsMultipleTypes() throws IOException { Settings indexSettings = Settings.builder() - .put("index.mapping.single_type", false) + .put("index.version.created", Version.V_5_6_0) .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); @@ -60,9 +61,7 @@ public void testDefaultsMultipleTypes() throws IOException { } public void testDefaultsSingleType() throws IOException { - Settings indexSettings = Settings.builder() - .put("index.mapping.single_type", true) - .build(); + Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java index 2209027c12f37..95b8b0daa48b1 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldTypeTests.java @@ -49,11 +49,10 @@ public void testRangeQuery() { public void testTermsQueryWhenTypesAreEnabled() throws Exception { QueryShardContext context = Mockito.mock(QueryShardContext.class); Settings indexSettings = Settings.builder() - .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0) // allows for multiple types .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) - .put("index.mapping.single_type", false).build(); + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build(); IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); Mockito.when(context.getIndexSettings()).thenReturn(mockSettings); @@ -80,8 +79,7 @@ public void testTermsQueryWhenTypesAreDisabled() throws Exception { .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) - .put("index.mapping.single_type", true).build(); + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build(); IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); Mockito.when(context.getIndexSettings()).thenReturn(mockSettings); 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 cb0b922e19703..26049bd9103af 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/MapperServiceTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.mapper; import org.elasticsearch.ExceptionsHelper; +import org.elasticsearch.Version; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; @@ -28,12 +29,15 @@ import org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType; import org.elasticsearch.index.mapper.MapperService.MergeReason; import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import org.hamcrest.Matchers; import java.io.IOException; import java.io.UncheckedIOException; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -48,6 +52,11 @@ public class MapperServiceTests extends ESSingleNodeTestCase { + @Override + protected Collection> getPlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testTypeNameStartsWithIllegalDot() { String index = "test-index"; String type = ".test-type"; @@ -74,7 +83,8 @@ public void testTypeNameTooLong() { } public void testTypes() throws Exception { - IndexService indexService1 = createIndex("index1", Settings.builder().put("index.mapping.single_type", false).build()); + IndexService indexService1 = createIndex("index1", Settings.builder().put("index.version.created", Version.V_5_6_0) // multi types + .build()); MapperService mapperService = indexService1.mapperService(); assertEquals(Collections.emptySet(), mapperService.types()); @@ -207,7 +217,8 @@ public void testMergeParentTypesSame() { } public void testOtherDocumentMappersOnlyUpdatedWhenChangingFieldType() throws IOException { - IndexService indexService = createIndex("test", Settings.builder().put("index.mapping.single_type", false).build()); + IndexService indexService = createIndex("test", + Settings.builder().put("index.version.created", Version.V_5_6_0).build()); // multiple types CompressedXContent simpleMapping = new CompressedXContent(XContentFactory.jsonBuilder().startObject() .startObject("properties") diff --git a/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java index d3091ac3459bb..3bbd4e8146527 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldMapperTests.java @@ -27,6 +27,7 @@ import org.apache.lucene.index.SortedSetDocValues; import org.apache.lucene.store.Directory; import org.apache.lucene.util.BytesRef; +import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.settings.Settings; @@ -89,7 +90,7 @@ public void testDocValues(boolean singleType) throws IOException { public void testDefaultsMultipleTypes() throws IOException { Settings indexSettings = Settings.builder() - .put("index.mapping.single_type", false) + .put("index.version.created", Version.V_5_6_0) .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); @@ -100,9 +101,7 @@ public void testDefaultsMultipleTypes() throws IOException { } public void testDefaultsSingleType() throws IOException { - Settings indexSettings = Settings.builder() - .put("index.mapping.single_type", true) - .build(); + Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldTypeTests.java index b8a2805efe9bb..8f64e051929de 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/TypeFieldTypeTests.java @@ -62,8 +62,7 @@ public void testTermsQueryWhenTypesAreDisabled() throws Exception { .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) - .put("index.mapping.single_type", true).build(); + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build(); IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); Mockito.when(context.getIndexSettings()).thenReturn(mockSettings); @@ -100,11 +99,11 @@ public void testTermsQueryWhenTypesAreEnabled() throws Exception { QueryShardContext context = Mockito.mock(QueryShardContext.class); Settings indexSettings = Settings.builder() - .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0) // to allow for multiple types .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) - .put("index.mapping.single_type", false).build(); + .build(); IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); Mockito.when(context.getIndexSettings()).thenReturn(mockSettings); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java index e5503738f0686..c5816de2e1920 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/UidFieldMapperTests.java @@ -21,22 +21,31 @@ import org.apache.lucene.index.IndexOptions; import org.apache.lucene.index.IndexableField; +import org.elasticsearch.Version; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.mapper.MapperService.MergeReason; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; public class UidFieldMapperTests extends ESSingleNodeTestCase { + @Override + protected Collection> getPlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testDefaultsMultipleTypes() throws IOException { Settings indexSettings = Settings.builder() - .put("index.mapping.single_type", false) + .put("index.version.created", Version.V_5_6_0) .build(); MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); @@ -49,9 +58,7 @@ public void testDefaultsMultipleTypes() throws IOException { } public void testDefaultsSingleType() throws IOException { - Settings indexSettings = Settings.builder() - .put("index.mapping.single_type", true) - .build(); + Settings indexSettings = Settings.EMPTY; MapperService mapperService = createIndex("test", indexSettings).mapperService(); DocumentMapper mapper = mapperService.merge("type", new CompressedXContent("{\"type\":{}}"), MergeReason.MAPPING_UPDATE, false); ParsedDocument document = mapper.parse(SourceToParse.source("index", "type", "id", new BytesArray("{}"), XContentType.JSON)); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/UidFieldTypeTests.java b/core/src/test/java/org/elasticsearch/index/mapper/UidFieldTypeTests.java index 1a9a78f51cf2e..14de6e0d255d2 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/UidFieldTypeTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/UidFieldTypeTests.java @@ -52,11 +52,11 @@ public void testRangeQuery() { public void testTermsQueryWhenTypesAreEnabled() throws Exception { QueryShardContext context = Mockito.mock(QueryShardContext.class); Settings indexSettings = Settings.builder() - .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) + .put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_5_6_0) // to allow for multipel types .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) - .put("index.mapping.single_type", false).build(); + .build(); IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); Mockito.when(context.getIndexSettings()).thenReturn(mockSettings); @@ -78,8 +78,7 @@ public void testTermsQueryWhenTypesAreDisabled() throws Exception { .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()) - .put("index.mapping.single_type", true).build(); + .put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build(); IndexMetaData indexMetaData = IndexMetaData.builder(IndexMetaData.INDEX_UUID_NA_VALUE).settings(indexSettings).build(); IndexSettings mockSettings = new IndexSettings(indexMetaData, Settings.EMPTY); Mockito.when(context.getIndexSettings()).thenReturn(mockSettings); diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java index b776b13dae9c4..43066c454a50d 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.indices; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse; import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequestBuilder; @@ -48,6 +49,7 @@ import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import java.util.Arrays; import java.util.Collection; @@ -68,7 +70,7 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase { @Override protected Collection> nodePlugins() { - return Arrays.asList(TestPlugin.class); + return Arrays.asList(TestPlugin.class, InternalSettingsPlugin.class); } public void testSpecifiedIndexUnavailableMultipleIndices() throws Exception { @@ -564,7 +566,7 @@ public void testPutMapping() throws Exception { verify(client().admin().indices().preparePutMapping("_all").setType("type1").setSource("field", "type=text"), true); for (String index : Arrays.asList("foo", "foobar", "bar", "barbaz")) { - assertAcked(prepareCreate(index).setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate(index).setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types } verify(client().admin().indices().preparePutMapping("foo").setType("type1").setSource("field", "type=text"), false); 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 31e3ca8232609..506cdc812fc03 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 @@ -18,15 +18,20 @@ */ package org.elasticsearch.indices.exists.types; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.exists.types.TypesExistsResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_BLOCKS_READ; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_BLOCKS_WRITE; @@ -37,10 +42,16 @@ import static org.hamcrest.Matchers.equalTo; public class TypesExistsIT extends ESIntegTestCase { + + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testSimple() throws Exception { Client client = client(); CreateIndexResponse response1 = client.admin().indices().prepareCreate("test1") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .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 57f3ec29e3262..c259a8db21924 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java @@ -19,16 +19,21 @@ package org.elasticsearch.indices.mapping; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import org.hamcrest.Matchers; import java.io.IOException; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -48,6 +53,11 @@ public class SimpleGetFieldMappingsIT extends ESIntegTestCase { + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testGetMappingsWhereThereAreNone() { createIndex("index"); GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings().get(); @@ -67,11 +77,11 @@ private XContentBuilder getMappingForType(String type) throws IOException { public void testSimpleGetFieldMappings() throws Exception { assertAcked(prepareCreate("indexa") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB"))); assertAcked(client().admin().indices().prepareCreate("indexb") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB"))); @@ -186,15 +196,14 @@ public void testSimpleGetFieldMappingsWithPretty() throws Exception { public void testGetFieldMappingsWithBlocks() throws Exception { assertAcked(prepareCreate("test") - .setSettings("index.mapping.single_type", false) - .addMapping("typeA", getMappingForType("typeA")) - .addMapping("typeB", getMappingForType("typeB"))); + .addMapping("doc", getMappingForType("doc"))); for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY)) { try { enableIndexBlock("test", block); - GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("test").setTypes("typeA").setFields("field1", "obj.subfield").get(); - assertThat(response.fieldMappings("test", "typeA", "field1").fullName(), equalTo("field1")); + GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("test").setTypes("doc") + .setFields("field1", "obj.subfield").get(); + assertThat(response.fieldMappings("test", "doc", "field1").fullName(), equalTo("field1")); } finally { disableIndexBlock("test", block); } 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 89b0d48ef22df..d60e93d80c49b 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java @@ -19,15 +19,20 @@ package org.elasticsearch.indices.mapping; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.common.Priority; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import static org.elasticsearch.cluster.metadata.IndexMetaData.INDEX_METADATA_BLOCK; import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_BLOCKS_METADATA; @@ -41,6 +46,12 @@ @ClusterScope(randomDynamicTemplates = false) public class SimpleGetMappingsIT extends ESIntegTestCase { + + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testGetMappingsWhereThereAreNone() { createIndex("index"); GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet(); @@ -56,14 +67,14 @@ private XContentBuilder getMappingForType(String type) throws IOException { public void testSimpleGetMappings() throws Exception { client().admin().indices().prepareCreate("indexa") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .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) + .setSettings("index.version.created", Version.V_5_6_0.id) .addMapping("typeA", getMappingForType("typeA")) .addMapping("typeB", getMappingForType("typeB")) .addMapping("Atype", getMappingForType("Atype")) @@ -145,9 +156,7 @@ public void testSimpleGetMappings() throws Exception { public void testGetMappingsWithBlocks() throws IOException { client().admin().indices().prepareCreate("test") - .setSettings("index.mapping.single_type", false) - .addMapping("typeA", getMappingForType("typeA")) - .addMapping("typeB", getMappingForType("typeB")) + .addMapping("doc", getMappingForType("doc")) .execute().actionGet(); ensureGreen(); @@ -156,7 +165,7 @@ public void testGetMappingsWithBlocks() throws IOException { enableIndexBlock("test", block); GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet(); assertThat(response.mappings().size(), equalTo(1)); - assertThat(response.mappings().get("test").size(), equalTo(2)); + assertThat(response.mappings().get("test").size(), equalTo(1)); } finally { disableIndexBlock("test", block); } 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 d41ef16d77191..36000b6a0c0a9 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.indices.mapping; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; @@ -33,13 +34,17 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; +import org.elasticsearch.test.InternalSettingsPlugin; import org.hamcrest.Matchers; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.concurrent.CyclicBarrier; @@ -62,6 +67,11 @@ @ClusterScope(randomDynamicTemplates = false) public class UpdateMappingIntegrationIT extends ESIntegTestCase { + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testDynamicUpdates() throws Exception { client().admin().indices().prepareCreate("test") .setSettings( @@ -69,7 +79,7 @@ public void testDynamicUpdates() throws Exception { .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) + .put("index.version.created", Version.V_5_6_0) // for multiple types ).execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); @@ -343,7 +353,7 @@ public void testPutMappingsWithBlocks() throws Exception { public void testUpdateMappingOnAllTypes() throws IOException { assertAcked(prepareCreate("index") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .addMapping("type1", "f", "type=keyword").addMapping("type2", "f", "type=keyword")); assertAcked(client().admin().indices().preparePutMapping("index") 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 b0179a675dd93..73430c92c8c22 100644 --- a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java @@ -20,6 +20,7 @@ package org.elasticsearch.indices.stats; import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; +import org.elasticsearch.Version; import org.elasticsearch.action.DocWriteResponse; import org.elasticsearch.action.ShardOperationFailedException; import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; @@ -53,14 +54,18 @@ import org.elasticsearch.indices.IndicesQueryCache; import org.elasticsearch.indices.IndicesRequestCache; import org.elasticsearch.indices.IndicesService; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.test.ESIntegTestCase.Scope; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.EnumSet; import java.util.List; import java.util.Random; @@ -90,6 +95,12 @@ @ClusterScope(scope = Scope.SUITE, numDataNodes = 2, numClientNodes = 0, randomDynamicTemplates = false) @SuppressCodecs("*") // requires custom completion format public class IndexStatsIT extends ESIntegTestCase { + + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + @Override protected Settings nodeSettings(int nodeOrdinal) { //Filter/Query cache is cleaned periodically, default is 60s, so make sure it runs often. Thread.sleep for 60s is bad @@ -378,7 +389,7 @@ public void testThrottleStats() throws Exception { } public void testSimpleStats() throws Exception { - assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types createIndex("test2"); ensureGreen(); @@ -508,7 +519,7 @@ public void testSimpleStats() throws Exception { } public void testMergeStats() { - assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types ensureGreen(); @@ -545,7 +556,7 @@ public void testMergeStats() { public void testSegmentsStats() { assertAcked(prepareCreate("test1") - .setSettings(SETTING_NUMBER_OF_REPLICAS, between(0, 1), "index.mapping.single_type", false)); + .setSettings(SETTING_NUMBER_OF_REPLICAS, between(0, 1), "index.version.created", Version.V_5_6_0.id)); ensureGreen(); NumShards test1 = getNumShards("test1"); @@ -570,7 +581,7 @@ public void testSegmentsStats() { public void testAllFlags() throws Exception { // rely on 1 replica for this tests - assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); createIndex("test2"); ensureGreen(); @@ -692,7 +703,7 @@ public void testFlagOrdinalOrder() { } public void testMultiIndex() throws Exception { - assertAcked(prepareCreate("test1").setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); createIndex("test2"); ensureGreen(); @@ -732,7 +743,7 @@ public void testMultiIndex() throws Exception { public void testFieldDataFieldsParam() throws Exception { assertAcked(client().admin().indices().prepareCreate("test1") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .addMapping("type", "bar", "type=text,fielddata=true", "baz", "type=text,fielddata=true").get()); @@ -780,7 +791,7 @@ public void testFieldDataFieldsParam() throws Exception { public void testCompletionFieldsParam() throws Exception { assertAcked(prepareCreate("test1") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) // allows for multiple types .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 017026844f11d..901e2b37bf830 100644 --- a/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java +++ b/core/src/test/java/org/elasticsearch/indices/template/SimpleIndexTemplateIT.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.indices.template; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse; @@ -37,13 +38,16 @@ import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.indices.InvalidAliasNameException; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.search.SearchHit; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import org.junit.After; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -67,6 +71,11 @@ public class SimpleIndexTemplateIT extends ESIntegTestCase { + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + @After public void cleanupTemplates() { client().admin().indices().prepareDeleteTemplate("*").get(); @@ -383,7 +392,7 @@ public void testIndexTemplateWithAliases() throws Exception { .get(); assertAcked(prepareCreate("test_index") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) // allow for multiple version .addMapping("type1").addMapping("type2").addMapping("typeX").addMapping("typeY").addMapping("typeZ")); ensureGreen(); @@ -431,8 +440,8 @@ public void testIndexTemplateWithAliasesInSource() { " \"aliases\" : {\n" + " \"my_alias\" : {\n" + " \"filter\" : {\n" + - " \"type\" : {\n" + - " \"value\" : \"type2\"\n" + + " \"term\" : {\n" + + " \"field\" : \"value2\"\n" + " }\n" + " }\n" + " }\n" + @@ -441,16 +450,15 @@ public void testIndexTemplateWithAliasesInSource() { assertAcked(prepareCreate("test_index") - .setSettings("index.mapping.single_type", false) - .addMapping("type1").addMapping("type2")); + .addMapping("doc")); ensureGreen(); GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get(); assertThat(getAliasesResponse.getAliases().size(), equalTo(1)); assertThat(getAliasesResponse.getAliases().get("test_index").size(), equalTo(1)); - client().prepareIndex("test_index", "type1", "1").setSource("field", "value1").get(); - client().prepareIndex("test_index", "type2", "2").setSource("field", "value2").get(); + client().prepareIndex("test_index", "doc", "1").setSource("field", "value1").get(); + client().prepareIndex("test_index", "doc", "2").setSource("field", "value2").get(); refresh(); SearchResponse searchResponse = client().prepareSearch("test_index").get(); @@ -458,7 +466,7 @@ public void testIndexTemplateWithAliasesInSource() { searchResponse = client().prepareSearch("my_alias").get(); assertHitCount(searchResponse, 1L); - assertThat(searchResponse.getHits().getAt(0).getType(), equalTo("type2")); + assertThat(searchResponse.getHits().getAt(0).getSourceAsMap().get("field"), equalTo("value2")); } public void testIndexTemplateWithAliasesSource() { @@ -469,8 +477,8 @@ public void testIndexTemplateWithAliasesSource() { " \"alias1\" : {},\n" + " \"alias2\" : {\n" + " \"filter\" : {\n" + - " \"type\" : {\n" + - " \"value\" : \"type2\"\n" + + " \"term\" : {\n" + + " \"field\" : \"value2\"\n" + " }\n" + " }\n" + " },\n" + @@ -478,16 +486,15 @@ public void testIndexTemplateWithAliasesSource() { " }\n").get(); assertAcked(prepareCreate("test_index") - .setSettings("index.mapping.single_type", false) - .addMapping("type1").addMapping("type2")); + .addMapping("doc")); ensureGreen(); GetAliasesResponse getAliasesResponse = client().admin().indices().prepareGetAliases().setIndices("test_index").get(); assertThat(getAliasesResponse.getAliases().size(), equalTo(1)); assertThat(getAliasesResponse.getAliases().get("test_index").size(), equalTo(3)); - client().prepareIndex("test_index", "type1", "1").setSource("field", "value1").get(); - client().prepareIndex("test_index", "type2", "2").setSource("field", "value2").get(); + client().prepareIndex("test_index", "doc", "1").setSource("field", "value1").get(); + client().prepareIndex("test_index", "doc", "2").setSource("field", "value2").get(); refresh(); SearchResponse searchResponse = client().prepareSearch("test_index").get(); @@ -498,7 +505,7 @@ public void testIndexTemplateWithAliasesSource() { searchResponse = client().prepareSearch("alias2").get(); assertHitCount(searchResponse, 1L); - assertThat(searchResponse.getHits().getAt(0).getType(), equalTo("type2")); + assertThat(searchResponse.getHits().getAt(0).getSourceAsMap().get("field"), equalTo("value2")); } public void testDuplicateAlias() throws Exception { 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 45956deefd36f..cd15c9668348b 100644 --- a/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java +++ b/core/src/test/java/org/elasticsearch/search/child/ParentFieldLoadingIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.child; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse; import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.cluster.ClusterState; @@ -60,7 +61,7 @@ protected Collection> nodePlugins() { .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) + .put("index.version.created", Version.V_5_6_0) .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 8f092383a5b38..3742166a61b3a 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 @@ -21,6 +21,7 @@ import org.apache.lucene.search.join.ScoreMode; import org.apache.lucene.util.ArrayUtil; +import org.elasticsearch.Version; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.health.ClusterHealthStatus; @@ -40,8 +41,10 @@ import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -72,7 +75,7 @@ public class InnerHitsIT extends ESIntegTestCase { @Override protected Collection> nodePlugins() { - return Collections.singleton(CustomScriptPlugin.class); + return Arrays.asList(InternalSettingsPlugin.class, CustomScriptPlugin.class); } public static class CustomScriptPlugin extends MockScriptPlugin { @@ -591,7 +594,7 @@ public void testNestedSourceFiltering() throws Exception { public void testInnerHitsWithIgnoreUnmapped() throws Exception { assertAcked(prepareCreate("index1") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .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 2bc98b39dc238..fbd5a4616f6a0 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 @@ -20,6 +20,7 @@ import com.carrotsearch.randomizedtesting.generators.RandomPicks; import org.apache.lucene.search.join.ScoreMode; +import org.elasticsearch.Version; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -1358,14 +1359,13 @@ public void testCommonTermsTermVector() throws IOException { 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") .putArray("index.analysis.filter.synonym.synonyms", "quick => fast"); - assertAcked(prepareCreate("test").setSettings(builder.build()).addMapping("type1", type1TermVectorMapping()) - .addMapping("type2", + assertAcked(prepareCreate("test").setSettings(builder.build()).addMapping("type1", type1TermVectorMapping())); + assertAcked(prepareCreate("test1").setSettings(builder.build()).addMapping("type2", "field4", "type=text,term_vector=with_positions_offsets,analyzer=synonym", "field3", "type=text,analyzer=synonym")); ensureGreen(); @@ -1421,26 +1421,29 @@ public void testPhrasePrefix() throws IOException { equalTo("The quick brown fox jumps over the lazy dog"))); // with synonyms - client().prepareIndex("test", "type2", "0").setSource( + client().prepareIndex("test1", "type2", "0").setSource( + "type", "type2", "field4", "The quick brown fox jumps over the lazy dog", "field3", "The quick brown fox jumps over the lazy dog").get(); - client().prepareIndex("test", "type2", "1").setSource( + client().prepareIndex("test1", "type2", "1").setSource( + "type", "type2", "field4", "The quick browse button is a fancy thing, right bro?").get(); - client().prepareIndex("test", "type2", "2").setSource( + client().prepareIndex("test1", "type2", "2").setSource( + "type", "type2", "field4", "a quick fast blue car").get(); refresh(); - source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field3", "fast bro")) + source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field3", "fast bro")) .highlighter(highlight().field("field3").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test").source(source)).actionGet(); + searchResponse = client().search(searchRequest("test1").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field3", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); logger.info("--> highlighting and searching on field4"); - source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field4", "the fast bro")) + source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field4", "the fast bro")) .highlighter(highlight().field("field4").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test").source(source)).actionGet(); + searchResponse = client().search(searchRequest("test1").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf( equalTo("The quick browse button is a fancy thing, right bro?"), @@ -1450,9 +1453,9 @@ public void testPhrasePrefix() throws IOException { equalTo("The quick brown fox jumps over the lazy dog"))); logger.info("--> highlighting and searching on field4"); - source = searchSource().postFilter(typeQuery("type2")).query(matchPhrasePrefixQuery("field4", "a fast quick blue ca")) + source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field4", "a fast quick blue ca")) .highlighter(highlight().field("field4").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test").source(source)).actionGet(); + searchResponse = client().search(searchRequest("test1").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf(equalTo("a quick fast blue car"), 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 b33196cf005c5..770294d586e22 100644 --- a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java +++ b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.fields; +import org.elasticsearch.Version; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; @@ -43,6 +44,7 @@ import org.elasticsearch.search.lookup.FieldLookup; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.ReadableDateTime; @@ -81,7 +83,7 @@ public class SearchFieldsIT extends ESIntegTestCase { @Override protected Collection> nodePlugins() { - return Collections.singletonList(CustomScriptPlugin.class); + return Arrays.asList(InternalSettingsPlugin.class, CustomScriptPlugin.class); } public static class CustomScriptPlugin extends MockScriptPlugin { @@ -640,10 +642,9 @@ public void testSearchFieldsNonLeafField() throws Exception { public void testGetFieldsComplexField() throws Exception { client().admin().indices().prepareCreate("my-index") .setSettings("index.refresh_interval", -1) - .setSettings("index.mapping.single_type", false) - .addMapping("my-type2", jsonBuilder() + .addMapping("doc", jsonBuilder() .startObject() - .startObject("my-type2") + .startObject("doc") .startObject("properties") .startObject("field1") .field("type", "object") @@ -692,19 +693,12 @@ public void testGetFieldsComplexField() throws Exception { .endArray() .endObject().bytes(); - client().prepareIndex("my-index", "my-type1", "1").setSource(source, XContentType.JSON).get(); - client().prepareIndex("my-index", "my-type2", "1").setRefreshPolicy(IMMEDIATE).setSource(source, XContentType.JSON).get(); + client().prepareIndex("my-index", "doc", "1").setRefreshPolicy(IMMEDIATE).setSource(source, XContentType.JSON).get(); String field = "field1.field2.field3.field4"; - SearchResponse searchResponse = client().prepareSearch("my-index").setTypes("my-type1").addStoredField(field).get(); - assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); - assertThat(searchResponse.getHits().getAt(0).field(field).isMetadataField(), equalTo(false)); - assertThat(searchResponse.getHits().getAt(0).field(field).getValues().size(), equalTo(2)); - assertThat(searchResponse.getHits().getAt(0).field(field).getValues().get(0).toString(), equalTo("value1")); - assertThat(searchResponse.getHits().getAt(0).field(field).getValues().get(1).toString(), equalTo("value2")); - searchResponse = client().prepareSearch("my-index").setTypes("my-type2").addStoredField(field).get(); + SearchResponse searchResponse = client().prepareSearch("my-index").addStoredField(field).get(); assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L)); assertThat(searchResponse.getHits().getAt(0).field(field).isMetadataField(), equalTo(false)); assertThat(searchResponse.getHits().getAt(0).field(field).getValues().size(), equalTo(2)); @@ -872,7 +866,7 @@ public void testScriptFields() throws Exception { public void testLoadMetadata() throws Exception { assertAcked(prepareCreate("test") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .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 8d4f2921f27b9..d504df60b630b 100644 --- a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.morelikethis; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; @@ -32,10 +33,14 @@ import org.elasticsearch.index.query.MoreLikeThisQueryBuilder; import org.elasticsearch.index.query.MoreLikeThisQueryBuilder.Item; import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutionException; @@ -58,6 +63,12 @@ import static org.hamcrest.Matchers.notNullValue; public class MoreLikeThisIT extends ESIntegTestCase { + + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testSimpleMoreLikeThis() throws Exception { logger.info("Creating index test"); assertAcked(prepareCreate("test").addMapping("type1", @@ -82,14 +93,13 @@ public void testSimpleMoreLikeThis() throws Exception { public void testSimpleMoreLikeOnLongField() throws Exception { logger.info("Creating index test"); 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)); logger.info("Indexing..."); client().index(indexRequest("test").type("type1").id("1").source(jsonBuilder().startObject().field("some_long", 1367484649580L).endObject())).actionGet(); - client().index(indexRequest("test").type("type2").id("2").source(jsonBuilder().startObject().field("some_long", 0).endObject())).actionGet(); + client().index(indexRequest("test").type("type1").id("2").source(jsonBuilder().startObject().field("some_long", 0).endObject())).actionGet(); client().index(indexRequest("test").type("type1").id("3").source(jsonBuilder().startObject().field("some_long", -666).endObject())).actionGet(); client().admin().indices().refresh(refreshRequest()).actionGet(); @@ -360,7 +370,7 @@ public void testSimpleMoreLikeThisIdsMultipleTypes() throws Exception { logger.info("Creating index test"); int numOfTypes = randomIntBetween(2, 10); CreateIndexRequestBuilder createRequestBuilder = prepareCreate("test") - .setSettings("index.mapping.single_type", false); + .setSettings("index.version.created", Version.V_5_6_0.id); 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/query/SearchQueryIT.java b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java index 51f61a7a9c311..01358dcfb899d 100644 --- a/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java +++ b/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java @@ -20,6 +20,7 @@ package org.elasticsearch.search.query; import org.apache.lucene.util.English; +import org.elasticsearch.Version; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.index.IndexRequestBuilder; import org.elasticsearch.action.search.SearchPhaseExecutionException; @@ -41,16 +42,20 @@ import org.elasticsearch.index.search.MatchQuery; import org.elasticsearch.index.search.MatchQuery.Type; import org.elasticsearch.indices.TermsLookup; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.test.ESIntegTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.format.ISODateTimeFormat; import java.io.IOException; +import java.util.Collection; +import java.util.Collections; import java.util.Random; import java.util.concurrent.ExecutionException; @@ -102,6 +107,11 @@ public class SearchQueryIT extends ESIntegTestCase { + @Override + protected Collection> nodePlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + @Override protected int maximumNumberOfShards() { return 7; @@ -545,7 +555,7 @@ public void testDateRangeInQueryStringWithTimeZone_10477() { } public void testTypeFilter() throws Exception { - assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate("test").setSettings("index.version.created", Version.V_5_6_0.id)); 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"), @@ -1181,7 +1191,36 @@ public void testTermsLookupFilter() throws Exception { } public void testBasicQueryById() throws Exception { - assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate("test")); + + client().prepareIndex("test", "doc", "1").setSource("field1", "value1").get(); + client().prepareIndex("test", "doc", "2").setSource("field1", "value2").get(); + client().prepareIndex("test", "doc", "3").setSource("field1", "value3").get(); + refresh(); + + SearchResponse searchResponse = client().prepareSearch().setQuery(idsQuery("doc").addIds("1", "2")).get(); + assertHitCount(searchResponse, 2L); + assertThat(searchResponse.getHits().getHits().length, equalTo(2)); + + searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1")).get(); + assertHitCount(searchResponse, 1L); + assertThat(searchResponse.getHits().getHits().length, equalTo(1)); + + searchResponse = client().prepareSearch().setQuery(idsQuery().addIds("1", "2")).get(); + assertHitCount(searchResponse, 2L); + assertThat(searchResponse.getHits().getHits().length, equalTo(2)); + + searchResponse = client().prepareSearch().setQuery(idsQuery(Strings.EMPTY_ARRAY).addIds("1")).get(); + assertHitCount(searchResponse, 1L); + assertThat(searchResponse.getHits().getHits().length, equalTo(1)); + + searchResponse = client().prepareSearch().setQuery(idsQuery("type1", "type2", "doc").addIds("1", "2", "3", "4")).get(); + assertHitCount(searchResponse, 3L); + assertThat(searchResponse.getHits().getHits().length, equalTo(3)); + } + + public void testBasicQueryByIdMultiType() throws Exception { + assertAcked(prepareCreate("test").setSettings("index.version.created", Version.V_5_6_0.id)); client().prepareIndex("test", "type1", "1").setSource("field1", "value1").get(); client().prepareIndex("test", "type2", "2").setSource("field1", "value2").get(); @@ -1212,6 +1251,7 @@ public void testBasicQueryById() throws Exception { assertThat(searchResponse.getHits().getHits().length, equalTo(2)); } + public void testNumericTermsAndRanges() throws Exception { assertAcked(prepareCreate("test") .addMapping("type1", @@ -1448,10 +1488,9 @@ public void testSpanNot() throws IOException, ExecutionException, InterruptedExc public void testSimpleDFSQuery() throws IOException { assertAcked(prepareCreate("test") - .setSettings("index.mapping.single_type", false) - .addMapping("s", jsonBuilder() + .addMapping("doc", jsonBuilder() .startObject() - .startObject("s") + .startObject("doc") .startObject("_routing") .field("required", true) .endObject() @@ -1470,13 +1509,17 @@ public void testSimpleDFSQuery() throws IOException { .endObject() .endObject() .endObject()) - .addMapping("bs", "online", "type=boolean", "ts", "type=date,ignore_malformed=false,format=epoch_millis")); + ); - client().prepareIndex("test", "s", "1").setRouting("Y").setSource("online", false, "bs", "Y", "ts", System.currentTimeMillis() - 100).get(); - client().prepareIndex("test", "s", "2").setRouting("X").setSource("online", true, "bs", "X", "ts", System.currentTimeMillis() - 10000000).get(); - client().prepareIndex("test", "bs", "3").setSource("online", false, "ts", System.currentTimeMillis() - 100).get(); - client().prepareIndex("test", "bs", "4").setSource("online", true, "ts", System.currentTimeMillis() - 123123).get(); + client().prepareIndex("test", "doc", "1").setRouting("Y").setSource("online", false, "bs", "Y", "ts", + System.currentTimeMillis() - 100, "type", "s").get(); + client().prepareIndex("test", "doc", "2").setRouting("X").setSource("online", true, "bs", "X", "ts", + System.currentTimeMillis() - 10000000, "type", "s").get(); + client().prepareIndex("test", "doc", "3").setRouting(randomAlphaOfLength(2)) + .setSource("online", false, "ts", System.currentTimeMillis() - 100, "type", "bs").get(); + client().prepareIndex("test", "doc", "4").setRouting(randomAlphaOfLength(2)) + .setSource("online", true, "ts", System.currentTimeMillis() - 123123, "type", "bs").get(); refresh(); SearchResponse response = client().prepareSearch("test") @@ -1487,11 +1530,11 @@ public void testSimpleDFSQuery() throws IOException { .must(boolQuery() .should(boolQuery() .must(rangeQuery("ts").lt(System.currentTimeMillis() - (15 * 1000))) - .must(termQuery("_type", "bs")) + .must(termQuery("type", "bs")) ) .should(boolQuery() .must(rangeQuery("ts").lt(System.currentTimeMillis() - (15 * 1000))) - .must(termQuery("_type", "s")) + .must(termQuery("type", "s")) ) ) ) @@ -1620,29 +1663,33 @@ public void testMinScore() throws ExecutionException, InterruptedException { } public void testQueryStringWithSlopAndFields() { - assertAcked(prepareCreate("test").setSettings("index.mapping.single_type", false)); + assertAcked(prepareCreate("test")); - client().prepareIndex("test", "customer", "1").setSource("desc", "one two three").get(); - client().prepareIndex("test", "product", "2").setSource("desc", "one two three").get(); + client().prepareIndex("test", "doc", "1").setSource("desc", "one two three", "type", "customer").get(); + client().prepareIndex("test", "doc", "2").setSource("desc", "one two three", "type", "product").get(); refresh(); { SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get(); assertHitCount(searchResponse, 2); } { - SearchResponse searchResponse = client().prepareSearch("test").setTypes("product").setQuery(QueryBuilders.queryStringQuery("\"one two\"").field("desc")).get(); + SearchResponse searchResponse = client().prepareSearch("test").setPostFilter(QueryBuilders.termQuery("type", "customer")) + .setQuery(QueryBuilders.queryStringQuery("\"one two\"").field("desc")).get(); assertHitCount(searchResponse, 1); } { - SearchResponse searchResponse = client().prepareSearch("test").setTypes("product").setQuery(QueryBuilders.queryStringQuery("\"one three\"~5").field("desc")).get(); + SearchResponse searchResponse = client().prepareSearch("test").setPostFilter(QueryBuilders.termQuery("type", "product")) + .setQuery(QueryBuilders.queryStringQuery("\"one three\"~5").field("desc")).get(); assertHitCount(searchResponse, 1); } { - SearchResponse searchResponse = client().prepareSearch("test").setTypes("customer").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get(); + SearchResponse searchResponse = client().prepareSearch("test").setPostFilter(QueryBuilders.termQuery("type", "customer")) + .setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get(); assertHitCount(searchResponse, 1); } { - SearchResponse searchResponse = client().prepareSearch("test").setTypes("customer").setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get(); + SearchResponse searchResponse = client().prepareSearch("test").setPostFilter(QueryBuilders.termQuery("type", "customer")) + .setQuery(QueryBuilders.queryStringQuery("\"one two\"").defaultField("desc")).get(); assertHitCount(searchResponse, 1); } } diff --git a/core/src/test/java/org/elasticsearch/tribe/TribeIT.java b/core/src/test/java/org/elasticsearch/tribe/TribeIT.java index f678d4528fe0f..62b4b3e9f2d0c 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 void testOnConflictPrefer() throws Exception { 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").setSettings("index.mapping.single_type", false)); + assertAcked(cluster1.client().admin().indices().prepareCreate("test1")); ensureGreen(cluster1.client()); - assertAcked(cluster2.client().admin().indices().prepareCreate("test2").setSettings("index.mapping.single_type", false)); + assertAcked(cluster2.client().admin().indices().prepareCreate("test2")); ensureGreen(cluster2.client()); // Wait for the tribe node to retrieve the indices into its cluster state @@ -411,21 +411,6 @@ public void testTribeOnOneCluster() throws Exception { assertThat(clusterState.getMetaData().index("test2").mapping("type1"), notNullValue()); }); - // More documents with another type - indexRandom(true, - client().prepareIndex("test1", "type2", "1").setSource("field1", "value1"), - client().prepareIndex("test2", "type2", "1").setSource("field1", "value1") - ); - assertHitCount(client().prepareSearch().get(), 4L); - assertBusy(() -> { - ClusterState clusterState = client().admin().cluster().prepareState().get().getState(); - assertThat(clusterState.getMetaData().index("test1").mapping("type1"), notNullValue()); - assertThat(clusterState.getMetaData().index("test1").mapping("type2"), notNullValue()); - - assertThat(clusterState.getMetaData().index("test2").mapping("type1"), notNullValue()); - assertThat(clusterState.getMetaData().index("test2").mapping("type2"), notNullValue()); - }); - // Make sure master level write operations fail... (we don't really have a master) expectThrows(MasterNotDiscoveredException.class, () -> { client().admin().indices().prepareCreate("tribe_index").setMasterNodeTimeout("10ms").get(); diff --git a/core/src/test/java/org/elasticsearch/update/UpdateIT.java b/core/src/test/java/org/elasticsearch/update/UpdateIT.java index 92234715c1e3c..dc46ef12e3669 100644 --- a/core/src/test/java/org/elasticsearch/update/UpdateIT.java +++ b/core/src/test/java/org/elasticsearch/update/UpdateIT.java @@ -33,6 +33,7 @@ import java.util.function.Function; import org.elasticsearch.ElasticsearchTimeoutException; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.DocWriteResponse; @@ -272,7 +273,7 @@ public void testUpsertFields() throws Exception { assertThat(updateResponse.getGetResult().sourceAsMap().get("bar").toString(), equalTo("baz")); assertThat(updateResponse.getGetResult().sourceAsMap().get("extra").toString(), equalTo("foo")); } - + public void testIndexAutoCreation() throws Exception { UpdateResponse updateResponse = client().prepareUpdate("test", "type1", "1") .setUpsert(XContentFactory.jsonBuilder().startObject().field("bar", "baz").endObject()) @@ -461,7 +462,7 @@ public void testUpdateRequestWithScriptAndShouldUpsertDoc() throws Exception { public void testContextVariables() throws Exception { assertAcked(prepareCreate("test") - .setSettings("index.mapping.single_type", false) + .setSettings("index.version.created", Version.V_5_6_0.id) .addAlias(new Alias("alias")) .addMapping("type1", XContentFactory.jsonBuilder() .startObject() From dff604e87c1acbfe859549695a6fad986ae625dd Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 21 Jun 2017 15:56:51 +0200 Subject: [PATCH 2/4] fix IdFieldMapperTests --- .../elasticsearch/index/mapper/IdFieldMapperTests.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java index a4bf903ef6411..cbef022af758a 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/IdFieldMapperTests.java @@ -29,14 +29,22 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.mapper.MapperService.MergeReason; +import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.InternalSettingsPlugin; import java.io.IOException; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; public class IdFieldMapperTests extends ESSingleNodeTestCase { + @Override + protected Collection> getPlugins() { + return Collections.singleton(InternalSettingsPlugin.class); + } + public void testIncludeInObjectNotAllowed() throws Exception { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); From b028ea4314fee86aad4958c24dc727493976c0f7 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 22 Jun 2017 15:06:53 +0200 Subject: [PATCH 3/4] Apply freedback --- .../org/elasticsearch/get/GetActionIT.java | 95 +++++++++++++++++-- .../indices/IndicesOptionsIntegrationIT.java | 33 +++++++ .../mapping/SimpleGetFieldMappingsIT.java | 53 ++++++++++- .../mapping/UpdateMappingIntegrationIT.java | 1 + .../indices/stats/IndexStatsIT.java | 43 ++++----- .../highlight/HighlighterSearchIT.java | 30 +++--- .../search/fields/SearchFieldsIT.java | 10 +- 7 files changed, 209 insertions(+), 56 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java index 7e5180f864143..86536b00e656e 100644 --- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -255,15 +255,55 @@ public void testGetDocWithMultivaluedFields() throws Exception { .startObject("field").field("type", "text").field("store", true).endObject() .endObject() .endObject().endObject().string(); + assertAcked(prepareCreate("test") + .addMapping("type1", mapping1, XContentType.JSON)); + ensureGreen(); + + GetResponse response = client().prepareGet("test", "type1", "1").get(); + assertThat(response.isExists(), equalTo(false)); + assertThat(response.isExists(), equalTo(false)); + + client().prepareIndex("test", "type1", "1") + .setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get(); + + response = client().prepareGet("test", "type1", "1").setStoredFields("field").get(); + assertThat(response.isExists(), equalTo(true)); + assertThat(response.getId(), equalTo("1")); + assertThat(response.getType(), equalTo("type1")); + Set fields = new HashSet<>(response.getFields().keySet()); + assertThat(fields, equalTo(singleton("field"))); + assertThat(response.getFields().get("field").getValues().size(), equalTo(2)); + assertThat(response.getFields().get("field").getValues().get(0).toString(), equalTo("1")); + assertThat(response.getFields().get("field").getValues().get(1).toString(), equalTo("2")); + + // Now test values being fetched from stored fields. + refresh(); + response = client().prepareGet("test", "type1", "1").setStoredFields("field").get(); + assertThat(response.isExists(), equalTo(true)); + assertThat(response.getId(), equalTo("1")); + fields = new HashSet<>(response.getFields().keySet()); + assertThat(fields, equalTo(singleton("field"))); + assertThat(response.getFields().get("field").getValues().size(), equalTo(2)); + assertThat(response.getFields().get("field").getValues().get(0).toString(), equalTo("1")); + assertThat(response.getFields().get("field").getValues().get(1).toString(), equalTo("2")); + } + + public void testGetDocWithMultivaluedFieldsMultiTypeBWC() throws Exception { + assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0"))); + String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type1") + .startObject("properties") + .startObject("field").field("type", "text").field("store", true).endObject() + .endObject() + .endObject().endObject().string(); String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type2") - .startObject("properties") - .startObject("field").field("type", "text").field("store", true).endObject() - .endObject() - .endObject().endObject().string(); + .startObject("properties") + .startObject("field").field("type", "text").field("store", true).endObject() + .endObject() + .endObject().endObject().string(); assertAcked(prepareCreate("test") - .addMapping("type1", mapping1, XContentType.JSON) - .addMapping("type2", mapping2, XContentType.JSON) - .setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id)); // multi types in 5.6 + .addMapping("type1", mapping1, XContentType.JSON) + .addMapping("type2", mapping2, XContentType.JSON) + .setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id)); // multi types in 5.6 ensureGreen(); GetResponse response = client().prepareGet("test", "type1", "1").get(); @@ -272,10 +312,10 @@ public void testGetDocWithMultivaluedFields() throws Exception { assertThat(response.isExists(), equalTo(false)); client().prepareIndex("test", "type1", "1") - .setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get(); + .setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get(); client().prepareIndex("test", "type2", "1") - .setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get(); + .setSource(jsonBuilder().startObject().array("field", "1", "2").endObject()).get(); response = client().prepareGet("test", "type1", "1").setStoredFields("field").get(); assertThat(response.isExists(), equalTo(true)); @@ -533,7 +573,42 @@ public void testMultiGetWithVersion() throws Exception { assertThat(response.getResponses()[2].getResponse().getSourceAsMap().get("field").toString(), equalTo("value2")); } - public void testGetFieldsMetaData() throws Exception { + public void testGetFieldsMetaDataWithRouting() throws Exception { + assertAcked(prepareCreate("test") + .addMapping("doc", "field1", "type=keyword,store=true") + .addAlias(new Alias("alias")) + .setSettings("index.refresh_interval", -1, "index.version.created", Version.V_5_6_0.id)); // multi types in 5.6 + + client().prepareIndex("test", "doc", "1") + .setRouting("1") + .setSource(jsonBuilder().startObject().field("field1", "value").endObject()) + .get(); + + GetResponse getResponse = client().prepareGet(indexOrAlias(), "doc", "1") + .setRouting("1") + .setStoredFields("field1") + .get(); + assertThat(getResponse.isExists(), equalTo(true)); + assertThat(getResponse.getField("field1").isMetadataField(), equalTo(false)); + assertThat(getResponse.getField("field1").getValue().toString(), equalTo("value")); + assertThat(getResponse.getField("_routing").isMetadataField(), equalTo(true)); + assertThat(getResponse.getField("_routing").getValue().toString(), equalTo("1")); + + flush(); + + getResponse = client().prepareGet(indexOrAlias(), "doc", "1") + .setStoredFields("field1") + .setRouting("1") + .get(); + assertThat(getResponse.isExists(), equalTo(true)); + assertThat(getResponse.getField("field1").isMetadataField(), equalTo(false)); + assertThat(getResponse.getField("field1").getValue().toString(), equalTo("value")); + assertThat(getResponse.getField("_routing").isMetadataField(), equalTo(true)); + assertThat(getResponse.getField("_routing").getValue().toString(), equalTo("1")); + } + + public void testGetFieldsMetaDataWithParentChild() throws Exception { + assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0"))); assertAcked(prepareCreate("test") .addMapping("parent") .addMapping("my-type1", "_parent", "type=parent", "field1", "type=keyword,store=true") diff --git a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java index 43066c454a50d..76d5be5ea1e8c 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java @@ -565,6 +565,39 @@ public void testPutMapping() throws Exception { 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); + for (String index : Arrays.asList("foo", "foobar", "bar", "barbaz")) { + assertAcked(prepareCreate(index)); + } + + verify(client().admin().indices().preparePutMapping("foo").setType("type").setSource("field", "type=text"), false); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo").get("type"), notNullValue()); + verify(client().admin().indices().preparePutMapping("b*").setType("type").setSource("field", "type=text"), false); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar").get("type"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type"), notNullValue()); + verify(client().admin().indices().preparePutMapping("_all").setType("type").setSource("field", "type=text"), false); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo").get("type"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar").get("type"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar").get("type"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type"), notNullValue()); + verify(client().admin().indices().preparePutMapping().setType("type").setSource("field", "type=text"), false); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo").get("type"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar").get("type"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar").get("type"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type"), notNullValue()); + + + verify(client().admin().indices().preparePutMapping("c*").setType("type").setSource("field", "type=text"), true); + + assertAcked(client().admin().indices().prepareClose("barbaz").get()); + verify(client().admin().indices().preparePutMapping("barbaz").setType("type").setSource("field", "type=text"), false); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz").get("type"), notNullValue()); + } + + public void testPutMappingMultiType() throws Exception { + assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0"))); + 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); + for (String index : Arrays.asList("foo", "foobar", "bar", "barbaz")) { assertAcked(prepareCreate(index).setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types } 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 c259a8db21924..a1faa4d5eeb71 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/SimpleGetFieldMappingsIT.java @@ -74,8 +74,59 @@ private XContentBuilder getMappingForType(String type) throws IOException { .endObject().endObject().endObject(); } - public void testSimpleGetFieldMappings() throws Exception { + public void testGetFieldMappings() throws Exception { + assertAcked(prepareCreate("indexa") + .addMapping("typeA", getMappingForType("typeA"))); + assertAcked(client().admin().indices().prepareCreate("indexb") + .addMapping("typeB", getMappingForType("typeB"))); + + + // Get mappings by full name + GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("indexa").setTypes("typeA").setFields("field1", "obj.subfield").get(); + assertThat(response.fieldMappings("indexa", "typeA", "field1").fullName(), equalTo("field1")); + assertThat(response.fieldMappings("indexa", "typeA", "field1").sourceAsMap(), hasKey("field1")); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield")); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield")); + assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue()); + + // Get mappings by name + response = client().admin().indices().prepareGetFieldMappings("indexa").setTypes("typeA").setFields("field1", "obj.subfield").get(); + assertThat(response.fieldMappings("indexa", "typeA", "field1").fullName(), equalTo("field1")); + assertThat(response.fieldMappings("indexa", "typeA", "field1").sourceAsMap(), hasKey("field1")); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield")); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield")); + assertThat(response.fieldMappings("indexa", "typeB", "field1"), nullValue()); + assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue()); + + // get mappings by name across multiple indices + response = client().admin().indices().prepareGetFieldMappings().setTypes("typeA").setFields("obj.subfield").get(); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield")); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield")); + assertThat(response.fieldMappings("indexa", "typeB", "obj.subfield"), nullValue()); + assertThat(response.fieldMappings("indexb", "typeB", "obj.subfield"), nullValue()); + + // get mappings by name across multiple types + response = client().admin().indices().prepareGetFieldMappings("indexa").setFields("obj.subfield").get(); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield")); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield")); + assertThat(response.fieldMappings("indexa", "typeA", "field1"), nullValue()); + assertThat(response.fieldMappings("indexb", "typeB", "obj.subfield"), nullValue()); + assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue()); + + // get mappings by name across multiple types & indices + response = client().admin().indices().prepareGetFieldMappings().setFields("obj.subfield").get(); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").fullName(), equalTo("obj.subfield")); + assertThat(response.fieldMappings("indexa", "typeA", "obj.subfield").sourceAsMap(), hasKey("subfield")); + assertThat(response.fieldMappings("indexa", "typeA", "field1"), nullValue()); + assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue()); + assertThat(response.fieldMappings("indexb", "typeB", "obj.subfield").fullName(), equalTo("obj.subfield")); + assertThat(response.fieldMappings("indexb", "typeB", "obj.subfield").sourceAsMap(), hasKey("subfield")); + assertThat(response.fieldMappings("indexb", "typeB", "field1"), nullValue()); + } + + public void testGetFieldMappingsMultiType() throws Exception { + assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0"))); assertAcked(prepareCreate("indexa") .setSettings("index.version.created", Version.V_5_6_0.id) .addMapping("typeA", getMappingForType("typeA")) 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 36000b6a0c0a9..c4e66caa79966 100644 --- a/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -352,6 +352,7 @@ public void testPutMappingsWithBlocks() throws Exception { } public void testUpdateMappingOnAllTypes() throws IOException { + assertTrue("remove this multi type test", Version.CURRENT.before(Version.fromString("7.0.0"))); assertAcked(prepareCreate("index") .setSettings("index.version.created", Version.V_5_6_0.id) .addMapping("type1", "f", "type=keyword").addMapping("type2", "f", "type=keyword")); 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 73430c92c8c22..e96f028161214 100644 --- a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java @@ -389,6 +389,7 @@ public void testThrottleStats() throws Exception { } public void testSimpleStats() throws Exception { + // this test has some type stats tests that can be removed in 7.0 assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types createIndex("test2"); ensureGreen(); @@ -519,7 +520,7 @@ public void testSimpleStats() throws Exception { } public void testMergeStats() { - assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); // allows for multiple types + assertAcked(prepareCreate("test_index")); ensureGreen(); @@ -541,8 +542,7 @@ public void testMergeStats() { assertThat(stats.getTotal().getSearch(), nullValue()); for (int i = 0; i < 20; i++) { - client().prepareIndex("test1", "type1", Integer.toString(i)).setSource("field", "value").execute().actionGet(); - client().prepareIndex("test1", "type2", Integer.toString(i)).setSource("field", "value").execute().actionGet(); + client().prepareIndex("test_index", "doc", Integer.toString(i)).setSource("field", "value").execute().actionGet(); client().admin().indices().prepareFlush().execute().actionGet(); } client().admin().indices().prepareForceMerge().setMaxNumSegments(1).execute().actionGet(); @@ -555,15 +555,14 @@ public void testMergeStats() { } public void testSegmentsStats() { - assertAcked(prepareCreate("test1") - .setSettings(SETTING_NUMBER_OF_REPLICAS, between(0, 1), "index.version.created", Version.V_5_6_0.id)); + assertAcked(prepareCreate("test_index") + .setSettings(SETTING_NUMBER_OF_REPLICAS, between(0, 1))); ensureGreen(); NumShards test1 = getNumShards("test1"); for (int i = 0; i < 100; i++) { - index("test1", "type1", Integer.toString(i), "field", "value"); - index("test1", "type2", Integer.toString(i), "field", "value"); + index("test_index", "doc", Integer.toString(i), "field", "value"); } IndicesStatsResponse stats = client().admin().indices().prepareStats().setSegments(true).get(); @@ -581,14 +580,14 @@ public void testSegmentsStats() { public void testAllFlags() throws Exception { // rely on 1 replica for this tests - assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); - createIndex("test2"); + assertAcked(prepareCreate("test_index")); + createIndex("test_index_2"); ensureGreen(); - client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet(); - client().prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet(); - client().prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet(); + client().prepareIndex("test_index", "doc", Integer.toString(1)).setSource("field", "value").execute().actionGet(); + client().prepareIndex("test_index", "doc", Integer.toString(2)).setSource("field", "value").execute().actionGet(); + client().prepareIndex("test_index_2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet(); client().admin().indices().prepareRefresh().execute().actionGet(); IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats(); @@ -703,14 +702,14 @@ public void testFlagOrdinalOrder() { } public void testMultiIndex() throws Exception { - assertAcked(prepareCreate("test1").setSettings("index.version.created", Version.V_5_6_0.id)); + assertAcked(prepareCreate("test1")); createIndex("test2"); ensureGreen(); - client().prepareIndex("test1", "type1", Integer.toString(1)).setSource("field", "value").execute().actionGet(); - client().prepareIndex("test1", "type2", Integer.toString(1)).setSource("field", "value").execute().actionGet(); - client().prepareIndex("test2", "type", Integer.toString(1)).setSource("field", "value").execute().actionGet(); + client().prepareIndex("test1", "doc", Integer.toString(1)).setSource("field", "value").execute().actionGet(); + client().prepareIndex("test1", "doc", Integer.toString(2)).setSource("field", "value").execute().actionGet(); + client().prepareIndex("test2", "doc", Integer.toString(1)).setSource("field", "value").execute().actionGet(); refresh(); int numShards1 = getNumShards("test1").totalNumShards; @@ -744,13 +743,13 @@ public void testMultiIndex() throws Exception { public void testFieldDataFieldsParam() throws Exception { assertAcked(client().admin().indices().prepareCreate("test1") .setSettings("index.version.created", Version.V_5_6_0.id) - .addMapping("type", "bar", "type=text,fielddata=true", + .addMapping("doc", "bar", "type=text,fielddata=true", "baz", "type=text,fielddata=true").get()); ensureGreen(); - client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get(); - client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get(); + client().prepareIndex("test1", "doc", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get(); + client().prepareIndex("test1", "doc", Integer.toString(2)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get(); refresh(); client().prepareSearch("_all").addSort("bar", SortOrder.ASC).addSort("baz", SortOrder.ASC).execute().actionGet(); @@ -791,14 +790,12 @@ public void testFieldDataFieldsParam() throws Exception { public void testCompletionFieldsParam() throws Exception { assertAcked(prepareCreate("test1") - .setSettings("index.version.created", Version.V_5_6_0.id) // allows for multiple types .addMapping( - "bar", + "doc", "{ \"properties\": { \"bar\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}},\"baz\": { \"type\": \"text\", \"fields\": { \"completion\": { \"type\": \"completion\" }}}}}", XContentType.JSON)); ensureGreen(); - client().prepareIndex("test1", "bar", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get(); - client().prepareIndex("test1", "baz", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get(); + client().prepareIndex("test1", "doc", Integer.toString(1)).setSource("{\"bar\":\"bar\",\"baz\":\"baz\"}", XContentType.JSON).get(); refresh(); IndicesStatsRequestBuilder builder = client().admin().indices().prepareStats(); 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 fbd5a4616f6a0..dd2652dc8494b 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 @@ -1364,23 +1364,22 @@ public void testPhrasePrefix() throws IOException { .put("index.analysis.filter.synonym.type", "synonym") .putArray("index.analysis.filter.synonym.synonyms", "quick => fast"); - assertAcked(prepareCreate("test").setSettings(builder.build()).addMapping("type1", type1TermVectorMapping())); - assertAcked(prepareCreate("test1").setSettings(builder.build()).addMapping("type2", - "field4", "type=text,term_vector=with_positions_offsets,analyzer=synonym", - "field3", "type=text,analyzer=synonym")); + assertAcked(prepareCreate("first_test_index").setSettings(builder.build()).addMapping("type1", type1TermVectorMapping())); + ensureGreen(); - client().prepareIndex("test", "type1", "0").setSource( + client().prepareIndex("first_test_index", "type1", "0").setSource( "field0", "The quick brown fox jumps over the lazy dog", "field1", "The quick brown fox jumps over the lazy dog").get(); - client().prepareIndex("test", "type1", "1").setSource("field1", "The quick browse button is a fancy thing, right bro?").get(); + client().prepareIndex("first_test_index", "type1", "1").setSource("field1", + "The quick browse button is a fancy thing, right bro?").get(); refresh(); logger.info("--> highlighting and searching on field0"); SearchSourceBuilder source = searchSource() .query(matchPhrasePrefixQuery("field0", "bro")) .highlighter(highlight().field("field0").order("score").preTags("").postTags("")); - SearchResponse searchResponse = client().search(searchRequest("test").source(source)).actionGet(); + SearchResponse searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field0", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); @@ -1388,7 +1387,7 @@ public void testPhrasePrefix() throws IOException { .query(matchPhrasePrefixQuery("field0", "quick bro")) .highlighter(highlight().field("field0").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test").source(source)).actionGet(); + searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field0", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); logger.info("--> highlighting and searching on field1"); @@ -1399,7 +1398,7 @@ public void testPhrasePrefix() throws IOException { ) .highlighter(highlight().field("field1").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test").source(source)).actionGet(); + searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet(); assertThat(searchResponse.getHits().totalHits, equalTo(2L)); for (int i = 0; i < 2; i++) { assertHighlight(searchResponse, i, "field1", 0, 1, anyOf( @@ -1411,7 +1410,7 @@ public void testPhrasePrefix() throws IOException { .query(matchPhrasePrefixQuery("field1", "quick bro")) .highlighter(highlight().field("field1").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test").source(source)).actionGet(); + searchResponse = client().search(searchRequest("first_test_index").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field1", 0, 1, anyOf( equalTo("The quick browse button is a fancy thing, right bro?"), @@ -1420,15 +1419,18 @@ public void testPhrasePrefix() throws IOException { equalTo("The quick browse button is a fancy thing, right bro?"), equalTo("The quick brown fox jumps over the lazy dog"))); + assertAcked(prepareCreate("second_test_index").setSettings(builder.build()).addMapping("doc", + "field4", "type=text,term_vector=with_positions_offsets,analyzer=synonym", + "field3", "type=text,analyzer=synonym")); // with synonyms - client().prepareIndex("test1", "type2", "0").setSource( + client().prepareIndex("second_test_index", "doc", "0").setSource( "type", "type2", "field4", "The quick brown fox jumps over the lazy dog", "field3", "The quick brown fox jumps over the lazy dog").get(); - client().prepareIndex("test1", "type2", "1").setSource( + client().prepareIndex("second_test_index", "doc", "1").setSource( "type", "type2", "field4", "The quick browse button is a fancy thing, right bro?").get(); - client().prepareIndex("test1", "type2", "2").setSource( + client().prepareIndex("second_test_index", "doc", "2").setSource( "type", "type2", "field4", "a quick fast blue car").get(); refresh(); @@ -1436,7 +1438,7 @@ public void testPhrasePrefix() throws IOException { source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field3", "fast bro")) .highlighter(highlight().field("field3").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test1").source(source)).actionGet(); + searchResponse = client().search(searchRequest("second_test_index").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field3", 0, 1, equalTo("The quick brown fox jumps over the lazy dog")); 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 770294d586e22..f33354879554f 100644 --- a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java +++ b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java @@ -865,15 +865,11 @@ public void testScriptFields() throws Exception { } public void testLoadMetadata() throws Exception { - assertAcked(prepareCreate("test") - .setSettings("index.version.created", Version.V_5_6_0.id) - .addMapping("parent") - .addMapping("my-type1", "_parent", "type=parent")); + assertAcked(prepareCreate("test")); indexRandom(true, - client().prepareIndex("test", "my-type1", "1") + client().prepareIndex("test", "doc", "1") .setRouting("1") - .setParent("parent_1") .setSource(jsonBuilder().startObject().field("field1", "value").endObject())); SearchResponse response = client().prepareSearch("test").addStoredField("field1").get(); @@ -885,7 +881,5 @@ public void testLoadMetadata() throws Exception { assertThat(fields.get("field1"), nullValue()); assertThat(fields.get("_routing").isMetadataField(), equalTo(true)); assertThat(fields.get("_routing").getValue().toString(), equalTo("1")); - assertThat(fields.get("_parent").isMetadataField(), equalTo(true)); - assertThat(fields.get("_parent").getValue().toString(), equalTo("parent_1")); } } From 8cd7289a6853c7dec661f2fe45725dd3614aa204 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 22 Jun 2017 15:51:12 +0200 Subject: [PATCH 4/4] fix 2 more tests --- .../java/org/elasticsearch/indices/stats/IndexStatsIT.java | 2 +- .../search/fetch/subphase/highlight/HighlighterSearchIT.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 e96f028161214..36381233a6190 100644 --- a/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java +++ b/core/src/test/java/org/elasticsearch/indices/stats/IndexStatsIT.java @@ -559,7 +559,7 @@ public void testSegmentsStats() { .setSettings(SETTING_NUMBER_OF_REPLICAS, between(0, 1))); ensureGreen(); - NumShards test1 = getNumShards("test1"); + NumShards test1 = getNumShards("test_index"); for (int i = 0; i < 100; i++) { index("test_index", "doc", Integer.toString(i), "field", "value"); 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 dd2652dc8494b..acaf35429be0a 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 @@ -1445,7 +1445,7 @@ public void testPhrasePrefix() throws IOException { logger.info("--> highlighting and searching on field4"); source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field4", "the fast bro")) .highlighter(highlight().field("field4").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test1").source(source)).actionGet(); + searchResponse = client().search(searchRequest("second_test_index").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf( equalTo("The quick browse button is a fancy thing, right bro?"), @@ -1457,7 +1457,7 @@ public void testPhrasePrefix() throws IOException { logger.info("--> highlighting and searching on field4"); source = searchSource().postFilter(termQuery("type", "type2")).query(matchPhrasePrefixQuery("field4", "a fast quick blue ca")) .highlighter(highlight().field("field4").order("score").preTags("").postTags("")); - searchResponse = client().search(searchRequest("test1").source(source)).actionGet(); + searchResponse = client().search(searchRequest("second_test_index").source(source)).actionGet(); assertHighlight(searchResponse, 0, "field4", 0, 1, anyOf(equalTo("a quick fast blue car"),