From de8411a5a48a4aeeaf360985ae0943480179d2a6 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Tue, 1 Oct 2019 14:41:07 +0100 Subject: [PATCH 01/18] Remove types from GetMappings request and response --- .../client/IndicesRequestConverters.java | 3 +- .../elasticsearch/client/IndicesClientIT.java | 2 +- .../client/IndicesRequestConvertersTests.java | 44 --------- .../client/indices/GetIndexResponseTests.java | 9 +- .../indices/GetMappingsResponseTests.java | 6 +- .../index/mapper/size/SizeMappingIT.java | 4 +- .../admin/indices/get/GetIndexResponse.java | 99 +++++++------------ .../indices/get/TransportGetIndexAction.java | 5 +- .../mapping/get/GetMappingsResponse.java | 78 +++++---------- .../get/TransportGetMappingsAction.java | 4 +- .../master/info/ClusterInfoRequest.java | 20 ++-- .../info/ClusterInfoRequestBuilder.java | 12 --- .../cluster/metadata/MetaData.java | 42 ++------ .../admin/indices/create/CreateIndexIT.java | 6 +- .../action/admin/indices/get/GetIndexIT.java | 18 ++-- .../indices/get/GetIndexResponseTests.java | 6 +- .../mapping/get/GetMappingsResponseTests.java | 55 +++-------- .../action/bulk/BulkIntegrationIT.java | 2 +- .../documentation/IndicesDocumentationIT.java | 4 +- .../cluster/SimpleClusterStateIT.java | 4 +- .../coordination/RareClusterStateIT.java | 2 +- .../MetaDataIndexStateServiceTests.java | 2 +- .../cluster/metadata/MetaDataTests.java | 87 +++++----------- .../gateway/MetaDataWriteDataNodesIT.java | 8 +- .../index/mapper/DynamicMappingIT.java | 4 +- .../mapper/FieldFilterMapperPluginTests.java | 22 ++--- .../mapper/MultiFieldsIntegrationIT.java | 10 +- .../indices/IndicesOptionsIntegrationIT.java | 24 ++--- .../indices/mapping/SimpleGetMappingsIT.java | 48 ++------- .../mapping/UpdateMappingIntegrationIT.java | 16 ++- .../xpack/ccr/CcrRepositoryIT.java | 2 +- .../xpack/ccr/IndexFollowingIT.java | 8 +- .../persistence/ElasticsearchMappings.java | 9 +- .../snapshots/SourceOnlySnapshotIT.java | 8 +- .../accesscontrol/FieldSubsetReaderTests.java | 32 +++--- .../ml/dataframe/DataFrameAnalyticsIndex.java | 2 +- .../xpack/ml/dataframe/MappingsMerger.java | 21 ++-- .../job/persistence/JobResultsProvider.java | 7 +- .../DataFrameAnalyticsIndexTests.java | 11 +-- .../ml/dataframe/MappingsMergerTests.java | 44 +++------ .../ml/integration/JobResultsProviderIT.java | 7 +- .../persistence/JobResultsProviderTests.java | 5 +- .../action/TransportPutRollupJobAction.java | 2 +- .../action/PutJobStateMachineTests.java | 30 +----- .../DocumentAndFieldLevelSecurityTests.java | 4 +- .../integration/KibanaUserRoleIntegTests.java | 5 +- .../HistoryTemplateHttpMappingsTests.java | 9 +- .../HistoryTemplateTimeMappingsTests.java | 6 +- .../AbstractWatcherIntegrationTestCase.java | 2 +- .../integration/HistoryIntegrationTests.java | 15 ++- 50 files changed, 273 insertions(+), 602 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java index ba85983704537..98fe80feec39c 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java @@ -192,9 +192,8 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) { @Deprecated static Request getMappings(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) { String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices(); - String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types(); - Request request = new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping", types)); + Request request = new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping")); RequestConverters.Params parameters = new RequestConverters.Params(); parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 43e4b26ac3f17..13989e42b76e2 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -472,7 +472,7 @@ public void testGetIndexWithTypes() throws IOException { assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS)); assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS)); assertNotNull(getIndexResponse.getMappings().get(indexName)); - MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName).get("_doc"); + MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName); assertNotNull(mappingMetaData); assertEquals("_doc", mappingMetaData.type()); assertEquals("{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}", mappingMetaData.source().string()); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java index a8a400fdcf308..115dabe4b049a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java @@ -288,50 +288,6 @@ public void testGetMapping() { Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); } - public void testGetMappingWithTypes() { - org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingRequest = - new org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest(); - - String[] indices = Strings.EMPTY_ARRAY; - if (randomBoolean()) { - indices = RequestConvertersTests.randomIndicesNames(0, 5); - getMappingRequest.indices(indices); - } else if (randomBoolean()) { - getMappingRequest.indices((String[]) null); - } - - String type = null; - if (randomBoolean()) { - type = randomAlphaOfLengthBetween(3, 10); - getMappingRequest.types(type); - } else if (randomBoolean()) { - getMappingRequest.types((String[]) null); - } - - Map expectedParams = new HashMap<>(); - - RequestConvertersTests.setRandomIndicesOptions(getMappingRequest::indicesOptions, - getMappingRequest::indicesOptions, expectedParams); - RequestConvertersTests.setRandomMasterTimeout(getMappingRequest, expectedParams); - RequestConvertersTests.setRandomLocal(getMappingRequest::local, expectedParams); - expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true"); - - Request request = IndicesRequestConverters.getMappings(getMappingRequest); - StringJoiner endpoint = new StringJoiner("/", "/", ""); - String index = String.join(",", indices); - if (Strings.hasLength(index)) { - endpoint.add(index); - } - endpoint.add("_mapping"); - if (type != null) { - endpoint.add(type); - } - Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint())); - - Assert.assertThat(expectedParams, equalTo(request.getParameters())); - Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); - } - public void testGetFieldMapping() { GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java index 19c25fd11f6ed..e6c12e4af1a97 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java @@ -162,19 +162,14 @@ private static Map randomFieldMapping() { private static void toXContent(GetIndexResponse response, XContentBuilder builder) throws IOException { // first we need to repackage from GetIndexResponse to org.elasticsearch.action.admin.indices.get.GetIndexResponse - ImmutableOpenMap.Builder> allMappings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder allMappings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); Map indexMappings = response.getMappings(); for (String index : response.getIndices()) { - MappingMetaData mmd = indexMappings.get(index); - ImmutableOpenMap.Builder typedMappings = ImmutableOpenMap.builder(); - if (mmd != null) { - typedMappings.put(MapperService.SINGLE_MAPPING_NAME, mmd); - } - allMappings.put(index, typedMappings.build()); + allMappings.put(index, indexMappings.get(index)); aliases.put(index, response.getAliases().get(index)); settings.put(index, response.getSettings().get(index)); defaultSettings.put(index, response.getDefaultSettings().get(index)); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java index 0601609a8a766..4595cf5cfe6b5 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java @@ -102,12 +102,10 @@ private static Map randomFieldMapping() { private static void toXContent(GetMappingsResponse response, XContentBuilder builder) throws IOException { Params params = new ToXContent.MapParams( Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "false")); - ImmutableOpenMap.Builder> allMappings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder allMappings = ImmutableOpenMap.builder(); for (Map.Entry indexEntry : response.mappings().entrySet()) { - ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); - mappings.put(MapperService.SINGLE_MAPPING_NAME, indexEntry.getValue()); - allMappings.put(indexEntry.getKey(), mappings.build()); + allMappings.put(indexEntry.getKey(), indexEntry.getValue()); } org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse serverResponse = diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java index cbf89567b9a59..dc6681c33218e 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java @@ -96,8 +96,8 @@ private void assertSizeMappingEnabled(String index, String type, boolean enabled String errMsg = String.format(Locale.ROOT, "Expected size field mapping to be " + (enabled ? "enabled" : "disabled") + " for %s/%s", index, type); GetMappingsResponse getMappingsResponse = - client().admin().indices().prepareGetMappings(index).addTypes(type).get(); - Map mappingSource = getMappingsResponse.getMappings().get(index).get(type).getSourceAsMap(); + client().admin().indices().prepareGetMappings(index).get(); + Map mappingSource = getMappingsResponse.getMappings().get(index).getSourceAsMap(); assertThat(errMsg, mappingSource, hasKey("_size")); String sizeAsString = mappingSource.get("_size").toString(); assertThat(sizeAsString, is(notNullValue())); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index fc8a5f439b27c..096c17130f08c 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -21,6 +21,7 @@ import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.apache.lucene.util.CollectionUtil; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; @@ -33,6 +34,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser.Token; +import org.elasticsearch.index.mapper.MapperService; import java.io.IOException; import java.util.ArrayList; @@ -43,22 +45,20 @@ import java.util.Objects; import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; -import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY; -import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER; /** * A response for a get index action. */ public class GetIndexResponse extends ActionResponse implements ToXContentObject { - private ImmutableOpenMap> mappings = ImmutableOpenMap.of(); + private ImmutableOpenMap mappings = ImmutableOpenMap.of(); private ImmutableOpenMap> aliases = ImmutableOpenMap.of(); private ImmutableOpenMap settings = ImmutableOpenMap.of(); private ImmutableOpenMap defaultSettings = ImmutableOpenMap.of(); private String[] indices; public GetIndexResponse(String[] indices, - ImmutableOpenMap> mappings, + ImmutableOpenMap mappings, ImmutableOpenMap> aliases, ImmutableOpenMap settings, ImmutableOpenMap defaultSettings) { @@ -84,15 +84,16 @@ public GetIndexResponse(String[] indices, this.indices = in.readStringArray(); int mappingsSize = in.readVInt(); - ImmutableOpenMap.Builder> mappingsMapBuilder = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder mappingsMapBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < mappingsSize; i++) { String key = in.readString(); - int valueSize = in.readVInt(); - ImmutableOpenMap.Builder mappingEntryBuilder = ImmutableOpenMap.builder(); - for (int j = 0; j < valueSize; j++) { - mappingEntryBuilder.put(in.readString(), new MappingMetaData(in)); + if (in.getVersion().before(Version.V_8_0_0)) { + int valueSize = in.readVInt(); + assert valueSize == 1 : "Expected single mapping but got " + valueSize; + String type = in.readString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got " + type; } - mappingsMapBuilder.put(key, mappingEntryBuilder.build()); + mappingsMapBuilder.put(key, new MappingMetaData(in)); } mappings = mappingsMapBuilder.build(); @@ -133,11 +134,11 @@ public String[] getIndices() { return indices(); } - public ImmutableOpenMap> mappings() { + public ImmutableOpenMap mappings() { return mappings; } - public ImmutableOpenMap> getMappings() { + public ImmutableOpenMap getMappings() { return mappings(); } @@ -197,12 +198,20 @@ public String getSetting(String index, String setting) { public void writeTo(StreamOutput out) throws IOException { out.writeStringArray(indices); out.writeVInt(mappings.size()); - for (ObjectObjectCursor> indexEntry : mappings) { + for (ObjectObjectCursor indexEntry : mappings) { out.writeString(indexEntry.key); - out.writeVInt(indexEntry.value.size()); - for (ObjectObjectCursor mappingEntry : indexEntry.value) { - out.writeString(mappingEntry.key); - mappingEntry.value.writeTo(out); + MappingMetaData mmd = indexEntry.value; + if (out.getVersion().before(Version.V_8_0_0)) { + if (mmd != null) { + out.writeVInt(1); + out.writeString(MapperService.SINGLE_MAPPING_NAME); + } + else { + out.writeVInt(0); + } + } + if (mmd != null) { + mmd.writeTo(out); } } out.writeVInt(aliases.size()); @@ -241,30 +250,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } builder.endObject(); - ImmutableOpenMap indexMappings = mappings.get(index); - boolean includeTypeName = params.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, - DEFAULT_INCLUDE_TYPE_NAME_POLICY); - if (includeTypeName) { - builder.startObject("mappings"); - if (indexMappings != null) { - for (final ObjectObjectCursor typeEntry : indexMappings) { - builder.field(typeEntry.key); - builder.map(typeEntry.value.sourceAsMap()); - } - } - builder.endObject(); - } else { - MappingMetaData mappings = null; - for (final ObjectObjectCursor typeEntry : indexMappings) { - assert mappings == null; - mappings = typeEntry.value; - } - if (mappings == null) { - // no mappings yet - builder.startObject("mappings").endObject(); - } else { - builder.field("mappings", mappings.sourceAsMap()); - } + MappingMetaData indexMappings = mappings.get(index); + if (indexMappings == null) { + builder.startObject("mappings").endObject(); + } + else { + builder.field("mappings", indexMappings.sourceAsMap()); } builder.startObject("settings"); @@ -298,25 +289,9 @@ private static List parseAliases(XContentParser parser) throws IO return indexAliases; } - private static ImmutableOpenMap parseMappings(XContentParser parser) throws IOException { - ImmutableOpenMap.Builder indexMappings = ImmutableOpenMap.builder(); - // We start at START_OBJECT since parseIndexEntry ensures that - while (parser.nextToken() != Token.END_OBJECT) { - ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation); - parser.nextToken(); - if (parser.currentToken() == Token.START_OBJECT) { - String mappingType = parser.currentName(); - indexMappings.put(mappingType, new MappingMetaData(mappingType, parser.map())); - } else if (parser.currentToken() == Token.START_ARRAY) { - parser.skipChildren(); - } - } - return indexMappings.build(); - } - private static IndexEntry parseIndexEntry(XContentParser parser) throws IOException { List indexAliases = null; - ImmutableOpenMap indexMappings = null; + MappingMetaData indexMappings = null; Settings indexSettings = null; Settings indexDefaultSettings = null; // We start at START_OBJECT since fromXContent ensures that @@ -329,7 +304,7 @@ private static IndexEntry parseIndexEntry(XContentParser parser) throws IOExcept indexAliases = parseAliases(parser); break; case "mappings": - indexMappings = parseMappings(parser); + indexMappings = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, parser.map()); break; case "settings": indexSettings = Settings.fromXContent(parser); @@ -350,10 +325,10 @@ private static IndexEntry parseIndexEntry(XContentParser parser) throws IOExcept // This is just an internal container to make stuff easier for returning private static class IndexEntry { List indexAliases = new ArrayList<>(); - ImmutableOpenMap indexMappings = ImmutableOpenMap.of(); + MappingMetaData indexMappings = null; Settings indexSettings = Settings.EMPTY; Settings indexDefaultSettings = Settings.EMPTY; - IndexEntry(List indexAliases, ImmutableOpenMap indexMappings, + IndexEntry(List indexAliases, MappingMetaData indexMappings, Settings indexSettings, Settings indexDefaultSettings) { if (indexAliases != null) this.indexAliases = indexAliases; if (indexMappings != null) this.indexMappings = indexMappings; @@ -364,7 +339,7 @@ private static class IndexEntry { public static GetIndexResponse fromXContent(XContentParser parser) throws IOException { ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); List indices = new ArrayList<>(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java index 6fb6da59735ef..9dc10ba07be1a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java @@ -86,7 +86,7 @@ protected GetIndexResponse read(StreamInput in) throws IOException { @Override protected void doMasterOperation(final GetIndexRequest request, String[] concreteIndices, final ClusterState state, final ActionListener listener) { - ImmutableOpenMap> mappingsResult = ImmutableOpenMap.of(); + ImmutableOpenMap mappingsResult = ImmutableOpenMap.of(); ImmutableOpenMap> aliasesResult = ImmutableOpenMap.of(); ImmutableOpenMap settings = ImmutableOpenMap.of(); ImmutableOpenMap defaultSettings = ImmutableOpenMap.of(); @@ -99,8 +99,7 @@ protected void doMasterOperation(final GetIndexRequest request, String[] concret case MAPPINGS: if (!doneMappings) { try { - mappingsResult = state.metaData().findMappings(concreteIndices, request.types(), - indicesService.getFieldFilter()); + mappingsResult = state.metaData().findMappings(concreteIndices, indicesService.getFieldFilter()); doneMappings = true; } catch (IOException e) { listener.onFailure(e); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java index aebcf8abb356f..a32cbfbf4d6c1 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.admin.indices.mapping.get; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.ParseField; @@ -30,57 +31,56 @@ import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.index.mapper.MapperService; import java.io.IOException; import java.util.Map; -import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY; - public class GetMappingsResponse extends ActionResponse implements ToXContentFragment { private static final ParseField MAPPINGS = new ParseField("mappings"); - private ImmutableOpenMap> mappings = ImmutableOpenMap.of(); + private ImmutableOpenMap mappings; - public GetMappingsResponse(ImmutableOpenMap> mappings) { + public GetMappingsResponse(ImmutableOpenMap mappings) { this.mappings = mappings; } GetMappingsResponse(StreamInput in) throws IOException { super(in); int size = in.readVInt(); - ImmutableOpenMap.Builder> indexMapBuilder = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder indexMapBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { String key = in.readString(); - int valueSize = in.readVInt(); - ImmutableOpenMap.Builder typeMapBuilder = ImmutableOpenMap.builder(); - for (int j = 0; j < valueSize; j++) { - typeMapBuilder.put(in.readString(), new MappingMetaData(in)); + if (in.getVersion().before(Version.V_8_0_0)) { + int valueSize = in.readVInt(); + assert valueSize == 1 : "Expected single mapping but got " + valueSize; + String type = in.readString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] type but got [" + type + "]"; } - indexMapBuilder.put(key, typeMapBuilder.build()); + indexMapBuilder.put(key, new MappingMetaData(in)); } mappings = indexMapBuilder.build(); } - public ImmutableOpenMap> mappings() { + public ImmutableOpenMap mappings() { return mappings; } - public ImmutableOpenMap> getMappings() { + public ImmutableOpenMap getMappings() { return mappings(); } @Override public void writeTo(StreamOutput out) throws IOException { out.writeVInt(mappings.size()); - for (ObjectObjectCursor> indexEntry : mappings) { + for (ObjectObjectCursor indexEntry : mappings) { out.writeString(indexEntry.key); - out.writeVInt(indexEntry.value.size()); - for (ObjectObjectCursor typeEntry : indexEntry.value) { - out.writeString(typeEntry.key); - typeEntry.value.writeTo(out); + if (out.getVersion().before(Version.V_8_0_0)) { + out.writeVInt(1); + out.writeString(MapperService.SINGLE_MAPPING_NAME); } + indexEntry.value.writeTo(out); } } @@ -91,22 +91,12 @@ public static GetMappingsResponse fromXContent(XContentParser parser) throws IOE assert parser.currentToken() == XContentParser.Token.START_OBJECT; Map parts = parser.map(); - ImmutableOpenMap.Builder> builder = new ImmutableOpenMap.Builder<>(); + ImmutableOpenMap.Builder builder = new ImmutableOpenMap.Builder<>(); for (Map.Entry entry : parts.entrySet()) { final String indexName = entry.getKey(); assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass(); final Map mapping = (Map) ((Map) entry.getValue()).get(MAPPINGS.getPreferredName()); - - ImmutableOpenMap.Builder typeBuilder = new ImmutableOpenMap.Builder<>(); - for (Map.Entry typeEntry : mapping.entrySet()) { - final String typeName = typeEntry.getKey(); - assert typeEntry.getValue() instanceof Map : "expected a map as inner type mapping, but got: " + - typeEntry.getValue().getClass(); - final Map fieldMappings = (Map) typeEntry.getValue(); - MappingMetaData mmd = new MappingMetaData(typeName, fieldMappings); - typeBuilder.put(typeName, mmd); - } - builder.put(indexName, typeBuilder.build()); + builder.put(indexName, new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, mapping)); } return new GetMappingsResponse(builder.build()); @@ -114,32 +104,16 @@ public static GetMappingsResponse fromXContent(XContentParser parser) throws IOE @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - boolean includeTypeName = params.paramAsBoolean(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, - DEFAULT_INCLUDE_TYPE_NAME_POLICY); - for (final ObjectObjectCursor> indexEntry : getMappings()) { + for (final ObjectObjectCursor indexEntry : getMappings()) { builder.startObject(indexEntry.key); { - if (includeTypeName == false) { - MappingMetaData mappings = null; - for (final ObjectObjectCursor typeEntry : indexEntry.value) { - assert mappings == null; - mappings = typeEntry.value; - } - if (mappings == null) { - // no mappings yet - builder.startObject(MAPPINGS.getPreferredName()).endObject(); - } else { - builder.field(MAPPINGS.getPreferredName(), mappings.sourceAsMap()); - } + MappingMetaData mappings = indexEntry.value; + if (mappings == null) { + // no mappings yet + builder.startObject(MAPPINGS.getPreferredName()).endObject(); } else { - builder.startObject(MAPPINGS.getPreferredName()); - { - for (final ObjectObjectCursor typeEntry : indexEntry.value) { - builder.field(typeEntry.key, typeEntry.value.sourceAsMap()); - } - } - builder.endObject(); + builder.field(MAPPINGS.getPreferredName(), mappings.sourceAsMap()); } } builder.endObject(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java index 6a53762461665..57f84c97c0ffb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java @@ -76,8 +76,8 @@ protected void doMasterOperation(final GetMappingsRequest request, String[] conc final ActionListener listener) { logger.trace("serving getMapping request based on version {}", state.version()); try { - ImmutableOpenMap> result = - state.metaData().findMappings(concreteIndices, request.types(), indicesService.getFieldFilter()); + ImmutableOpenMap result = + state.metaData().findMappings(concreteIndices, indicesService.getFieldFilter()); listener.onResponse(new GetMappingsResponse(result)); } catch (IOException e) { listener.onFailure(e); diff --git a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java index d41d9dcec926f..662347fbf59b4 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java @@ -19,6 +19,7 @@ package org.elasticsearch.action.support.master.info; +import org.elasticsearch.Version; import org.elasticsearch.action.IndicesRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.MasterNodeReadRequest; @@ -32,7 +33,6 @@ public abstract class ClusterInfoRequest> findAliases(final String[] } /** - * Finds all mappings for types and concrete indices. Types are expanded to include all types that match the glob - * patterns in the types array. Empty types array, null or {"_all"} will be expanded to all types available for - * the given indices. Only fields that match the provided field filter will be returned (default is a predicate - * that always returns true, which can be overridden via plugins) + * Finds all mappings for concrete indices. Only fields that match the provided field + * filter will be returned (default is a predicate that always returns true, which can be + * overridden via plugins) * * @see MapperPlugin#getFieldFilter() * */ - public ImmutableOpenMap> findMappings(String[] concreteIndices, - final String[] types, - Function> fieldFilter) + public ImmutableOpenMap findMappings(String[] concreteIndices, + Function> fieldFilter) throws IOException { - assert types != null; assert concreteIndices != null; if (concreteIndices.length == 0) { return ImmutableOpenMap.of(); } - boolean isAllTypes = isAllTypes(types); - ImmutableOpenMap.Builder> indexMapBuilder = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder indexMapBuilder = ImmutableOpenMap.builder(); Iterable intersection = HppcMaps.intersection(ObjectHashSet.from(concreteIndices), indices.keys()); for (String index : intersection) { IndexMetaData indexMetaData = indices.get(index); Predicate fieldPredicate = fieldFilter.apply(index); - if (isAllTypes) { - indexMapBuilder.put(index, filterFields(indexMetaData.getMappings(), fieldPredicate)); - } else { - ImmutableOpenMap.Builder filteredMappings = ImmutableOpenMap.builder(); - for (ObjectObjectCursor cursor : indexMetaData.getMappings()) { - if (Regex.simpleMatch(types, cursor.key)) { - filteredMappings.put(cursor.key, filterFields(cursor.value, fieldPredicate)); - } - } - if (!filteredMappings.isEmpty()) { - indexMapBuilder.put(index, filteredMappings.build()); - } - } + indexMapBuilder.put(index, filterFields(indexMetaData.mapping(), fieldPredicate)); } return indexMapBuilder.build(); } - private static ImmutableOpenMap filterFields(ImmutableOpenMap mappings, - Predicate fieldPredicate) throws IOException { - if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) { - return mappings; - } - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(mappings.size()); - for (ObjectObjectCursor cursor : mappings) { - builder.put(cursor.key, filterFields(cursor.value, fieldPredicate)); - } - return builder.build(); // No types specified means return them all - } - @SuppressWarnings("unchecked") private static MappingMetaData filterFields(MappingMetaData mappingMetaData, Predicate fieldPredicate) throws IOException { if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) { diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java index 7be8871ee06be..442eb54ecc57b 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java @@ -127,7 +127,7 @@ public void testNonNestedMappings() throws Exception { GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); - ImmutableOpenMap mappings = response.mappings().get("test"); + ImmutableOpenMap mappings = response.mappings(); assertNotNull(mappings); MappingMetaData metadata = mappings.get("_doc"); @@ -141,7 +141,7 @@ public void testEmptyNestedMappings() throws Exception { GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); - ImmutableOpenMap mappings = response.mappings().get("test"); + ImmutableOpenMap mappings = response.mappings(); assertNotNull(mappings); MappingMetaData metadata = mappings.get("_doc"); @@ -165,7 +165,7 @@ public void testEmptyMappings() throws Exception { GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); - ImmutableOpenMap mappings = response.mappings().get("test"); + ImmutableOpenMap mappings = response.mappings(); assertNotNull(mappings); MappingMetaData metadata = mappings.get("_doc"); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java index 91479e4bfe192..5f02ba9dc4b00 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java @@ -45,6 +45,7 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; @ESIntegTestCase.SuiteScopeTestCase public class GetIndexIT extends ESIntegTestCase { @@ -230,24 +231,21 @@ private void assertNonEmptySettings(GetIndexResponse response, String indexName) } private void assertMappings(GetIndexResponse response, String indexName) { - ImmutableOpenMap> mappings = response.mappings(); + ImmutableOpenMap mappings = response.mappings(); assertThat(mappings, notNullValue()); assertThat(mappings.size(), equalTo(1)); - ImmutableOpenMap indexMappings = mappings.get(indexName); + MappingMetaData indexMappings = mappings.get(indexName); assertThat(indexMappings, notNullValue()); - assertThat(indexMappings.size(), equalTo(1)); - MappingMetaData mapping = indexMappings.get("type1"); - assertThat(mapping, notNullValue()); - assertThat(mapping.type(), equalTo("type1")); + assertThat(indexMappings, notNullValue()); + assertThat(indexMappings.type(), equalTo("type1")); } private void assertEmptyOrOnlyDefaultMappings(GetIndexResponse response, String indexName) { - ImmutableOpenMap> mappings = response.mappings(); + ImmutableOpenMap mappings = response.mappings(); assertThat(mappings, notNullValue()); assertThat(mappings.size(), equalTo(1)); - ImmutableOpenMap indexMappings = mappings.get(indexName); - assertThat(indexMappings, notNullValue()); - assertThat(indexMappings.size(), equalTo(0)); + MappingMetaData indexMappings = mappings.get(indexName); + assertThat(indexMappings, nullValue()); } private void assertAliases(GetIndexResponse response, String indexName) { diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexResponseTests.java index 1c277545cbbce..86d2b1ecaade4 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexResponseTests.java @@ -56,16 +56,14 @@ protected Writeable.Reader instanceReader() { @Override protected GetIndexResponse createTestInstance() { String[] indices = generateRandomStringArray(5, 5, false, false); - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); IndexScopedSettings indexScopedSettings = IndexScopedSettings.DEFAULT_SCOPED_SETTINGS; boolean includeDefaults = randomBoolean(); for (String index: indices) { - // rarely have no types - int typeCount = rarely() ? 0 : 1; - mappings.put(index, GetMappingsResponseTests.createMappingsForIndex(typeCount, true)); + mappings.put(index, GetMappingsResponseTests.createMappingsForIndex()); List aliasMetaDataList = new ArrayList<>(); int aliasesNum = randomIntBetween(0, 3); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java index 6586d8af0ae5c..fa4638eb9d78a 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.admin.indices.mapping.get; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.Writeable; @@ -32,11 +31,8 @@ import org.elasticsearch.test.EqualsHashCodeTestUtils; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Objects; @@ -63,21 +59,9 @@ protected Writeable.Reader instanceReader() { } private static GetMappingsResponse mutate(GetMappingsResponse original) throws IOException { - ImmutableOpenMap.Builder> builder = ImmutableOpenMap.builder(original.mappings()); + ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(original.mappings()); String indexKey = original.mappings().keys().iterator().next().value; - - ImmutableOpenMap.Builder typeBuilder = ImmutableOpenMap.builder(original.mappings().get(indexKey)); - final String typeKey; - Iterator> iter = original.mappings().get(indexKey).keys().iterator(); - if (iter.hasNext()) { - typeKey = iter.next().value; - } else { - typeKey = "new-type"; - } - - typeBuilder.put(typeKey, new MappingMetaData("type-" + randomAlphaOfLength(6), randomFieldMapping())); - - builder.put(indexKey, typeBuilder.build()); + builder.put(indexKey, new MappingMetaData("type-" + randomAlphaOfLength(6), randomFieldMapping())); return new GetMappingsResponse(builder.build()); } @@ -86,32 +70,22 @@ protected GetMappingsResponse mutateInstance(GetMappingsResponse instance) throw return mutate(instance); } - public static ImmutableOpenMap createMappingsForIndex(int typeCount, boolean randomTypeName) { - List typeMappings = new ArrayList<>(typeCount); - - for (int i = 0; i < typeCount; i++) { + public static MappingMetaData createMappingsForIndex() { + try { if (rarely() == false) { // rarely have no fields Map mappings = new HashMap<>(); - mappings.put("field-" + i, randomFieldMapping()); + mappings.put("field-1", randomFieldMapping()); if (randomBoolean()) { - mappings.put("field2-" + i, randomFieldMapping()); - } - - try { - String typeName = MapperService.SINGLE_MAPPING_NAME; - if (randomTypeName) { - typeName = "type-" + randomAlphaOfLength(5); - } - MappingMetaData mmd = new MappingMetaData(typeName, mappings); - typeMappings.add(mmd); - } catch (IOException e) { - fail("shouldn't have failed " + e); + mappings.put("field2-2", randomFieldMapping()); } + String typeName = MapperService.SINGLE_MAPPING_NAME; + return new MappingMetaData(typeName, mappings); } + return new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, Collections.emptyMap()); + } catch (IOException e) { + fail("shouldn't have failed " + e); } - ImmutableOpenMap.Builder typeBuilder = ImmutableOpenMap.builder(); - typeMappings.forEach(mmd -> typeBuilder.put(mmd.type(), mmd)); - return typeBuilder.build(); + return null; // we never reach here } /** @@ -125,9 +99,8 @@ protected Params getToXContentParams() { @Override protected GetMappingsResponse createTestInstance() { - ImmutableOpenMap.Builder> indexBuilder = ImmutableOpenMap.builder(); - int typeCount = rarely() ? 0 : 1; - indexBuilder.put("index-" + randomAlphaOfLength(5), createMappingsForIndex(typeCount, randomBoolean())); + ImmutableOpenMap.Builder indexBuilder = ImmutableOpenMap.builder(); + indexBuilder.put("index-" + randomAlphaOfLength(5), createMappingsForIndex()); GetMappingsResponse resp = new GetMappingsResponse(indexBuilder.build()); logger.debug("--> created: {}", resp); return resp; diff --git a/server/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java b/server/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java index 5109f89d0dfee..78063bf0d6df6 100644 --- a/server/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationIT.java @@ -62,7 +62,7 @@ public void testBulkIndexCreatesMapping() throws Exception { assertBusy(() -> { GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get(); assertTrue(mappingsResponse.getMappings().containsKey("logstash-2014.03.30")); - assertTrue(mappingsResponse.getMappings().get("logstash-2014.03.30").containsKey("logs")); + assertNotNull(mappingsResponse.getMappings().get("logstash-2014.03.30")); }); } diff --git a/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java b/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java index a980e682095b9..f6cf601b4cfc8 100644 --- a/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java +++ b/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java @@ -60,7 +60,7 @@ public void testPutMappingDocumentation() throws Exception { // end::index-with-mapping GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get(); assertEquals(1, getMappingsResponse.getMappings().size()); - ImmutableOpenMap indexMapping = getMappingsResponse.getMappings().get("twitter"); + ImmutableOpenMap indexMapping = getMappingsResponse.getMappings(); assertThat(indexMapping.get("_doc"), instanceOf(MappingMetaData.class)); // we need to delete in order to create a fresh new index with another type @@ -95,7 +95,7 @@ public void testPutMappingDocumentation() throws Exception { // end::putMapping-request-source getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get(); assertEquals(1, getMappingsResponse.getMappings().size()); - indexMapping = getMappingsResponse.getMappings().get("twitter"); + indexMapping = getMappingsResponse.getMappings(); assertEquals(singletonMap("properties", singletonMap("name", singletonMap("type", "text"))), indexMapping.get("_doc").getSourceAsMap()); } diff --git a/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java b/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java index 6c0b9fb7f80c9..fd2484b782a35 100644 --- a/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java @@ -244,10 +244,10 @@ public void testLargeClusterStatePublishing() throws Exception { .setTimeout("60s").get()); ensureGreen(); // wait for green state, so its both green, and there are no more pending events MappingMetaData masterMappingMetaData = client().admin().indices() - .prepareGetMappings("test").setTypes("type").get().getMappings().get("test").get("type"); + .prepareGetMappings("test").get().getMappings().get("test"); for (Client client : clients()) { MappingMetaData mappingMetadata = client.admin().indices() - .prepareGetMappings("test").setTypes("type").setLocal(true).get().getMappings().get("test").get("type"); + .prepareGetMappings("test").setLocal(true).get().getMappings().get("test"); assertThat(mappingMetadata.source().string(), equalTo(masterMappingMetaData.source().string())); assertThat(mappingMetadata, equalTo(masterMappingMetaData)); } diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java index a709748d8ea7c..cb935bbac828f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java @@ -239,7 +239,7 @@ public void testDelayedMappingPropagationOnPrimary() throws Exception { // ...and wait for mappings to be available on master assertBusy(() -> { ImmutableOpenMap indexMappings = client().admin().indices() - .prepareGetMappings("index").get().getMappings().get("index"); + .prepareGetMappings("index").get().getMappings(); assertNotNull(indexMappings); MappingMetaData typeMappings = indexMappings.get("type"); assertNotNull(typeMappings); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateServiceTests.java index ac180d9e80ae8..3b054b92a2193 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataIndexStateServiceTests.java @@ -333,7 +333,7 @@ public void testAddIndexClosedBlocksReusesBlocks() { } public void testValidateShardLimit() { - int nodesInCluster = randomIntBetween(2,100); + int nodesInCluster = randomIntBetween(2,90); ClusterShardLimitIT.ShardCounts counts = forDataNodeCount(nodesInCluster); Settings clusterSettings = Settings.builder() .put(MetaData.SETTING_CLUSTER_MAX_SHARDS_PER_NODE.getKey(), counts.getShardsPerNode()) diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java index e9893f16f95c5..0c24f759f6e3a 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java @@ -515,25 +515,19 @@ public void testFindMappings() throws IOException { .putMapping("_doc", FIND_MAPPINGS_TEST_ITEM)).build(); { - ImmutableOpenMap> mappings = metaData.findMappings(Strings.EMPTY_ARRAY, - Strings.EMPTY_ARRAY, MapperPlugin.NOOP_FIELD_FILTER); + ImmutableOpenMap mappings = metaData.findMappings(Strings.EMPTY_ARRAY, + MapperPlugin.NOOP_FIELD_FILTER); assertEquals(0, mappings.size()); } { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - new String[]{"notfound"}, MapperPlugin.NOOP_FIELD_FILTER); - assertEquals(0, mappings.size()); - } - { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - Strings.EMPTY_ARRAY, MapperPlugin.NOOP_FIELD_FILTER); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index1"}, + MapperPlugin.NOOP_FIELD_FILTER); assertEquals(1, mappings.size()); assertIndexMappingsNotFiltered(mappings, "index1"); } { - ImmutableOpenMap> mappings = metaData.findMappings( - new String[]{"index1", "index2"}, - new String[]{randomBoolean() ? "_doc" : "_all"}, MapperPlugin.NOOP_FIELD_FILTER); + ImmutableOpenMap mappings = metaData.findMappings( + new String[]{"index1", "index2"}, MapperPlugin.NOOP_FIELD_FILTER); assertEquals(2, mappings.size()); assertIndexMappingsNotFiltered(mappings, "index1"); assertIndexMappingsNotFiltered(mappings, "index2"); @@ -551,31 +545,15 @@ public void testFindMappingsNoOpFilters() throws IOException { .putMapping(originalMappingMetaData)).build(); { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - randomBoolean() ? Strings.EMPTY_ARRAY : new String[]{"_all"}, MapperPlugin.NOOP_FIELD_FILTER); - ImmutableOpenMap index1 = mappings.get("index1"); - MappingMetaData mappingMetaData = index1.get("_doc"); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index1"}, + MapperPlugin.NOOP_FIELD_FILTER); + MappingMetaData mappingMetaData = mappings.get("index1"); assertSame(originalMappingMetaData, mappingMetaData); } { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - randomBoolean() ? Strings.EMPTY_ARRAY : new String[]{"_all"}, index -> field -> randomBoolean()); - ImmutableOpenMap index1 = mappings.get("index1"); - MappingMetaData mappingMetaData = index1.get("_doc"); - assertNotSame(originalMappingMetaData, mappingMetaData); - } - { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - new String[]{"_doc"}, MapperPlugin.NOOP_FIELD_FILTER); - ImmutableOpenMap index1 = mappings.get("index1"); - MappingMetaData mappingMetaData = index1.get("_doc"); - assertSame(originalMappingMetaData, mappingMetaData); - } - { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - new String[]{"_doc"}, index -> field -> randomBoolean()); - ImmutableOpenMap index1 = mappings.get("index1"); - MappingMetaData mappingMetaData = index1.get("_doc"); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index1"}, + index -> field -> randomBoolean()); + MappingMetaData mappingMetaData = mappings.get("index1"); assertNotSame(originalMappingMetaData, mappingMetaData); } } @@ -607,9 +585,8 @@ public void testFindMappingsWithFilters() throws IOException { .putMapping("_doc", mapping)).build(); { - ImmutableOpenMap> mappings = metaData.findMappings( - new String[]{"index1", "index2", "index3"}, - new String[]{"_doc"}, index -> { + ImmutableOpenMap mappings = metaData.findMappings( + new String[]{"index1", "index2", "index3"}, index -> { if (index.equals("index1")) { return field -> field.startsWith("name.") == false && field.startsWith("properties.key.") == false && field.equals("age") == false && field.equals("address.location") == false; @@ -625,11 +602,7 @@ public void testFindMappingsWithFilters() throws IOException { assertIndexMappingsNoFields(mappings, "index2"); assertIndexMappingsNotFiltered(mappings, "index3"); - ImmutableOpenMap index1Mappings = mappings.get("index1"); - assertNotNull(index1Mappings); - - assertEquals(1, index1Mappings.size()); - MappingMetaData docMapping = index1Mappings.get("_doc"); + MappingMetaData docMapping = mappings.get("index1"); assertNotNull(docMapping); Map sourceAsMap = docMapping.getSourceAsMap(); @@ -671,15 +644,13 @@ public void testFindMappingsWithFilters() throws IOException { } { - ImmutableOpenMap> mappings = metaData.findMappings( - new String[]{"index1", "index2" , "index3"}, - new String[]{"_doc"}, index -> field -> (index.equals("index3") && field.endsWith("keyword"))); + ImmutableOpenMap mappings = metaData.findMappings( + new String[]{"index1", "index2", "index3"}, + index -> field -> (index.equals("index3") && field.endsWith("keyword"))); assertIndexMappingsNoFields(mappings, "index1"); assertIndexMappingsNoFields(mappings, "index2"); - ImmutableOpenMap index3 = mappings.get("index3"); - assertEquals(1, index3.size()); - MappingMetaData mappingMetaData = index3.get("_doc"); + MappingMetaData mappingMetaData = mappings.get("index3"); Map sourceAsMap = mappingMetaData.getSourceAsMap(); assertEquals(3, sourceAsMap.size()); assertTrue(sourceAsMap.containsKey("_routing")); @@ -707,9 +678,8 @@ public void testFindMappingsWithFilters() throws IOException { } { - ImmutableOpenMap> mappings = metaData.findMappings( - new String[]{"index1", "index2" , "index3"}, - new String[]{"_doc"}, index -> field -> (index.equals("index2"))); + ImmutableOpenMap mappings = metaData.findMappings( + new String[]{"index1", "index2", "index3"}, index -> field -> (index.equals("index2"))); assertIndexMappingsNoFields(mappings, "index1"); assertIndexMappingsNoFields(mappings, "index3"); @@ -725,12 +695,9 @@ private IndexMetaData.Builder buildIndexMetaData(String name, String alias, Bool } @SuppressWarnings("unchecked") - private static void assertIndexMappingsNoFields(ImmutableOpenMap> mappings, + private static void assertIndexMappingsNoFields(ImmutableOpenMap mappings, String index) { - ImmutableOpenMap indexMappings = mappings.get(index); - assertNotNull(indexMappings); - assertEquals(1, indexMappings.size()); - MappingMetaData docMapping = indexMappings.get("_doc"); + MappingMetaData docMapping = mappings.get(index); assertNotNull(docMapping); Map sourceAsMap = docMapping.getSourceAsMap(); assertEquals(3, sourceAsMap.size()); @@ -741,13 +708,9 @@ private static void assertIndexMappingsNoFields(ImmutableOpenMap> mappings, + private static void assertIndexMappingsNotFiltered(ImmutableOpenMap mappings, String index) { - ImmutableOpenMap indexMappings = mappings.get(index); - assertNotNull(indexMappings); - - assertEquals(1, indexMappings.size()); - MappingMetaData docMapping = indexMappings.get("_doc"); + MappingMetaData docMapping = mappings.get(index); assertNotNull(docMapping); Map sourceAsMap = docMapping.getSourceAsMap(); diff --git a/server/src/test/java/org/elasticsearch/gateway/MetaDataWriteDataNodesIT.java b/server/src/test/java/org/elasticsearch/gateway/MetaDataWriteDataNodesIT.java index 93bd3a44de919..94176123050f8 100644 --- a/server/src/test/java/org/elasticsearch/gateway/MetaDataWriteDataNodesIT.java +++ b/server/src/test/java/org/elasticsearch/gateway/MetaDataWriteDataNodesIT.java @@ -110,8 +110,8 @@ public void testMetaWrittenWhenIndexIsClosedAndMetaUpdated() throws Exception { .endObject() .endObject()).get(); - GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings(index).addTypes("_doc").get(); - assertNotNull(((Map) (getMappingsResponse.getMappings().get(index).get("_doc").getSourceAsMap().get("properties"))) + GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings(index).get(); + assertNotNull(((Map) (getMappingsResponse.getMappings().get(index).getSourceAsMap().get("properties"))) .get("integer_field")); // make sure it was also written on red node although index is closed @@ -137,8 +137,8 @@ public void testMetaWrittenWhenIndexIsClosedAndMetaUpdated() throws Exception { .endObject() .endObject()).get(); - getMappingsResponse = client().admin().indices().prepareGetMappings(index).addTypes("_doc").get(); - assertNotNull(((Map) (getMappingsResponse.getMappings().get(index).get("_doc").getSourceAsMap().get("properties"))) + getMappingsResponse = client().admin().indices().prepareGetMappings(index).get(); + assertNotNull(((Map) (getMappingsResponse.getMappings().get(index).getSourceAsMap().get("properties"))) .get("float_field")); // make sure it was also written on red node although index is closed diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java index f51363cf8df34..c30bd93c5d228 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java @@ -73,7 +73,7 @@ public void testConflictingDynamicMappingsBulk() { } private static void assertMappingsHaveField(GetMappingsResponse mappings, String index, String type, String field) throws IOException { - ImmutableOpenMap indexMappings = mappings.getMappings().get("index"); + ImmutableOpenMap indexMappings = mappings.getMappings(); assertNotNull(indexMappings); MappingMetaData typeMappings = indexMappings.get(type); assertNotNull(typeMappings); @@ -111,7 +111,7 @@ public void run() { throw error.get(); } Thread.sleep(2000); - GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").setTypes("type").get(); + GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").get(); for (int i = 0; i < indexThreads.length; ++i) { assertMappingsHaveField(mappings, "index", "type", "field" + i); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java b/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java index 2608e16497214..fd8c91bb1e55e 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java @@ -85,8 +85,8 @@ public void testGetFieldMappings() { //double check that submitting the filtered mappings to an unfiltered index leads to the same get field mappings output //as the one coming from a filtered index with same mappings GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("filtered").get(); - ImmutableOpenMap filtered = getMappingsResponse.getMappings().get("filtered"); - assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filtered.get("_doc").getSourceAsMap())); + MappingMetaData filtered = getMappingsResponse.getMappings().get("filtered"); + assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filtered.getSourceAsMap())); GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("test").setFields("*").get(); assertEquals(1, response.mappings().size()); assertFieldMappings(response.mappings().get("test"), FILTERED_FLAT_FIELDS); @@ -104,8 +104,8 @@ public void testFieldCapabilities() { //double check that submitting the filtered mappings to an unfiltered index leads to the same field_caps output //as the one coming from a filtered index with same mappings GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("filtered").get(); - ImmutableOpenMap filteredMapping = getMappingsResponse.getMappings().get("filtered"); - assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filteredMapping.get("_doc").getSourceAsMap())); + MappingMetaData filteredMapping = getMappingsResponse.getMappings().get("filtered"); + assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filteredMapping.getSourceAsMap())); FieldCapabilitiesResponse test = client().fieldCaps(new FieldCapabilitiesRequest().fields("*").indices("test")).actionGet(); // properties.value is an object field in the new mapping filteredFields.add("properties.value"); @@ -142,12 +142,12 @@ private static void assertFieldMappings(Map> mappings) { + private void assertExpectedMappings(ImmutableOpenMap mappings) { assertEquals(2, mappings.size()); assertNotFiltered(mappings.get("index1")); - ImmutableOpenMap filtered = mappings.get("filtered"); + MappingMetaData filtered = mappings.get("filtered"); assertFiltered(filtered); - assertMappingsAreValid(filtered.get("_doc").getSourceAsMap()); + assertMappingsAreValid(filtered.getSourceAsMap()); } private void assertMappingsAreValid(Map sourceAsMap) { @@ -160,9 +160,7 @@ private void assertMappingsAreValid(Map sourceAsMap) { } @SuppressWarnings("unchecked") - private static void assertFiltered(ImmutableOpenMap mappings) { - assertEquals(1, mappings.size()); - MappingMetaData mappingMetaData = mappings.get("_doc"); + private static void assertFiltered(MappingMetaData mappingMetaData) { assertNotNull(mappingMetaData); Map sourceAsMap = mappingMetaData.getSourceAsMap(); assertEquals(4, sourceAsMap.size()); @@ -207,9 +205,7 @@ private static void assertFiltered(ImmutableOpenMap map } @SuppressWarnings("unchecked") - private static void assertNotFiltered(ImmutableOpenMap mappings) { - assertEquals(1, mappings.size()); - MappingMetaData mappingMetaData = mappings.get("_doc"); + private static void assertNotFiltered(MappingMetaData mappingMetaData) { assertNotNull(mappingMetaData); Map sourceAsMap = mappingMetaData.getSourceAsMap(); assertEquals(4, sourceAsMap.size()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java index d8066977fed8b..7cf592417efaf 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java @@ -51,7 +51,7 @@ public void testMultiFields() throws Exception { ); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); Map mappingSource = mappingMetaData.sourceAsMap(); Map titleFields = ((Map) XContentMapValues.extractValue("properties.title.fields", mappingSource)); @@ -79,7 +79,7 @@ public void testMultiFields() throws Exception { ); getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); mappingSource = mappingMetaData.sourceAsMap(); assertThat(((Map) XContentMapValues.extractValue("properties.title", mappingSource)).size(), equalTo(2)); @@ -109,7 +109,7 @@ public void testGeoPointMultiField() throws Exception { ); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); Map mappingSource = mappingMetaData.sourceAsMap(); Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource)); @@ -140,7 +140,7 @@ public void testCompletionMultiField() throws Exception { ); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); Map mappingSource = mappingMetaData.sourceAsMap(); Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource)); @@ -165,7 +165,7 @@ public void testIpMultiField() throws Exception { ); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); Map mappingSource = mappingMetaData.sourceAsMap(); Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource)); diff --git a/server/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java b/server/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java index e922fcca9c5a7..13eab9c241aa9 100644 --- a/server/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java @@ -538,27 +538,27 @@ public void testPutMapping() throws Exception { } 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()); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), 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()); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), 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()); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), 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()); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), 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()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), notNullValue()); } public static final class TestPlugin extends Plugin { diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java index c52cd313a8e6c..71a58f5864ccb 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java @@ -41,6 +41,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertBlocked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; public class SimpleGetMappingsIT extends ESIntegTestCase { @@ -53,7 +54,7 @@ public void testGetMappingsWhereThereAreNone() { createIndex("index"); GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet(); assertThat(response.mappings().containsKey("index"), equalTo(true)); - assertThat(response.mappings().get("index").size(), equalTo(0)); + assertThat(response.mappings().get("index"), nullValue()); } private XContentBuilder getMappingForType(String type) throws IOException { @@ -77,50 +78,19 @@ public void testSimpleGetMappings() throws Exception { // Get all mappings GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet(); assertThat(response.mappings().size(), equalTo(2)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - assertThat(response.mappings().get("indexb").size(), equalTo(1)); - assertThat(response.mappings().get("indexb").get("typeA"), notNullValue()); + assertThat(response.mappings().get("indexa"), notNullValue()); + assertThat(response.mappings().get("indexb"), notNullValue()); // Get all mappings, via wildcard support - response = client().admin().indices().prepareGetMappings("*").setTypes("*").execute().actionGet(); + response = client().admin().indices().prepareGetMappings("*").execute().actionGet(); assertThat(response.mappings().size(), equalTo(2)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - assertThat(response.mappings().get("indexb").size(), equalTo(1)); - assertThat(response.mappings().get("indexb").get("typeA"), notNullValue()); - - // Get all typeA mappings in all indices - response = client().admin().indices().prepareGetMappings("*").setTypes("typeA").execute().actionGet(); - assertThat(response.mappings().size(), equalTo(2)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - assertThat(response.mappings().get("indexb").size(), equalTo(1)); - assertThat(response.mappings().get("indexb").get("typeA"), notNullValue()); + assertThat(response.mappings().get("indexa"), notNullValue()); + assertThat(response.mappings().get("indexb"), notNullValue()); // Get all mappings in indexa response = client().admin().indices().prepareGetMappings("indexa").execute().actionGet(); assertThat(response.mappings().size(), equalTo(1)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - - // Get all mappings beginning with A* in indexa - response = client().admin().indices().prepareGetMappings("indexa").setTypes("*A").execute().actionGet(); - assertThat(response.mappings().size(), equalTo(1)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - - // Get all mappings beginning with B* in all indices - response = client().admin().indices().prepareGetMappings().setTypes("B*").execute().actionGet(); - assertThat(response.mappings().size(), equalTo(0)); - - // Get all mappings beginning with B* and A* in all indices - response = client().admin().indices().prepareGetMappings().setTypes("B*", "*A").execute().actionGet(); - assertThat(response.mappings().size(), equalTo(2)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - assertThat(response.mappings().get("indexb").size(), equalTo(1)); - assertThat(response.mappings().get("indexb").get("typeA"), notNullValue()); + assertThat(response.mappings().get("indexa"), notNullValue()); } public void testGetMappingsWithBlocks() throws IOException { @@ -134,7 +104,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(1)); + assertThat(response.mappings().get("test"), notNullValue()); } finally { disableIndexBlock("test", block); } diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java index 19f7324db435d..0392153b42739 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -28,7 +28,6 @@ import org.elasticsearch.cluster.action.index.MappingUpdatedAction; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.Priority; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; @@ -129,7 +128,7 @@ public void testUpdateMappingWithoutType() { assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet(); - assertThat(getMappingsResponse.mappings().get("test").get("_doc").source().toString(), + assertThat(getMappingsResponse.mappings().get("test").source().toString(), equalTo("{\"_doc\":{\"properties\":{\"body\":{\"type\":\"text\"},\"date\":{\"type\":\"integer\"}}}}")); } @@ -149,7 +148,7 @@ public void testUpdateMappingWithoutTypeMultiObjects() { assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet(); - assertThat(getMappingsResponse.mappings().get("test").get("_doc").source().toString(), + assertThat(getMappingsResponse.mappings().get("test").source().toString(), equalTo("{\"_doc\":{\"properties\":{\"date\":{\"type\":\"integer\"}}}}")); } @@ -243,9 +242,8 @@ public void testUpdateMappingConcurrently() throws Throwable { assertThat(response.isAcknowledged(), equalTo(true)); GetMappingsResponse getMappingResponse = client2.admin().indices().prepareGetMappings(indexName).get(); - ImmutableOpenMap mappings = getMappingResponse.getMappings().get(indexName); - assertThat(mappings.containsKey(typeName), equalTo(true)); - assertThat(((Map) mappings.get(typeName).getSourceAsMap().get("properties")).keySet(), + MappingMetaData mappings = getMappingResponse.getMappings().get(indexName); + assertThat(((Map) mappings.getSourceAsMap().get("properties")).keySet(), Matchers.hasItem(fieldName)); } } catch (Exception e) { @@ -315,10 +313,8 @@ private void assertConcreteMappingsOnAll(final String index, final String type, * Waits for the given mapping type to exists on the master node. */ private void assertMappingOnMaster(final String index, final String type, final String... fieldNames) { - GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).setTypes(type).get(); - ImmutableOpenMap mappings = response.getMappings().get(index); - assertThat(mappings, notNullValue()); - MappingMetaData mappingMetaData = mappings.get(type); + GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).get(); + MappingMetaData mappingMetaData = response.getMappings().get(index); assertThat(mappingMetaData, notNullValue()); Map mappingSource = mappingMetaData.getSourceAsMap(); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java index 76e9751626bd9..69aa0b0dd9b0c 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java @@ -435,7 +435,7 @@ public void testFollowerMappingIsUpdated() throws IOException { clusterStateRequest.metaData(true); clusterStateRequest.indices(followerIndex); MappingMetaData mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() - .get("index2").get("doc"); + .get("index2"); assertThat(XContentMapValues.extractValue("properties.k.type", mappingMetaData.sourceAsMap()), equalTo("long")); } finally { for (MockTransportService transportService : transportServices) { diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index 4a6c00505ca09..d55e564dd6669 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -369,7 +369,7 @@ public void testSyncMappings() throws Exception { assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get() .getHits().getTotalHits().value, equalTo(firstBatchNumDocs))); MappingMetaData mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() - .get("index2").get("doc"); + .get("index2"); assertThat(XContentMapValues.extractValue("properties.f.type", mappingMetaData.sourceAsMap()), equalTo("integer")); assertThat(XContentMapValues.extractValue("properties.k", mappingMetaData.sourceAsMap()), nullValue()); @@ -382,7 +382,7 @@ public void testSyncMappings() throws Exception { assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs))); mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() - .get("index2").get("doc"); + .get("index2"); assertThat(XContentMapValues.extractValue("properties.f.type", mappingMetaData.sourceAsMap()), equalTo("integer")); assertThat(XContentMapValues.extractValue("properties.k.type", mappingMetaData.sourceAsMap()), equalTo("long")); pauseFollow("index2"); @@ -406,7 +406,7 @@ public void testNoMappingDefined() throws Exception { pauseFollow("index2"); MappingMetaData mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() - .get("index2").get("doc"); + .get("index2"); assertThat(XContentMapValues.extractValue("properties.f.type", mappingMetaData.sourceAsMap()), equalTo("long")); assertThat(XContentMapValues.extractValue("properties.k", mappingMetaData.sourceAsMap()), nullValue()); } @@ -1009,7 +1009,7 @@ public void testUpdateAnalysisLeaderIndexSettings() throws Exception { GetMappingsRequest getMappingsRequest = new GetMappingsRequest(); getMappingsRequest.indices("follower"); GetMappingsResponse getMappingsResponse = followerClient().admin().indices().getMappings(getMappingsRequest).actionGet(); - MappingMetaData mappingMetaData = getMappingsResponse.getMappings().get("follower").get("doc"); + MappingMetaData mappingMetaData = getMappingsResponse.getMappings().get("follower"); assertThat(XContentMapValues.extractValue("properties.new_field.type", mappingMetaData.sourceAsMap()), equalTo("text")); assertThat(XContentMapValues.extractValue("properties.new_field.analyzer", mappingMetaData.sourceAsMap()), equalTo("my_analyzer")); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java index 804e9c8dcda69..16fd442c0699d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java @@ -1156,13 +1156,12 @@ public static XContentBuilder auditMessageMapping() throws IOException { static String[] mappingRequiresUpdate(ClusterState state, String[] concreteIndices, Version minVersion) throws IOException { List indicesToUpdate = new ArrayList<>(); - ImmutableOpenMap> currentMapping = state.metaData().findMappings(concreteIndices, - new String[0], MapperPlugin.NOOP_FIELD_FILTER); + ImmutableOpenMap currentMapping = state.metaData().findMappings(concreteIndices, + MapperPlugin.NOOP_FIELD_FILTER); for (String index : concreteIndices) { - ImmutableOpenMap innerMap = currentMapping.get(index); - if (innerMap != null) { - MappingMetaData metaData = innerMap.valuesIt().next(); + MappingMetaData metaData = currentMapping.get(index); + if (metaData != null) { try { @SuppressWarnings("unchecked") Map meta = (Map) metaData.sourceAsMap().get("_meta"); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java index a54c57aceb3a6..605d3081790fa 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java @@ -16,7 +16,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -147,9 +146,8 @@ public void testSnapshotAndRestoreWithNested() throws Exception { private void assertMappings(String sourceIdx, boolean requireRouting, boolean useNested) throws IOException { GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings(sourceIdx).get(); - ImmutableOpenMap mapping = getMappingsResponse + MappingMetaData mapping = getMappingsResponse .getMappings().get(sourceIdx); - assertTrue(mapping.containsKey("_doc")); String nested = useNested ? ",\"incorrect\":{\"type\":\"object\"},\"nested\":{\"type\":\"nested\",\"properties\":{\"value\":{\"type\":\"long\"}}}" : ""; if (requireRouting) { @@ -157,12 +155,12 @@ private void assertMappings(String sourceIdx, boolean requireRouting, boolean us "\"_meta\":{\"_doc\":{\"_routing\":{\"required\":true}," + "\"properties\":{\"field1\":{\"type\":\"text\"," + "\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}" + nested + - "}}}}}", mapping.get("_doc").source().string()); + "}}}}}", mapping.source().string()); } else { assertEquals("{\"_doc\":{\"enabled\":false," + "\"_meta\":{\"_doc\":{\"properties\":{\"field1\":{\"type\":\"text\"," + "\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}" + nested + "}}}}}", - mapping.get("_doc").source().string()); + mapping.source().string()); } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java index 22ee0df16c102..23c410917497f 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java @@ -1024,10 +1024,10 @@ public void testMappingsFilteringDuelWithSourceFiltering() throws Exception { { FieldPermissionsDefinition definition = new FieldPermissionsDefinition(new String[]{"*inner1"}, Strings.EMPTY_ARRAY); FieldPermissions fieldPermissions = new FieldPermissions(definition); - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index"}, - new String[]{"doc"}, index -> fieldPermissions::grantsAccessTo); - ImmutableOpenMap index = mappings.get("index"); - Map sourceAsMap = index.get("doc").getSourceAsMap(); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index"}, + index -> fieldPermissions::grantsAccessTo); + MappingMetaData index = mappings.get("index"); + Map sourceAsMap = index.getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map) sourceAsMap.get("properties"); assertEquals(2, properties.size()); @@ -1061,10 +1061,10 @@ public void testMappingsFilteringDuelWithSourceFiltering() throws Exception { { FieldPermissionsDefinition definition = new FieldPermissionsDefinition(new String[]{"object*"}, Strings.EMPTY_ARRAY); FieldPermissions fieldPermissions = new FieldPermissions(definition); - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index"}, - new String[]{"doc"}, index -> fieldPermissions::grantsAccessTo); - ImmutableOpenMap index = mappings.get("index"); - Map sourceAsMap = index.get("doc").getSourceAsMap(); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index"}, + index -> fieldPermissions::grantsAccessTo); + MappingMetaData index = mappings.get("index"); + Map sourceAsMap = index.getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map) sourceAsMap.get("properties"); assertEquals(1, properties.size()); @@ -1097,10 +1097,10 @@ public void testMappingsFilteringDuelWithSourceFiltering() throws Exception { { FieldPermissionsDefinition definition = new FieldPermissionsDefinition(new String[]{"object"}, Strings.EMPTY_ARRAY); FieldPermissions fieldPermissions = new FieldPermissions(definition); - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index"}, - new String[]{"doc"}, index -> fieldPermissions::grantsAccessTo); - ImmutableOpenMap index = mappings.get("index"); - Map sourceAsMap = index.get("doc").getSourceAsMap(); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index"}, + index -> fieldPermissions::grantsAccessTo); + MappingMetaData index = mappings.get("index"); + Map sourceAsMap = index.getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map) sourceAsMap.get("properties"); assertEquals(1, properties.size()); @@ -1123,10 +1123,10 @@ public void testMappingsFilteringDuelWithSourceFiltering() throws Exception { { FieldPermissionsDefinition definition = new FieldPermissionsDefinition(new String[]{"nested.inner2"}, Strings.EMPTY_ARRAY); FieldPermissions fieldPermissions = new FieldPermissions(definition); - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index"}, - new String[]{"doc"}, index -> fieldPermissions::grantsAccessTo); - ImmutableOpenMap index = mappings.get("index"); - Map sourceAsMap = index.get("doc").getSourceAsMap(); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index"}, + index -> fieldPermissions::grantsAccessTo); + MappingMetaData index = mappings.get("index"); + Map sourceAsMap = index.getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map) sourceAsMap.get("properties"); assertEquals(1, properties.size()); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndex.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndex.java index c19472e22a84e..182c1f98bf044 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndex.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndex.java @@ -183,7 +183,7 @@ public static void updateMappingsToDestIndex(Client client, DataFrameAnalyticsCo // We have validated the destination index should match a single index assert getIndexResponse.indices().length == 1; - ImmutableOpenMap mappings = getIndexResponse.getMappings().get(getIndexResponse.indices()[0]); + ImmutableOpenMap mappings = getIndexResponse.getMappings(); String type = mappings.keysIt().next(); Map addedMappings = Map.of(PROPERTIES, Map.of(ID_COPY, Map.of("type", "keyword"))); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java index f007831f7cfa4..ec33004571c16 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java @@ -45,26 +45,17 @@ public static void mergeMappings(Client client, Map headers, Str } static ImmutableOpenMap mergeMappings(GetMappingsResponse getMappingsResponse) { - ImmutableOpenMap> indexToMappings = getMappingsResponse.getMappings(); + ImmutableOpenMap indexToMappings = getMappingsResponse.getMappings(); String type = null; Map mergedMappings = new HashMap<>(); - Iterator>> iterator = indexToMappings.iterator(); + Iterator> iterator = indexToMappings.iterator(); while (iterator.hasNext()) { - ObjectObjectCursor> indexMappings = iterator.next(); - Iterator> typeIterator = indexMappings.value.iterator(); - while (typeIterator.hasNext()) { - ObjectObjectCursor typeMapping = typeIterator.next(); - if (type == null) { - type = typeMapping.key; - } else { - if (type.equals(typeMapping.key) == false) { - throw ExceptionsHelper.badRequestException("source indices contain mappings for different types: [{}, {}]", - type, typeMapping.key); - } - } - Map currentMappings = typeMapping.value.getSourceAsMap(); + ObjectObjectCursor indexMappings = iterator.next(); + MappingMetaData mapping = indexMappings.value; + if (mapping != null) { + Map currentMappings = mapping.getSourceAsMap(); if (currentMappings.containsKey("properties")) { @SuppressWarnings("unchecked") diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java index d9a2bc2e5c300..0addea3d355e8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java @@ -45,7 +45,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; @@ -311,12 +310,10 @@ public void createJobResultIndex(Job job, ClusterState state, final ActionListen // just been created. So we need yet another operation to get the mappings for it. getLatestIndexMappings(indexName, ActionListener.wrap( response -> { - // Expect one index and one type. If this is not the case then it means the + // Expect one index. If this is not the case then it means the // index has been deleted almost immediately after being created, and this is // so unlikely that it's reasonable to fail the whole operation. - ImmutableOpenMap indexMappings = - response.getMappings().iterator().next().value; - MappingMetaData typeMappings = indexMappings.iterator().next().value; + MappingMetaData typeMappings = response.getMappings().iterator().next().value; addTermsAndAliases(typeMappings, indexName, termFields, createAliasListener); }, finalListener::onFailure diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndexTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndexTests.java index 82b8b0a6c65b8..895942e3d9fbd 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndexTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndexTests.java @@ -119,14 +119,9 @@ public void testCreateDestinationIndex() throws IOException { Map index2Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings", "field_2", "field_2_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("_doc", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("_doc", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java index 670f6e559bd4f..36eb7c3acd17b 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java @@ -29,14 +29,9 @@ public void testMergeMappings_GivenIndicesWithIdenticalMappings() throws IOExcep Map index2Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings", "field_2", "field_2_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("_doc", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("_doc", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); @@ -54,14 +49,9 @@ public void testMergeMappings_GivenIndicesWithDifferentTypes() throws IOExceptio Map index2Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("type_1", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("type_2", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); @@ -80,14 +70,9 @@ public void testMergeMappings_GivenFieldWithDifferentMapping() throws IOExceptio Map index2Mappings = Map.of("properties", Map.of("field_1", "different_field_1_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("_doc", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("_doc", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); @@ -106,14 +91,9 @@ public void testMergeMappings_GivenIndicesWithDifferentMappingsButNoConflicts() Map.of("field_1", "field_1_mappings", "field_3", "field_3_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("_doc", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("_doc", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java index 3c62db210f763..3b1ecf377f8d4 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java @@ -120,12 +120,11 @@ public void testMultipleSimultaneousJobCreations() { String sharedResultsIndex = AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + AnomalyDetectorsIndexFields.RESULTS_INDEX_DEFAULT; GetMappingsRequest request = new GetMappingsRequest().indices(sharedResultsIndex); GetMappingsResponse response = client().execute(GetMappingsAction.INSTANCE, request).actionGet(); - ImmutableOpenMap> indexMappings = response.getMappings(); + ImmutableOpenMap indexMappings = response.getMappings(); assertNotNull(indexMappings); - ImmutableOpenMap typeMappings = indexMappings.get(sharedResultsIndex); + MappingMetaData typeMappings = indexMappings.get(sharedResultsIndex); assertNotNull("expected " + sharedResultsIndex + " in " + indexMappings, typeMappings); - assertEquals("expected 1 type in " + typeMappings, 1, typeMappings.size()); - Map mappings = typeMappings.iterator().next().value.getSourceAsMap(); + Map mappings = typeMappings.getSourceAsMap(); assertNotNull(mappings); @SuppressWarnings("unchecked") Map properties = (Map) mappings.get("properties"); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java index 76b1b459c2165..061245f016a04 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java @@ -145,10 +145,7 @@ public void testCreateJobWithExistingIndex() { GetMappingsResponse getMappingsResponse = mock(GetMappingsResponse.class); ImmutableOpenMap typeMappings = ImmutableOpenMap.of(); - ImmutableOpenMap> mappings = - ImmutableOpenMap.>builder() - .fPut(AnomalyDetectorsIndex.jobResultsAliasedName("foo"), typeMappings).build(); - when(getMappingsResponse.mappings()).thenReturn(mappings); + when(getMappingsResponse.mappings()).thenReturn(typeMappings); clientBuilder.prepareGetMapping(getMappingsResponse); Job.Builder job = buildJobBuilder("foo123"); diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java index b18b917113802..c231200e57d6d 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java @@ -213,7 +213,7 @@ static void updateMapping(RollupJob job, ActionListener li final String indexName = job.getConfig().getRollupIndex(); CheckedConsumer getMappingResponseHandler = getMappingResponse -> { - MappingMetaData mappings = getMappingResponse.getMappings().get(indexName).get(RollupField.TYPE_NAME); + MappingMetaData mappings = getMappingResponse.getMappings().get(indexName); Object m = mappings.getSourceAsMap().get("_meta"); if (m == null) { String msg = "Rollup data cannot be added to existing indices that contain non-rollup data (expected " + diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java index 9f5359c9424de..29cfb8dec545d 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java @@ -199,11 +199,7 @@ public void testNoMetadataInMapping() { MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.emptyMap()); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); builder.put(RollupField.TYPE_NAME, meta); - - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(job.getConfig().getRollupIndex(), builder.build()); - - when(response.getMappings()).thenReturn(builder2.build()); + when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; }).when(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), requestCaptor.capture()); @@ -237,11 +233,7 @@ public void testMetadataButNotRollup() { Collections.singletonMap("_meta", m)); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); builder.put(RollupField.TYPE_NAME, meta); - - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(job.getConfig().getRollupIndex(), builder.build()); - - when(response.getMappings()).thenReturn(builder2.build()); + when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; }).when(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), requestCaptor.capture()); @@ -274,11 +266,7 @@ public void testNoMappingVersion() { Collections.singletonMap("_meta", m)); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); builder.put(RollupField.TYPE_NAME, meta); - - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(job.getConfig().getRollupIndex(), builder.build()); - - when(response.getMappings()).thenReturn(builder2.build()); + when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; }).when(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), requestCaptor.capture()); @@ -311,11 +299,7 @@ public void testJobAlreadyInMapping() { Collections.singletonMap("_meta", m)); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); builder.put(RollupField.TYPE_NAME, meta); - - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(job.getConfig().getRollupIndex(), builder.build()); - - when(response.getMappings()).thenReturn(builder2.build()); + when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; }).when(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), requestCaptor.capture()); @@ -352,11 +336,7 @@ public void testAddJobToMapping() { Collections.singletonMap("_meta", m)); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); builder.put(RollupField.TYPE_NAME, meta); - - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(unrelatedJob.getRollupIndex(), builder.build()); - - when(response.getMappings()).thenReturn(builder2.build()); + when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; }).when(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), requestCaptor.capture()); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java index ce235895e0fa2..d88827da0f6d6 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java @@ -398,9 +398,9 @@ public void testFieldCapabilitiesIsFiltered() { } @SuppressWarnings("unchecked") - private static void assertExpectedFields(ImmutableOpenMap> mappings, + private static void assertExpectedFields(ImmutableOpenMap mappings, String... fields) { - Map sourceAsMap = mappings.get("test").get("type1").getSourceAsMap(); + Map sourceAsMap = mappings.get("test").getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map)sourceAsMap.get("properties"); assertEquals(fields.length, properties.size()); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java index 19533542686de..7ffaac32b3441 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java @@ -155,11 +155,10 @@ public void testGetMappings() throws Exception { .indices() .prepareGetMappings("logstash-*") .get(); - ImmutableOpenMap> mappingsMap = response.getMappings(); + ImmutableOpenMap mappingsMap = response.getMappings(); assertNotNull(mappingsMap); assertNotNull(mappingsMap.get(index)); - assertNotNull(mappingsMap.get(index).get(type)); - MappingMetaData mappingMetaData = mappingsMap.get(index).get(type); + MappingMetaData mappingMetaData = mappingsMap.get(index); assertThat(mappingMetaData.getSourceAsMap(), hasKey("properties")); assertThat(mappingMetaData.getSourceAsMap().get("properties"), instanceOf(Map.class)); Map propertiesMap = (Map) mappingMetaData.getSourceAsMap().get("properties"); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index d97415ea8ca9d..2a80b2b4f6747 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -8,7 +8,6 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.index.query.QueryBuilders; @@ -33,7 +32,6 @@ import java.util.List; import java.util.Map; -import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -158,11 +156,10 @@ public void testExceptionMapping() { // ensure that enabled is set to false List indexed = new ArrayList<>(); GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings(HistoryStoreField.INDEX_PREFIX + "*").get(); - Iterator> iterator = mappingsResponse.getMappings().valuesIt(); + Iterator iterator = mappingsResponse.getMappings().valuesIt(); while (iterator.hasNext()) { - ImmutableOpenMap mapping = iterator.next(); - assertThat(mapping.containsKey(SINGLE_MAPPING_NAME), is(true)); - Map docMapping = mapping.get(SINGLE_MAPPING_NAME).getSourceAsMap(); + MappingMetaData mapping = iterator.next(); + Map docMapping = mapping.getSourceAsMap(); if (abortAtInput) { Boolean enabled = ObjectPath.eval("properties.result.properties.input.properties.error.enabled", docMapping); indexed.add(enabled); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java index 69d0ea9b0b0e6..d42ebf753a3a9 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; @@ -20,7 +19,6 @@ import java.util.Map; import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue; -import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME; import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction; import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput; @@ -50,11 +48,11 @@ public void testTimeFields() throws Exception { GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get(); assertThat(mappingsResponse, notNullValue()); assertThat(mappingsResponse.getMappings().isEmpty(), is(false)); - for (ObjectObjectCursor> metadatas : mappingsResponse.getMappings()) { + for (ObjectObjectCursor metadatas : mappingsResponse.getMappings()) { if (!metadatas.key.startsWith(HistoryStoreField.INDEX_PREFIX)) { continue; } - MappingMetaData metadata = metadatas.value.get(SINGLE_MAPPING_NAME); + MappingMetaData metadata = metadatas.value; assertThat(metadata, notNullValue()); try { Map source = metadata.getSourceAsMap(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 594bdb6258cc8..82a9cffc35a9d 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -263,7 +263,7 @@ private void createWatcherIndicesOrAliases() throws Exception { public void replaceWatcherIndexWithRandomlyNamedIndex(String originalIndexOrAlias, String to) { GetIndexResponse index = client().admin().indices().prepareGetIndex().setIndices(originalIndexOrAlias).get(); - MappingMetaData mapping = index.getMappings().get(index.getIndices()[0]).get(MapperService.SINGLE_MAPPING_NAME); + MappingMetaData mapping = index.getMappings().get(index.getIndices()[0]); Settings settings = index.getSettings().get(index.getIndices()[0]); Settings.Builder newSettings = Settings.builder().put(settings); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java index 7c9e3107042fc..5aab8a27a1b5b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java @@ -102,9 +102,8 @@ public void testFailedInputResultWithDotsInFieldNameGetsStored() throws Exceptio assertHitCount(searchResponse, 1); // as fields with dots are allowed in 5.0 again, the mapping must be checked in addition - GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*") - .addTypes(SINGLE_MAPPING_NAME).get(); - byte[] bytes = response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME).source().uncompressed(); + GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); + byte[] bytes = response.getMappings().values().iterator().next().value.source().uncompressed(); XContentSource source = new XContentSource(new BytesArray(bytes), XContentType.JSON); // lets make sure the body fields are disabled if (useChained) { @@ -143,9 +142,8 @@ public void testPayloadInputWithDotsInFieldNameWorks() throws Exception { assertHitCount(searchResponse, 1); // as fields with dots are allowed in 5.0 again, the mapping must be checked in addition - GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*") - .addTypes(SINGLE_MAPPING_NAME).get(); - byte[] bytes = response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME).source().uncompressed(); + GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); + byte[] bytes = response.getMappings().values().iterator().next().value.source().uncompressed(); XContentSource source = new XContentSource(new BytesArray(bytes), XContentType.JSON); // lets make sure the body fields are disabled @@ -201,9 +199,8 @@ public void testThatHistoryContainsStatus() throws Exception { assertThat(lastExecutionSuccesful, is(actionStatus.lastExecution().successful())); // also ensure that the status field is disabled in the watch history - GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*") - .addTypes(SINGLE_MAPPING_NAME).get(); - byte[] bytes = response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME).source().uncompressed(); + GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); + byte[] bytes = response.getMappings().values().iterator().next().value.source().uncompressed(); XContentSource mappingSource = new XContentSource(new BytesArray(bytes), XContentType.JSON); assertThat(mappingSource.getValue(SINGLE_MAPPING_NAME + ".properties.status.enabled"), is(false)); assertThat(mappingSource.getValue(SINGLE_MAPPING_NAME + ".properties.status.properties.status"), is(nullValue())); From e8e8ca99d9ca7d80c63b01d722ef1ec9303bdeef Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 2 Oct 2019 09:32:17 +0100 Subject: [PATCH 02/18] test failures --- .../test/indices.get/11_basic_with_types.yml | 73 ------------------- .../admin/indices/get/GetIndexResponse.java | 14 +--- .../action/PutJobStateMachineTests.java | 10 +-- 3 files changed, 9 insertions(+), 88 deletions(-) delete mode 100644 rest-api-spec/src/main/resources/rest-api-spec/test/indices.get/11_basic_with_types.yml diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get/11_basic_with_types.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get/11_basic_with_types.yml deleted file mode 100644 index 3ca4417870376..0000000000000 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.get/11_basic_with_types.yml +++ /dev/null @@ -1,73 +0,0 @@ ---- -setup: - - - do: - indices.create: - include_type_name: true - index: test_index - body: - aliases: - test_alias: {} - test_blias: {} - mappings: - type_1: {} - settings: - number_of_shards: 1 - number_of_replicas: 1 - - - do: - indices.create: - index: test_index_2 - body: - settings: - number_of_shards: 1 - number_of_replicas: 2 - aliases: - test_alias: {} - test_blias: {} - - - do: - indices.create: - index: test_index_3 - body: - aliases: - test_alias: {} - test_blias: {} - - - do: - indices.close: - index: test_index_3 - - - do: - cluster.health: - wait_for_status: yellow - ---- -"Test include_type_name": - - - - do: - indices.get: - include_type_name: true - index: test_index - - - is_true: test_index.mappings - - is_true: test_index.mappings.type_1 - - - do: - indices.get: - include_type_name: false - index: test_index - - - is_true: test_index.mappings - - is_false: test_index.mappings.type_1 - ---- -"Test include_type_name dafaults to false": - - - do: - indices.get: - index: test_index - - - is_true: test_index.mappings - - is_false: test_index.mappings.type_1 diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index 096c17130f08c..adafa7005014f 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -201,18 +201,12 @@ public void writeTo(StreamOutput out) throws IOException { for (ObjectObjectCursor indexEntry : mappings) { out.writeString(indexEntry.key); MappingMetaData mmd = indexEntry.value; + assert mmd != null; if (out.getVersion().before(Version.V_8_0_0)) { - if (mmd != null) { - out.writeVInt(1); - out.writeString(MapperService.SINGLE_MAPPING_NAME); - } - else { - out.writeVInt(0); - } - } - if (mmd != null) { - mmd.writeTo(out); + out.writeVInt(1); + out.writeString(MapperService.SINGLE_MAPPING_NAME); } + mmd.writeTo(out); } out.writeVInt(aliases.size()); for (ObjectObjectCursor> indexEntry : aliases) { diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java index 29cfb8dec545d..699209195f50a 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java @@ -198,7 +198,7 @@ public void testNoMetadataInMapping() { GetMappingsResponse response = mock(GetMappingsResponse.class); MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.emptyMap()); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); + builder.put(job.getConfig().getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; @@ -232,7 +232,7 @@ public void testMetadataButNotRollup() { MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.singletonMap("_meta", m)); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); + builder.put(job.getConfig().getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; @@ -265,7 +265,7 @@ public void testNoMappingVersion() { MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.singletonMap("_meta", m)); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); + builder.put(job.getConfig().getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; @@ -298,7 +298,7 @@ public void testJobAlreadyInMapping() { MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.singletonMap("_meta", m)); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); + builder.put(job.getConfig().getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; @@ -335,7 +335,7 @@ public void testAddJobToMapping() { MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.singletonMap("_meta", m)); ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); + builder.put("rollup_index_foo", meta); when(response.getMappings()).thenReturn(builder.build()); requestCaptor.getValue().onResponse(response); return null; From 04341c8ee3b2f23d740e6b891f5ec5f8fc496d9d Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 2 Oct 2019 15:11:50 +0100 Subject: [PATCH 03/18] null check --- .../java/org/elasticsearch/cluster/metadata/MetaData.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index d087552bf2544..34c17be87d8b6 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -386,8 +386,10 @@ public ImmutableOpenMap findMappings(String[] concreteI Iterable intersection = HppcMaps.intersection(ObjectHashSet.from(concreteIndices), indices.keys()); for (String index : intersection) { IndexMetaData indexMetaData = indices.get(index); - Predicate fieldPredicate = fieldFilter.apply(index); - indexMapBuilder.put(index, filterFields(indexMetaData.mapping(), fieldPredicate)); + if (indexMetaData.mapping() != null) { + Predicate fieldPredicate = fieldFilter.apply(index); + indexMapBuilder.put(index, filterFields(indexMetaData.mapping(), fieldPredicate)); + } } return indexMapBuilder.build(); } From 4a053c3f32ff99a8cb7a1e7bf08f87a36c8b4d5f Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 3 Oct 2019 10:26:01 +0100 Subject: [PATCH 04/18] null checks - need to work out what to do here --- .../action/admin/indices/get/GetIndexResponse.java | 1 - .../main/java/org/elasticsearch/cluster/metadata/MetaData.java | 3 +++ .../elasticsearch/cluster/coordination/RareClusterStateIT.java | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index adafa7005014f..2d221572a3bc1 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -201,7 +201,6 @@ public void writeTo(StreamOutput out) throws IOException { for (ObjectObjectCursor indexEntry : mappings) { out.writeString(indexEntry.key); MappingMetaData mmd = indexEntry.value; - assert mmd != null; if (out.getVersion().before(Version.V_8_0_0)) { out.writeVInt(1); out.writeString(MapperService.SINGLE_MAPPING_NAME); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 34c17be87d8b6..59f3272d717d9 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -390,6 +390,9 @@ public ImmutableOpenMap findMappings(String[] concreteI Predicate fieldPredicate = fieldFilter.apply(index); indexMapBuilder.put(index, filterFields(indexMetaData.mapping(), fieldPredicate)); } + else { + indexMapBuilder.put(index, null); + } } return indexMapBuilder.build(); } diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java index cb935bbac828f..6c1a026886cea 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java @@ -241,7 +241,7 @@ public void testDelayedMappingPropagationOnPrimary() throws Exception { ImmutableOpenMap indexMappings = client().admin().indices() .prepareGetMappings("index").get().getMappings(); assertNotNull(indexMappings); - MappingMetaData typeMappings = indexMappings.get("type"); + MappingMetaData typeMappings = indexMappings.get("index"); assertNotNull(typeMappings); Object properties; try { From b584dbe58fb40919865da04059415025ca3139e7 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 3 Oct 2019 13:58:54 +0100 Subject: [PATCH 05/18] Deal correctly with null mappings --- .../admin/indices/get/GetIndexResponse.java | 18 ++++++++++++++++-- .../mapping/get/GetMappingsResponse.java | 18 ++++++++++++++++-- .../admin/indices/create/CreateIndexIT.java | 6 +++--- .../indices/mapping/SimpleGetMappingsIT.java | 1 + 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index 2d221572a3bc1..4bf3633af84d6 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -92,8 +92,16 @@ public GetIndexResponse(String[] indices, assert valueSize == 1 : "Expected single mapping but got " + valueSize; String type = in.readString(); assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got " + type; + mappingsMapBuilder.put(key, new MappingMetaData(in)); + } + else { + if (in.readBoolean()) { + mappingsMapBuilder.put(key, new MappingMetaData(in)); + } + else { + mappingsMapBuilder.put(key, null); + } } - mappingsMapBuilder.put(key, new MappingMetaData(in)); } mappings = mappingsMapBuilder.build(); @@ -204,8 +212,14 @@ public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().before(Version.V_8_0_0)) { out.writeVInt(1); out.writeString(MapperService.SINGLE_MAPPING_NAME); + mmd.writeTo(out); + } + else { + out.writeBoolean(mmd != null); + if (mmd != null) { + mmd.writeTo(out); + } } - mmd.writeTo(out); } out.writeVInt(aliases.size()); for (ObjectObjectCursor> indexEntry : aliases) { diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java index a32cbfbf4d6c1..a64929e870f56 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -57,8 +57,16 @@ public GetMappingsResponse(ImmutableOpenMap mappings) { assert valueSize == 1 : "Expected single mapping but got " + valueSize; String type = in.readString(); assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] type but got [" + type + "]"; + indexMapBuilder.put(key, new MappingMetaData(in)); + } + else { + if (in.readBoolean()) { + indexMapBuilder.put(key, new MappingMetaData(in)); + } + else { + indexMapBuilder.put(key, null); + } } - indexMapBuilder.put(key, new MappingMetaData(in)); } mappings = indexMapBuilder.build(); } @@ -79,8 +87,14 @@ public void writeTo(StreamOutput out) throws IOException { if (out.getVersion().before(Version.V_8_0_0)) { out.writeVInt(1); out.writeString(MapperService.SINGLE_MAPPING_NAME); + indexEntry.value.writeTo(out); + } + else { + out.writeBoolean(indexEntry.value != null); + if (indexEntry.value != null) { + indexEntry.value.writeTo(out); + } } - indexEntry.value.writeTo(out); } } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java index 442eb54ecc57b..c8ebef90dd073 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java @@ -130,7 +130,7 @@ public void testNonNestedMappings() throws Exception { ImmutableOpenMap mappings = response.mappings(); assertNotNull(mappings); - MappingMetaData metadata = mappings.get("_doc"); + MappingMetaData metadata = mappings.get("test"); assertNotNull(metadata); assertFalse(metadata.sourceAsMap().isEmpty()); } @@ -144,7 +144,7 @@ public void testEmptyNestedMappings() throws Exception { ImmutableOpenMap mappings = response.mappings(); assertNotNull(mappings); - MappingMetaData metadata = mappings.get("_doc"); + MappingMetaData metadata = mappings.get("test"); assertNotNull(metadata); assertTrue(metadata.sourceAsMap().isEmpty()); } @@ -168,7 +168,7 @@ public void testEmptyMappings() throws Exception { ImmutableOpenMap mappings = response.mappings(); assertNotNull(mappings); - MappingMetaData metadata = mappings.get("_doc"); + MappingMetaData metadata = mappings.get("test"); assertNotNull(metadata); assertTrue(metadata.sourceAsMap().isEmpty()); } diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java index 71a58f5864ccb..eb79f8358a8de 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java @@ -19,6 +19,7 @@ package org.elasticsearch.indices.mapping; +import com.carrotsearch.randomizedtesting.annotations.Seed; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.common.Priority; From 8edbc27a4a3d45444fbb9dc092e1c54a82a3792f Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 3 Oct 2019 14:24:02 +0100 Subject: [PATCH 06/18] imports --- .../org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java index eb79f8358a8de..71a58f5864ccb 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java @@ -19,7 +19,6 @@ package org.elasticsearch.indices.mapping; -import com.carrotsearch.randomizedtesting.annotations.Seed; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.common.Priority; From 51382b96058f9301c1db976117694f67dc48443e Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 4 Oct 2019 11:58:50 +0100 Subject: [PATCH 07/18] Fix ml mapping merger --- .../xpack/ml/dataframe/MappingsMerger.java | 1 + .../ml/dataframe/MappingsMergerTests.java | 24 +------------------ 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java index ec33004571c16..992b0fb7bcc74 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java @@ -55,6 +55,7 @@ static ImmutableOpenMap mergeMappings(GetMappingsRespon ObjectObjectCursor indexMappings = iterator.next(); MappingMetaData mapping = indexMappings.value; if (mapping != null) { + type = mapping.type(); Map currentMappings = mapping.getSourceAsMap(); if (currentMappings.containsKey("properties")) { diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java index 36eb7c3acd17b..9defc670cbae8 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java @@ -16,7 +16,6 @@ import java.util.Map; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -41,28 +40,7 @@ public void testMergeMappings_GivenIndicesWithIdenticalMappings() throws IOExcep assertThat(mergedMappings.containsKey("_doc"), is(true)); assertThat(mergedMappings.valuesIt().next().getSourceAsMap(), equalTo(index1Mappings)); } - - public void testMergeMappings_GivenIndicesWithDifferentTypes() throws IOException { - Map index1Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings")); - MappingMetaData index1MappingMetaData = new MappingMetaData("_doc", index1Mappings); - - Map index2Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings")); - MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - - ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingMetaData); - mappings.put("index_2", index2MappingMetaData); - - GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); - - ElasticsearchStatusException e = expectThrows(ElasticsearchStatusException.class, - () -> MappingsMerger.mergeMappings(getMappingsResponse)); - assertThat(e.status(), equalTo(RestStatus.BAD_REQUEST)); - assertThat(e.getMessage(), containsString("source indices contain mappings for different types:")); - assertThat(e.getMessage(), containsString("type_1")); - assertThat(e.getMessage(), containsString("type_2")); - } - + public void testMergeMappings_GivenFieldWithDifferentMapping() throws IOException { Map index1Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings")); MappingMetaData index1MappingMetaData = new MappingMetaData("_doc", index1Mappings); From 5bfc3ba9cc9d000d8aa0cd89d8f63d8f06a2e11a Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 4 Oct 2019 13:27:52 +0100 Subject: [PATCH 08/18] tests --- .../client/documentation/IndicesDocumentationIT.java | 4 ++-- .../org/elasticsearch/index/mapper/DynamicMappingIT.java | 6 +++--- .../xpack/ml/dataframe/MappingsMergerTests.java | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java b/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java index f6cf601b4cfc8..32839e401b291 100644 --- a/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java +++ b/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java @@ -61,7 +61,7 @@ public void testPutMappingDocumentation() throws Exception { GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get(); assertEquals(1, getMappingsResponse.getMappings().size()); ImmutableOpenMap indexMapping = getMappingsResponse.getMappings(); - assertThat(indexMapping.get("_doc"), instanceOf(MappingMetaData.class)); + assertThat(indexMapping.get("twitter"), instanceOf(MappingMetaData.class)); // we need to delete in order to create a fresh new index with another type client.admin().indices().prepareDelete("twitter").get(); @@ -97,7 +97,7 @@ public void testPutMappingDocumentation() throws Exception { assertEquals(1, getMappingsResponse.getMappings().size()); indexMapping = getMappingsResponse.getMappings(); assertEquals(singletonMap("properties", singletonMap("name", singletonMap("type", "text"))), - indexMapping.get("_doc").getSourceAsMap()); + indexMapping.get("twitter").getSourceAsMap()); } } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java index c30bd93c5d228..1276cfa79de2e 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java @@ -72,10 +72,10 @@ public void testConflictingDynamicMappingsBulk() { assertTrue(bulkResponse.hasFailures()); } - private static void assertMappingsHaveField(GetMappingsResponse mappings, String index, String type, String field) throws IOException { + private static void assertMappingsHaveField(GetMappingsResponse mappings, String index, String field) throws IOException { ImmutableOpenMap indexMappings = mappings.getMappings(); assertNotNull(indexMappings); - MappingMetaData typeMappings = indexMappings.get(type); + MappingMetaData typeMappings = indexMappings.get(index); assertNotNull(typeMappings); Map typeMappingsMap = typeMappings.getSourceAsMap(); Map properties = (Map) typeMappingsMap.get("properties"); @@ -113,7 +113,7 @@ public void run() { Thread.sleep(2000); GetMappingsResponse mappings = client().admin().indices().prepareGetMappings("index").get(); for (int i = 0; i < indexThreads.length; ++i) { - assertMappingsHaveField(mappings, "index", "type", "field" + i); + assertMappingsHaveField(mappings, "index", "field" + i); } for (int i = 0; i < indexThreads.length; ++i) { assertTrue(client().prepareGet("index", Integer.toString(i)).get().isExists()); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java index 9defc670cbae8..f44e8a9f3e61a 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java @@ -40,7 +40,7 @@ public void testMergeMappings_GivenIndicesWithIdenticalMappings() throws IOExcep assertThat(mergedMappings.containsKey("_doc"), is(true)); assertThat(mergedMappings.valuesIt().next().getSourceAsMap(), equalTo(index1Mappings)); } - + public void testMergeMappings_GivenFieldWithDifferentMapping() throws IOException { Map index1Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings")); MappingMetaData index1MappingMetaData = new MappingMetaData("_doc", index1Mappings); From 292c045f8cb2ffe0a308ada61db14f39f86bf038 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Sun, 13 Oct 2019 16:43:38 +0100 Subject: [PATCH 09/18] GetMappingsResponse and GetIndexResponse don't return types in mappings --- .../elasticsearch/client/IndicesClient.java | 85 ------------ .../client/IndicesRequestConverters.java | 16 --- .../elasticsearch/client/IndicesClientIT.java | 28 ---- .../client/IndicesRequestConvertersTests.java | 44 ------ .../client/indices/GetIndexResponseTests.java | 8 +- .../indices/GetMappingsResponseTests.java | 6 +- .../index/mapper/size/SizeMappingIT.java | 16 +-- .../admin/indices/get/GetIndexResponse.java | 126 ++++++------------ .../indices/get/TransportGetIndexAction.java | 5 +- .../mapping/get/GetMappingsResponse.java | 110 ++++++--------- .../get/TransportGetMappingsAction.java | 4 +- .../master/info/ClusterInfoRequest.java | 10 -- .../info/ClusterInfoRequestBuilder.java | 12 -- .../cluster/metadata/MetaData.java | 35 +---- .../admin/indices/create/CreateIndexIT.java | 21 +-- .../action/admin/indices/get/GetIndexIT.java | 14 +- .../indices/get/GetIndexResponseTests.java | 38 +----- .../mapping/get/GetMappingsResponseTests.java | 84 +++--------- .../documentation/IndicesDocumentationIT.java | 7 +- .../cluster/SimpleClusterStateIT.java | 4 +- .../coordination/RareClusterStateIT.java | 5 +- .../cluster/metadata/MetaDataTests.java | 82 +++++------- .../gateway/MetaDataWriteDataNodesIT.java | 12 +- .../index/mapper/DynamicMappingIT.java | 7 +- .../mapper/FieldFilterMapperPluginTests.java | 22 ++- .../mapper/MultiFieldsIntegrationIT.java | 10 +- .../indices/IndicesOptionsIntegrationIT.java | 24 ++-- .../indices/mapping/SimpleGetMappingsIT.java | 49 ++----- .../mapping/UpdateMappingIntegrationIT.java | 18 +-- .../xpack/ccr/CcrRepositoryIT.java | 2 +- .../xpack/ccr/IndexFollowingIT.java | 12 +- .../persistence/ElasticsearchMappings.java | 9 +- .../snapshots/SourceOnlySnapshotIT.java | 9 +- .../accesscontrol/FieldSubsetReaderTests.java | 32 ++--- .../ml/dataframe/DataFrameAnalyticsIndex.java | 6 +- .../xpack/ml/dataframe/MappingsMerger.java | 20 +-- .../job/persistence/JobResultsProvider.java | 7 +- .../DataFrameAnalyticsIndexTests.java | 11 +- .../ml/dataframe/MappingsMergerTests.java | 44 ++---- .../ml/integration/JobResultsProviderIT.java | 7 +- .../persistence/JobResultsProviderTests.java | 7 +- .../action/TransportPutRollupJobAction.java | 2 +- .../action/PutJobStateMachineTests.java | 30 ++--- .../DocumentAndFieldLevelSecurityTests.java | 4 +- .../integration/KibanaUserRoleIntegTests.java | 5 +- .../HistoryTemplateHttpMappingsTests.java | 9 +- .../HistoryTemplateTimeMappingsTests.java | 6 +- .../AbstractWatcherIntegrationTestCase.java | 2 +- .../integration/HistoryIntegrationTests.java | 15 +-- 49 files changed, 305 insertions(+), 836 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java index 5003fa4525d80..418623931aacb 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java @@ -297,55 +297,6 @@ public Cancellable getMappingAsync(GetMappingsRequest getMappingsRequest, Reques emptySet()); } - /** - * Retrieves the mappings on an index or indices using the Get Mapping API. - * See - * Get Mapping API on elastic.co - * @param getMappingsRequest the request - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - * - * @deprecated This method uses old request and response objects which still refer to types, a deprecated - * feature. The method {@link #getMapping(GetMappingsRequest, RequestOptions)} should be used instead, which - * accepts a new request object. - */ - @Deprecated - public org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse getMapping( - org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest, - RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest, - IndicesRequestConverters::getMappings, - options, - org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent, - emptySet()); - } - - /** - * Asynchronously retrieves the mappings on an index on indices using the Get Mapping API. - * See - * Get Mapping API on elastic.co - * @param getMappingsRequest the request - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * - * @deprecated This method uses old request and response objects which still refer to types, a deprecated feature. - * The method {@link #getMapping(GetMappingsRequest, RequestOptions)} should be used instead, which accepts a new - * request object. - * @return cancellable that may be used to cancel the request - */ - @Deprecated - public Cancellable getMappingAsync(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest, - RequestOptions options, - ActionListener listener) { - return restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest, - IndicesRequestConverters::getMappings, - options, - org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent, - listener, - emptySet()); - } - /** * Retrieves the field mappings on an index or indices using the Get Field Mapping API. * See @@ -679,42 +630,6 @@ public Cancellable getAsync(GetIndexRequest getIndexRequest, RequestOptions opti GetIndexResponse::fromXContent, listener, emptySet()); } - /** - * Retrieve information about one or more indexes - * See - * Indices Get Index API on elastic.co - * @param getIndexRequest the request - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @return the response - * @throws IOException in case there is a problem sending the request or parsing back the response - * @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method - * {@link #get(GetIndexRequest, RequestOptions)} should be used instead, which accepts a new request object. - */ - @Deprecated - public org.elasticsearch.action.admin.indices.get.GetIndexResponse get( - org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(getIndexRequest, IndicesRequestConverters::getIndex, options, - org.elasticsearch.action.admin.indices.get.GetIndexResponse::fromXContent, emptySet()); - } - - /** - * Retrieve information about one or more indexes - * See - * Indices Get Index API on elastic.co - * @param getIndexRequest the request - * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized - * @param listener the listener to be notified upon request completion - * @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method - * {@link #getAsync(GetIndexRequest, RequestOptions, ActionListener)} should be used instead, which accepts a new request object. - * @return cancellable that may be used to cancel the request - */ - @Deprecated - public Cancellable getAsync(org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest, RequestOptions options, - ActionListener listener) { - return restHighLevelClient.performRequestAsyncAndParseEntity(getIndexRequest, IndicesRequestConverters::getIndex, options, - org.elasticsearch.action.admin.indices.get.GetIndexResponse::fromXContent, listener, emptySet()); - } - /** * Force merge one or more indices using the Force Merge API. * See diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java index ba85983704537..96f56afe4d1ca 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java @@ -189,22 +189,6 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) { return request; } - @Deprecated - static Request getMappings(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) { - String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices(); - String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types(); - - Request request = new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping", types)); - - RequestConverters.Params parameters = new RequestConverters.Params(); - parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout()); - parameters.withIndicesOptions(getMappingsRequest.indicesOptions()); - parameters.withLocal(getMappingsRequest.local()); - parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true"); - request.addParameters(parameters.asMap()); - return request; - } - static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest) { String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices(); String[] fields = getFieldMappingsRequest.fields() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.fields(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java index 43e4b26ac3f17..50a5a5c29e4bf 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java @@ -100,7 +100,6 @@ import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction; import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateAction; -import org.elasticsearch.rest.action.admin.indices.RestGetIndicesAction; import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction; import org.elasticsearch.rest.action.admin.indices.RestRolloverIndexAction; @@ -451,33 +450,6 @@ public void testGetIndex() throws IOException { assertEquals("integer", fieldMapping.get("type")); } - @SuppressWarnings("unchecked") - public void testGetIndexWithTypes() throws IOException { - String indexName = "get_index_test"; - Settings basicSettings = Settings.builder() - .put(SETTING_NUMBER_OF_SHARDS, 1) - .put(SETTING_NUMBER_OF_REPLICAS, 0) - .build(); - String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}"; - createIndex(indexName, basicSettings, mappings); - - org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest = - new org.elasticsearch.action.admin.indices.get.GetIndexRequest().indices(indexName).includeDefaults(false); - org.elasticsearch.action.admin.indices.get.GetIndexResponse getIndexResponse = execute(getIndexRequest, - highLevelClient().indices()::get, highLevelClient().indices()::getAsync, - expectWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE)); - - // default settings should be null - assertNull(getIndexResponse.getSetting(indexName, "index.refresh_interval")); - assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS)); - assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS)); - assertNotNull(getIndexResponse.getMappings().get(indexName)); - MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName).get("_doc"); - assertNotNull(mappingMetaData); - assertEquals("_doc", mappingMetaData.type()); - assertEquals("{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}", mappingMetaData.source().string()); - } - @SuppressWarnings("unchecked") public void testGetIndexWithDefaults() throws IOException { String indexName = "get_index_test"; diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java index a8a400fdcf308..115dabe4b049a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java @@ -288,50 +288,6 @@ public void testGetMapping() { Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); } - public void testGetMappingWithTypes() { - org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingRequest = - new org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest(); - - String[] indices = Strings.EMPTY_ARRAY; - if (randomBoolean()) { - indices = RequestConvertersTests.randomIndicesNames(0, 5); - getMappingRequest.indices(indices); - } else if (randomBoolean()) { - getMappingRequest.indices((String[]) null); - } - - String type = null; - if (randomBoolean()) { - type = randomAlphaOfLengthBetween(3, 10); - getMappingRequest.types(type); - } else if (randomBoolean()) { - getMappingRequest.types((String[]) null); - } - - Map expectedParams = new HashMap<>(); - - RequestConvertersTests.setRandomIndicesOptions(getMappingRequest::indicesOptions, - getMappingRequest::indicesOptions, expectedParams); - RequestConvertersTests.setRandomMasterTimeout(getMappingRequest, expectedParams); - RequestConvertersTests.setRandomLocal(getMappingRequest::local, expectedParams); - expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true"); - - Request request = IndicesRequestConverters.getMappings(getMappingRequest); - StringJoiner endpoint = new StringJoiner("/", "/", ""); - String index = String.join(",", indices); - if (Strings.hasLength(index)) { - endpoint.add(index); - } - endpoint.add("_mapping"); - if (type != null) { - endpoint.add(type); - } - Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint())); - - Assert.assertThat(expectedParams, equalTo(request.getParameters())); - Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod())); - } - public void testGetFieldMapping() { GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest(); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java index 19c25fd11f6ed..bcc4cc367935b 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java @@ -162,7 +162,7 @@ private static Map randomFieldMapping() { private static void toXContent(GetIndexResponse response, XContentBuilder builder) throws IOException { // first we need to repackage from GetIndexResponse to org.elasticsearch.action.admin.indices.get.GetIndexResponse - ImmutableOpenMap.Builder> allMappings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder allMappings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); @@ -170,11 +170,7 @@ private static void toXContent(GetIndexResponse response, XContentBuilder builde Map indexMappings = response.getMappings(); for (String index : response.getIndices()) { MappingMetaData mmd = indexMappings.get(index); - ImmutableOpenMap.Builder typedMappings = ImmutableOpenMap.builder(); - if (mmd != null) { - typedMappings.put(MapperService.SINGLE_MAPPING_NAME, mmd); - } - allMappings.put(index, typedMappings.build()); + allMappings.put(index, mmd); aliases.put(index, response.getAliases().get(index)); settings.put(index, response.getSettings().get(index)); defaultSettings.put(index, response.getDefaultSettings().get(index)); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java index 0601609a8a766..4595cf5cfe6b5 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java @@ -102,12 +102,10 @@ private static Map randomFieldMapping() { private static void toXContent(GetMappingsResponse response, XContentBuilder builder) throws IOException { Params params = new ToXContent.MapParams( Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "false")); - ImmutableOpenMap.Builder> allMappings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder allMappings = ImmutableOpenMap.builder(); for (Map.Entry indexEntry : response.mappings().entrySet()) { - ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); - mappings.put(MapperService.SINGLE_MAPPING_NAME, indexEntry.getValue()); - allMappings.put(indexEntry.getKey(), mappings.build()); + allMappings.put(indexEntry.getKey(), indexEntry.getValue()); } org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse serverResponse = diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java index cbf89567b9a59..f6c35a607c3c2 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java @@ -56,7 +56,7 @@ public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() thr assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); // check mapping again - assertSizeMappingEnabled(index, type, true); + assertSizeMappingEnabled(index, true); // update some field in the mapping XContentBuilder updateMappingBuilder = @@ -67,7 +67,7 @@ public void testThatUpdatingMappingShouldNotRemoveSizeMappingConfiguration() thr assertAcked(putMappingResponse); // make sure size field is still in mapping - assertSizeMappingEnabled(index, type, true); + assertSizeMappingEnabled(index, true); } public void testThatSizeCanBeSwitchedOnAndOff() throws Exception { @@ -79,7 +79,7 @@ public void testThatSizeCanBeSwitchedOnAndOff() throws Exception { assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder)); // check mapping again - assertSizeMappingEnabled(index, type, true); + assertSizeMappingEnabled(index, true); // update some field in the mapping XContentBuilder updateMappingBuilder = @@ -89,15 +89,15 @@ public void testThatSizeCanBeSwitchedOnAndOff() throws Exception { assertAcked(putMappingResponse); // make sure size field is still in mapping - assertSizeMappingEnabled(index, type, false); + assertSizeMappingEnabled(index, false); } - private void assertSizeMappingEnabled(String index, String type, boolean enabled) throws IOException { + private void assertSizeMappingEnabled(String index, boolean enabled) throws IOException { String errMsg = String.format(Locale.ROOT, - "Expected size field mapping to be " + (enabled ? "enabled" : "disabled") + " for %s/%s", index, type); + "Expected size field mapping to be " + (enabled ? "enabled" : "disabled") + " for %s", index); GetMappingsResponse getMappingsResponse = - client().admin().indices().prepareGetMappings(index).addTypes(type).get(); - Map mappingSource = getMappingsResponse.getMappings().get(index).get(type).getSourceAsMap(); + client().admin().indices().prepareGetMappings(index).get(); + Map mappingSource = getMappingsResponse.getMappings().get(index).getSourceAsMap(); assertThat(errMsg, mappingSource, hasKey("_size")); String sizeAsString = mappingSource.get("_size").toString(); assertThat(sizeAsString, is(notNullValue())); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index fc8a5f439b27c..77eca8b1aec84 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -20,7 +20,7 @@ package org.elasticsearch.action.admin.indices.get; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import org.apache.lucene.util.CollectionUtil; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; @@ -33,32 +33,30 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser.Token; +import org.elasticsearch.index.mapper.MapperService; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.Comparator; import java.util.List; import java.util.Objects; import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; -import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY; -import static org.elasticsearch.rest.BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER; /** * A response for a get index action. */ public class GetIndexResponse extends ActionResponse implements ToXContentObject { - private ImmutableOpenMap> mappings = ImmutableOpenMap.of(); + private ImmutableOpenMap mappings = ImmutableOpenMap.of(); private ImmutableOpenMap> aliases = ImmutableOpenMap.of(); private ImmutableOpenMap settings = ImmutableOpenMap.of(); private ImmutableOpenMap defaultSettings = ImmutableOpenMap.of(); private String[] indices; public GetIndexResponse(String[] indices, - ImmutableOpenMap> mappings, + ImmutableOpenMap mappings, ImmutableOpenMap> aliases, ImmutableOpenMap settings, ImmutableOpenMap defaultSettings) { @@ -84,15 +82,24 @@ public GetIndexResponse(String[] indices, this.indices = in.readStringArray(); int mappingsSize = in.readVInt(); - ImmutableOpenMap.Builder> mappingsMapBuilder = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder mappingsMapBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < mappingsSize; i++) { - String key = in.readString(); - int valueSize = in.readVInt(); - ImmutableOpenMap.Builder mappingEntryBuilder = ImmutableOpenMap.builder(); - for (int j = 0; j < valueSize; j++) { - mappingEntryBuilder.put(in.readString(), new MappingMetaData(in)); + String index = in.readString(); + if (in.getVersion().before(Version.V_8_0_0)) { + int numMappings = in.readVInt(); + assert numMappings == 0 || numMappings == 1 : "Expected 0 or 1 mappings but got " + numMappings; + if (numMappings == 1) { + String type = in.readString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but got [" + type + "]"; + mappingsMapBuilder.put(index, new MappingMetaData(in)); + } + } + else { + boolean hasMapping = in.readBoolean(); + if (hasMapping) { + mappingsMapBuilder.put(index, new MappingMetaData(in)); + } } - mappingsMapBuilder.put(key, mappingEntryBuilder.build()); } mappings = mappingsMapBuilder.build(); @@ -133,11 +140,11 @@ public String[] getIndices() { return indices(); } - public ImmutableOpenMap> mappings() { + public ImmutableOpenMap mappings() { return mappings; } - public ImmutableOpenMap> getMappings() { + public ImmutableOpenMap getMappings() { return mappings(); } @@ -197,12 +204,20 @@ public String getSetting(String index, String setting) { public void writeTo(StreamOutput out) throws IOException { out.writeStringArray(indices); out.writeVInt(mappings.size()); - for (ObjectObjectCursor> indexEntry : mappings) { + for (ObjectObjectCursor indexEntry : mappings) { out.writeString(indexEntry.key); - out.writeVInt(indexEntry.value.size()); - for (ObjectObjectCursor mappingEntry : indexEntry.value) { - out.writeString(mappingEntry.key); - mappingEntry.value.writeTo(out); + if (out.getVersion().before(Version.V_8_0_0)) { + out.writeVInt(indexEntry.value == null ? 0 : 1); + if (indexEntry.value != null) { + out.writeString(MapperService.SINGLE_MAPPING_NAME); + indexEntry.value.writeTo(out); + } + } + else { + out.writeBoolean(indexEntry.value != null); + if (indexEntry.value != null) { + indexEntry.value.writeTo(out); + } } } out.writeVInt(aliases.size()); @@ -241,31 +256,14 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws } builder.endObject(); - ImmutableOpenMap indexMappings = mappings.get(index); - boolean includeTypeName = params.paramAsBoolean(INCLUDE_TYPE_NAME_PARAMETER, - DEFAULT_INCLUDE_TYPE_NAME_POLICY); - if (includeTypeName) { - builder.startObject("mappings"); - if (indexMappings != null) { - for (final ObjectObjectCursor typeEntry : indexMappings) { - builder.field(typeEntry.key); - builder.map(typeEntry.value.sourceAsMap()); - } - } - builder.endObject(); - } else { - MappingMetaData mappings = null; - for (final ObjectObjectCursor typeEntry : indexMappings) { - assert mappings == null; - mappings = typeEntry.value; - } - if (mappings == null) { - // no mappings yet - builder.startObject("mappings").endObject(); - } else { - builder.field("mappings", mappings.sourceAsMap()); - } + MappingMetaData indexMappings = mappings.get(index); + if (indexMappings != null) { + builder.field("mappings", indexMappings.sourceAsMap()); } + else { + builder.startObject("mappings").endObject(); + } + builder.endObject(); builder.startObject("settings"); Settings indexSettings = settings.get(index); @@ -362,46 +360,6 @@ private static class IndexEntry { } } - public static GetIndexResponse fromXContent(XContentParser parser) throws IOException { - ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); - ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); - List indices = new ArrayList<>(); - - if (parser.currentToken() == null) { - parser.nextToken(); - } - ensureExpectedToken(Token.START_OBJECT, parser.currentToken(), parser::getTokenLocation); - parser.nextToken(); - - while (!parser.isClosed()) { - if (parser.currentToken() == Token.START_OBJECT) { - // we assume this is an index entry - String indexName = parser.currentName(); - indices.add(indexName); - IndexEntry indexEntry = parseIndexEntry(parser); - // make the order deterministic - CollectionUtil.timSort(indexEntry.indexAliases, Comparator.comparing(AliasMetaData::alias)); - aliases.put(indexName, Collections.unmodifiableList(indexEntry.indexAliases)); - mappings.put(indexName, indexEntry.indexMappings); - settings.put(indexName, indexEntry.indexSettings); - if (indexEntry.indexDefaultSettings.isEmpty() == false) { - defaultSettings.put(indexName, indexEntry.indexDefaultSettings); - } - } else if (parser.currentToken() == Token.START_ARRAY) { - parser.skipChildren(); - } else { - parser.nextToken(); - } - } - return - new GetIndexResponse( - indices.toArray(new String[0]), mappings.build(), aliases.build(), - settings.build(), defaultSettings.build() - ); - } - @Override public String toString() { return Strings.toString(this); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java index 6fb6da59735ef..9dc10ba07be1a 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/TransportGetIndexAction.java @@ -86,7 +86,7 @@ protected GetIndexResponse read(StreamInput in) throws IOException { @Override protected void doMasterOperation(final GetIndexRequest request, String[] concreteIndices, final ClusterState state, final ActionListener listener) { - ImmutableOpenMap> mappingsResult = ImmutableOpenMap.of(); + ImmutableOpenMap mappingsResult = ImmutableOpenMap.of(); ImmutableOpenMap> aliasesResult = ImmutableOpenMap.of(); ImmutableOpenMap settings = ImmutableOpenMap.of(); ImmutableOpenMap defaultSettings = ImmutableOpenMap.of(); @@ -99,8 +99,7 @@ protected void doMasterOperation(final GetIndexRequest request, String[] concret case MAPPINGS: if (!doneMappings) { try { - mappingsResult = state.metaData().findMappings(concreteIndices, request.types(), - indicesService.getFieldFilter()); + mappingsResult = state.metaData().findMappings(concreteIndices, indicesService.getFieldFilter()); doneMappings = true; } catch (IOException e) { listener.onFailure(e); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java index aebcf8abb356f..588f5f4cfe553 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -20,6 +20,7 @@ package org.elasticsearch.action.admin.indices.mapping.get; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; +import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.ParseField; @@ -29,117 +30,86 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContentFragment; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.index.mapper.MapperService; import java.io.IOException; -import java.util.Map; - -import static org.elasticsearch.rest.BaseRestHandler.DEFAULT_INCLUDE_TYPE_NAME_POLICY; public class GetMappingsResponse extends ActionResponse implements ToXContentFragment { private static final ParseField MAPPINGS = new ParseField("mappings"); - private ImmutableOpenMap> mappings = ImmutableOpenMap.of(); + private final ImmutableOpenMap mappings; - public GetMappingsResponse(ImmutableOpenMap> mappings) { + public GetMappingsResponse(ImmutableOpenMap mappings) { this.mappings = mappings; } GetMappingsResponse(StreamInput in) throws IOException { super(in); int size = in.readVInt(); - ImmutableOpenMap.Builder> indexMapBuilder = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder indexMapBuilder = ImmutableOpenMap.builder(); for (int i = 0; i < size; i++) { - String key = in.readString(); - int valueSize = in.readVInt(); - ImmutableOpenMap.Builder typeMapBuilder = ImmutableOpenMap.builder(); - for (int j = 0; j < valueSize; j++) { - typeMapBuilder.put(in.readString(), new MappingMetaData(in)); + String index = in.readString(); + if (in.getVersion().before(Version.V_8_0_0)) { + int mappingCount = in.readVInt(); + assert mappingCount == 1 || mappingCount == 0 : "Expected 0 or 1 mappings but got " + mappingCount; + if (mappingCount == 1) { + String type = in.readString(); + assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got [" + type + "]"; + indexMapBuilder.put(index, new MappingMetaData(in)); + } + } + else { + boolean hasMapping = in.readBoolean(); + if (hasMapping) { + indexMapBuilder.put(index, new MappingMetaData(in)); + } } - indexMapBuilder.put(key, typeMapBuilder.build()); } mappings = indexMapBuilder.build(); } - public ImmutableOpenMap> mappings() { + public ImmutableOpenMap mappings() { return mappings; } - public ImmutableOpenMap> getMappings() { + public ImmutableOpenMap getMappings() { return mappings(); } @Override public void writeTo(StreamOutput out) throws IOException { out.writeVInt(mappings.size()); - for (ObjectObjectCursor> indexEntry : mappings) { + for (ObjectObjectCursor indexEntry : mappings) { out.writeString(indexEntry.key); - out.writeVInt(indexEntry.value.size()); - for (ObjectObjectCursor typeEntry : indexEntry.value) { - out.writeString(typeEntry.key); - typeEntry.value.writeTo(out); + if (out.getVersion().before(Version.V_8_0_0)) { + out.writeVInt(indexEntry.value == null ? 0 : 1); + if (indexEntry.value != null) { + out.writeString(MapperService.SINGLE_MAPPING_NAME); + indexEntry.value.writeTo(out); + } } - } - } - - public static GetMappingsResponse fromXContent(XContentParser parser) throws IOException { - if (parser.currentToken() == null) { - parser.nextToken(); - } - assert parser.currentToken() == XContentParser.Token.START_OBJECT; - Map parts = parser.map(); - - ImmutableOpenMap.Builder> builder = new ImmutableOpenMap.Builder<>(); - for (Map.Entry entry : parts.entrySet()) { - final String indexName = entry.getKey(); - assert entry.getValue() instanceof Map : "expected a map as type mapping, but got: " + entry.getValue().getClass(); - final Map mapping = (Map) ((Map) entry.getValue()).get(MAPPINGS.getPreferredName()); - - ImmutableOpenMap.Builder typeBuilder = new ImmutableOpenMap.Builder<>(); - for (Map.Entry typeEntry : mapping.entrySet()) { - final String typeName = typeEntry.getKey(); - assert typeEntry.getValue() instanceof Map : "expected a map as inner type mapping, but got: " + - typeEntry.getValue().getClass(); - final Map fieldMappings = (Map) typeEntry.getValue(); - MappingMetaData mmd = new MappingMetaData(typeName, fieldMappings); - typeBuilder.put(typeName, mmd); + else { + out.writeBoolean(indexEntry.value != null); + if (indexEntry.value != null) { + indexEntry.value.writeTo(out); + } } - builder.put(indexName, typeBuilder.build()); } - - return new GetMappingsResponse(builder.build()); } @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - boolean includeTypeName = params.paramAsBoolean(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, - DEFAULT_INCLUDE_TYPE_NAME_POLICY); - for (final ObjectObjectCursor> indexEntry : getMappings()) { + for (final ObjectObjectCursor indexEntry : getMappings()) { builder.startObject(indexEntry.key); { - if (includeTypeName == false) { - MappingMetaData mappings = null; - for (final ObjectObjectCursor typeEntry : indexEntry.value) { - assert mappings == null; - mappings = typeEntry.value; - } - if (mappings == null) { - // no mappings yet - builder.startObject(MAPPINGS.getPreferredName()).endObject(); - } else { - builder.field(MAPPINGS.getPreferredName(), mappings.sourceAsMap()); - } + MappingMetaData mappings = indexEntry.value; + if (mappings == null) { + // no mappings yet + builder.startObject(MAPPINGS.getPreferredName()).endObject(); } else { - builder.startObject(MAPPINGS.getPreferredName()); - { - for (final ObjectObjectCursor typeEntry : indexEntry.value) { - builder.field(typeEntry.key, typeEntry.value.sourceAsMap()); - } - } - builder.endObject(); + builder.field(MAPPINGS.getPreferredName(), mappings.sourceAsMap()); } } builder.endObject(); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java index 6a53762461665..57f84c97c0ffb 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/TransportGetMappingsAction.java @@ -76,8 +76,8 @@ protected void doMasterOperation(final GetMappingsRequest request, String[] conc final ActionListener listener) { logger.trace("serving getMapping request based on version {}", state.version()); try { - ImmutableOpenMap> result = - state.metaData().findMappings(concreteIndices, request.types(), indicesService.getFieldFilter()); + ImmutableOpenMap result = + state.metaData().findMappings(concreteIndices, indicesService.getFieldFilter()); listener.onResponse(new GetMappingsResponse(result)); } catch (IOException e) { listener.onFailure(e); diff --git a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java index d41d9dcec926f..d23c881bf8408 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequest.java @@ -61,12 +61,6 @@ public Request indices(String... indices) { return (Request) this; } - @SuppressWarnings("unchecked") - public Request types(String... types) { - this.types = types; - return (Request) this; - } - @SuppressWarnings("unchecked") public Request indicesOptions(IndicesOptions indicesOptions) { this.indicesOptions = indicesOptions; @@ -78,10 +72,6 @@ public String[] indices() { return indices; } - public String[] types() { - return types; - } - @Override public IndicesOptions indicesOptions() { return indicesOptions; diff --git a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java index 41833a563c4e4..674faeeac305c 100644 --- a/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java +++ b/server/src/main/java/org/elasticsearch/action/support/master/info/ClusterInfoRequestBuilder.java @@ -46,18 +46,6 @@ public Builder addIndices(String... indices) { return (Builder) this; } - @SuppressWarnings("unchecked") - public Builder setTypes(String... types) { - request.types(types); - return (Builder) this; - } - - @SuppressWarnings("unchecked") - public Builder addTypes(String... types) { - request.types(ArrayUtils.concat(request.types(), types)); - return (Builder) this; - } - @SuppressWarnings("unchecked") public Builder setIndicesOptions(IndicesOptions indicesOptions) { request.indicesOptions(indicesOptions); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index 0b14c692d53a5..db540ec2b08d8 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -375,51 +375,24 @@ private ImmutableOpenMap> findAliases(final String[] * @see MapperPlugin#getFieldFilter() * */ - public ImmutableOpenMap> findMappings(String[] concreteIndices, - final String[] types, - Function> fieldFilter) + public ImmutableOpenMap findMappings(String[] concreteIndices, + Function> fieldFilter) throws IOException { - assert types != null; assert concreteIndices != null; if (concreteIndices.length == 0) { return ImmutableOpenMap.of(); } - boolean isAllTypes = isAllTypes(types); - ImmutableOpenMap.Builder> indexMapBuilder = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder indexMapBuilder = ImmutableOpenMap.builder(); Iterable intersection = HppcMaps.intersection(ObjectHashSet.from(concreteIndices), indices.keys()); for (String index : intersection) { IndexMetaData indexMetaData = indices.get(index); Predicate fieldPredicate = fieldFilter.apply(index); - if (isAllTypes) { - indexMapBuilder.put(index, filterFields(indexMetaData.getMappings(), fieldPredicate)); - } else { - ImmutableOpenMap.Builder filteredMappings = ImmutableOpenMap.builder(); - for (ObjectObjectCursor cursor : indexMetaData.getMappings()) { - if (Regex.simpleMatch(types, cursor.key)) { - filteredMappings.put(cursor.key, filterFields(cursor.value, fieldPredicate)); - } - } - if (!filteredMappings.isEmpty()) { - indexMapBuilder.put(index, filteredMappings.build()); - } - } + indexMapBuilder.put(index, filterFields(indexMetaData.mapping(), fieldPredicate)); } return indexMapBuilder.build(); } - private static ImmutableOpenMap filterFields(ImmutableOpenMap mappings, - Predicate fieldPredicate) throws IOException { - if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) { - return mappings; - } - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(mappings.size()); - for (ObjectObjectCursor cursor : mappings) { - builder.put(cursor.key, filterFields(cursor.value, fieldPredicate)); - } - return builder.build(); // No types specified means return them all - } - @SuppressWarnings("unchecked") private static MappingMetaData filterFields(MappingMetaData mappingMetaData, Predicate fieldPredicate) throws IOException { if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) { diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java index 7be8871ee06be..d393741d89765 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/create/CreateIndexIT.java @@ -127,12 +127,9 @@ public void testNonNestedMappings() throws Exception { GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); - ImmutableOpenMap mappings = response.mappings().get("test"); + MappingMetaData mappings = response.mappings().get("test"); assertNotNull(mappings); - - MappingMetaData metadata = mappings.get("_doc"); - assertNotNull(metadata); - assertFalse(metadata.sourceAsMap().isEmpty()); + assertFalse(mappings.sourceAsMap().isEmpty()); } public void testEmptyNestedMappings() throws Exception { @@ -141,12 +138,9 @@ public void testEmptyNestedMappings() throws Exception { GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); - ImmutableOpenMap mappings = response.mappings().get("test"); + MappingMetaData mappings = response.mappings().get("test"); assertNotNull(mappings); - - MappingMetaData metadata = mappings.get("_doc"); - assertNotNull(metadata); - assertTrue(metadata.sourceAsMap().isEmpty()); + assertTrue(mappings.sourceAsMap().isEmpty()); } public void testMappingParamAndNestedMismatch() throws Exception { @@ -165,12 +159,9 @@ public void testEmptyMappings() throws Exception { GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").get(); - ImmutableOpenMap mappings = response.mappings().get("test"); + MappingMetaData mappings = response.mappings().get("test"); assertNotNull(mappings); - - MappingMetaData metadata = mappings.get("_doc"); - assertNotNull(metadata); - assertTrue(metadata.sourceAsMap().isEmpty()); + assertTrue(mappings.sourceAsMap().isEmpty()); } public void testInvalidShardCountSettings() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java index 91479e4bfe192..99c1576c2876e 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java @@ -230,24 +230,20 @@ private void assertNonEmptySettings(GetIndexResponse response, String indexName) } private void assertMappings(GetIndexResponse response, String indexName) { - ImmutableOpenMap> mappings = response.mappings(); + ImmutableOpenMap mappings = response.mappings(); assertThat(mappings, notNullValue()); assertThat(mappings.size(), equalTo(1)); - ImmutableOpenMap indexMappings = mappings.get(indexName); + MappingMetaData indexMappings = mappings.get(indexName); assertThat(indexMappings, notNullValue()); - assertThat(indexMappings.size(), equalTo(1)); - MappingMetaData mapping = indexMappings.get("type1"); - assertThat(mapping, notNullValue()); - assertThat(mapping.type(), equalTo("type1")); } private void assertEmptyOrOnlyDefaultMappings(GetIndexResponse response, String indexName) { - ImmutableOpenMap> mappings = response.mappings(); + ImmutableOpenMap mappings = response.mappings(); assertThat(mappings, notNullValue()); assertThat(mappings.size(), equalTo(1)); - ImmutableOpenMap indexMappings = mappings.get(indexName); + MappingMetaData indexMappings = mappings.get(indexName); assertThat(indexMappings, notNullValue()); - assertThat(indexMappings.size(), equalTo(0)); + assertThat(indexMappings.sourceAsMap().size(), equalTo(0)); } private void assertAliases(GetIndexResponse response, String indexName) { diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexResponseTests.java index 1c277545cbbce..ee789259c3525 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexResponseTests.java @@ -28,25 +28,15 @@ import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.RandomCreateIndexGenerator; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.test.AbstractSerializingTestCase; +import org.elasticsearch.test.AbstractWireSerializingTestCase; -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.function.Predicate; -public class GetIndexResponseTests extends AbstractSerializingTestCase { - - @Override - protected GetIndexResponse doParseInstance(XContentParser parser) throws IOException { - return GetIndexResponse.fromXContent(parser); - } +public class GetIndexResponseTests extends AbstractWireSerializingTestCase { @Override protected Writeable.Reader instanceReader() { @@ -56,16 +46,15 @@ protected Writeable.Reader instanceReader() { @Override protected GetIndexResponse createTestInstance() { String[] indices = generateRandomStringArray(5, 5, false, false); - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); IndexScopedSettings indexScopedSettings = IndexScopedSettings.DEFAULT_SCOPED_SETTINGS; boolean includeDefaults = randomBoolean(); for (String index: indices) { - // rarely have no types - int typeCount = rarely() ? 0 : 1; - mappings.put(index, GetMappingsResponseTests.createMappingsForIndex(typeCount, true)); + + mappings.put(index, GetMappingsResponseTests.createMappingsForIndex()); List aliasMetaDataList = new ArrayList<>(); int aliasesNum = randomIntBetween(0, 3); @@ -87,21 +76,4 @@ protected GetIndexResponse createTestInstance() { indices, mappings.build(), aliases.build(), settings.build(), defaultSettings.build() ); } - - @Override - protected Predicate getRandomFieldsExcludeFilter() { - //we do not want to add new fields at the root (index-level), or inside the blocks - return - f -> f.equals("") || f.contains(".settings") || f.contains(".defaults") || f.contains(".mappings") || - f.contains(".aliases"); - } - - /** - * For xContent roundtrip testing we force the xContent output to still contain types because the parser still expects them. - * The new typeless parsing is implemented in the client side GetIndexResponse. - */ - @Override - protected ToXContent.Params getToXContentParams() { - return new ToXContent.MapParams(Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "true")); - } } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java index 6586d8af0ae5c..ea4680dae41aa 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java @@ -19,65 +19,34 @@ package org.elasticsearch.action.admin.indices.mapping.get; -import com.carrotsearch.hppc.cursors.ObjectCursor; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.Writeable; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.ToXContent.Params; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.test.AbstractSerializingTestCase; +import org.elasticsearch.test.AbstractWireSerializingTestCase; import org.elasticsearch.test.EqualsHashCodeTestUtils; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; -import java.util.List; import java.util.Map; import java.util.Objects; -public class GetMappingsResponseTests extends AbstractSerializingTestCase { - - @Override - protected boolean supportsUnknownFields() { - return false; - } +public class GetMappingsResponseTests extends AbstractWireSerializingTestCase { public void testCheckEqualsAndHashCode() { GetMappingsResponse resp = createTestInstance(); EqualsHashCodeTestUtils.checkEqualsAndHashCode(resp, r -> new GetMappingsResponse(r.mappings()), GetMappingsResponseTests::mutate); } - @Override - protected GetMappingsResponse doParseInstance(XContentParser parser) throws IOException { - return GetMappingsResponse.fromXContent(parser); - } - @Override protected Writeable.Reader instanceReader() { return GetMappingsResponse::new; } - private static GetMappingsResponse mutate(GetMappingsResponse original) throws IOException { - ImmutableOpenMap.Builder> builder = ImmutableOpenMap.builder(original.mappings()); + private static GetMappingsResponse mutate(GetMappingsResponse original) { + ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(original.mappings()); String indexKey = original.mappings().keys().iterator().next().value; - - ImmutableOpenMap.Builder typeBuilder = ImmutableOpenMap.builder(original.mappings().get(indexKey)); - final String typeKey; - Iterator> iter = original.mappings().get(indexKey).keys().iterator(); - if (iter.hasNext()) { - typeKey = iter.next().value; - } else { - typeKey = "new-type"; - } - - typeBuilder.put(typeKey, new MappingMetaData("type-" + randomAlphaOfLength(6), randomFieldMapping())); - - builder.put(indexKey, typeBuilder.build()); + builder.put(indexKey + "1", createMappingsForIndex()); return new GetMappingsResponse(builder.build()); } @@ -86,48 +55,25 @@ protected GetMappingsResponse mutateInstance(GetMappingsResponse instance) throw return mutate(instance); } - public static ImmutableOpenMap createMappingsForIndex(int typeCount, boolean randomTypeName) { - List typeMappings = new ArrayList<>(typeCount); - - for (int i = 0; i < typeCount; i++) { + public static MappingMetaData createMappingsForIndex() { + try { + Map mappings = new HashMap<>(); if (rarely() == false) { // rarely have no fields - Map mappings = new HashMap<>(); - mappings.put("field-" + i, randomFieldMapping()); + mappings.put("field", randomFieldMapping()); if (randomBoolean()) { - mappings.put("field2-" + i, randomFieldMapping()); - } - - try { - String typeName = MapperService.SINGLE_MAPPING_NAME; - if (randomTypeName) { - typeName = "type-" + randomAlphaOfLength(5); - } - MappingMetaData mmd = new MappingMetaData(typeName, mappings); - typeMappings.add(mmd); - } catch (IOException e) { - fail("shouldn't have failed " + e); + mappings.put("field2", randomFieldMapping()); } } + return new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, mappings); + } catch (IOException e) { + throw new AssertionError("shouldn't have failed " + e); } - ImmutableOpenMap.Builder typeBuilder = ImmutableOpenMap.builder(); - typeMappings.forEach(mmd -> typeBuilder.put(mmd.type(), mmd)); - return typeBuilder.build(); - } - - /** - * For xContent roundtrip testing we force the xContent output to still contain types because the parser - * still expects them. The new typeless parsing is implemented in the client side GetMappingsResponse. - */ - @Override - protected Params getToXContentParams() { - return new ToXContent.MapParams(Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "true")); } @Override protected GetMappingsResponse createTestInstance() { - ImmutableOpenMap.Builder> indexBuilder = ImmutableOpenMap.builder(); - int typeCount = rarely() ? 0 : 1; - indexBuilder.put("index-" + randomAlphaOfLength(5), createMappingsForIndex(typeCount, randomBoolean())); + ImmutableOpenMap.Builder indexBuilder = ImmutableOpenMap.builder(); + indexBuilder.put("index-" + randomAlphaOfLength(5), createMappingsForIndex()); GetMappingsResponse resp = new GetMappingsResponse(indexBuilder.build()); logger.debug("--> created: {}", resp); return resp; diff --git a/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java b/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java index a980e682095b9..905b1b7ac7e41 100644 --- a/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java +++ b/server/src/test/java/org/elasticsearch/client/documentation/IndicesDocumentationIT.java @@ -22,12 +22,10 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.test.ESIntegTestCase; import static java.util.Collections.singletonMap; -import static org.hamcrest.Matchers.instanceOf; /** * This class is used to generate the Java indices administration documentation. @@ -60,8 +58,7 @@ public void testPutMappingDocumentation() throws Exception { // end::index-with-mapping GetMappingsResponse getMappingsResponse = client.admin().indices().prepareGetMappings("twitter").get(); assertEquals(1, getMappingsResponse.getMappings().size()); - ImmutableOpenMap indexMapping = getMappingsResponse.getMappings().get("twitter"); - assertThat(indexMapping.get("_doc"), instanceOf(MappingMetaData.class)); + MappingMetaData indexMapping = getMappingsResponse.getMappings().get("twitter"); // we need to delete in order to create a fresh new index with another type client.admin().indices().prepareDelete("twitter").get(); @@ -97,7 +94,7 @@ public void testPutMappingDocumentation() throws Exception { assertEquals(1, getMappingsResponse.getMappings().size()); indexMapping = getMappingsResponse.getMappings().get("twitter"); assertEquals(singletonMap("properties", singletonMap("name", singletonMap("type", "text"))), - indexMapping.get("_doc").getSourceAsMap()); + indexMapping.getSourceAsMap()); } } diff --git a/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java b/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java index 6c0b9fb7f80c9..fd2484b782a35 100644 --- a/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/SimpleClusterStateIT.java @@ -244,10 +244,10 @@ public void testLargeClusterStatePublishing() throws Exception { .setTimeout("60s").get()); ensureGreen(); // wait for green state, so its both green, and there are no more pending events MappingMetaData masterMappingMetaData = client().admin().indices() - .prepareGetMappings("test").setTypes("type").get().getMappings().get("test").get("type"); + .prepareGetMappings("test").get().getMappings().get("test"); for (Client client : clients()) { MappingMetaData mappingMetadata = client.admin().indices() - .prepareGetMappings("test").setTypes("type").setLocal(true).get().getMappings().get("test").get("type"); + .prepareGetMappings("test").setLocal(true).get().getMappings().get("test"); assertThat(mappingMetadata.source().string(), equalTo(masterMappingMetaData.source().string())); assertThat(mappingMetadata, equalTo(masterMappingMetaData)); } diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java b/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java index a709748d8ea7c..c38be31f69eed 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java @@ -39,7 +39,6 @@ import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.allocation.AllocationService; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.discovery.Discovery; @@ -238,10 +237,8 @@ public void testDelayedMappingPropagationOnPrimary() throws Exception { // ...and wait for mappings to be available on master assertBusy(() -> { - ImmutableOpenMap indexMappings = client().admin().indices() + MappingMetaData typeMappings = client().admin().indices() .prepareGetMappings("index").get().getMappings().get("index"); - assertNotNull(indexMappings); - MappingMetaData typeMappings = indexMappings.get("type"); assertNotNull(typeMappings); Object properties; try { diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java index e9893f16f95c5..aca1183a07ee5 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetaDataTests.java @@ -515,25 +515,20 @@ public void testFindMappings() throws IOException { .putMapping("_doc", FIND_MAPPINGS_TEST_ITEM)).build(); { - ImmutableOpenMap> mappings = metaData.findMappings(Strings.EMPTY_ARRAY, - Strings.EMPTY_ARRAY, MapperPlugin.NOOP_FIELD_FILTER); + ImmutableOpenMap mappings = metaData.findMappings(Strings.EMPTY_ARRAY, + MapperPlugin.NOOP_FIELD_FILTER); assertEquals(0, mappings.size()); } { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - new String[]{"notfound"}, MapperPlugin.NOOP_FIELD_FILTER); - assertEquals(0, mappings.size()); - } - { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - Strings.EMPTY_ARRAY, MapperPlugin.NOOP_FIELD_FILTER); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index1"}, + MapperPlugin.NOOP_FIELD_FILTER); assertEquals(1, mappings.size()); assertIndexMappingsNotFiltered(mappings, "index1"); } { - ImmutableOpenMap> mappings = metaData.findMappings( + ImmutableOpenMap mappings = metaData.findMappings( new String[]{"index1", "index2"}, - new String[]{randomBoolean() ? "_doc" : "_all"}, MapperPlugin.NOOP_FIELD_FILTER); + MapperPlugin.NOOP_FIELD_FILTER); assertEquals(2, mappings.size()); assertIndexMappingsNotFiltered(mappings, "index1"); assertIndexMappingsNotFiltered(mappings, "index2"); @@ -551,31 +546,27 @@ public void testFindMappingsNoOpFilters() throws IOException { .putMapping(originalMappingMetaData)).build(); { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - randomBoolean() ? Strings.EMPTY_ARRAY : new String[]{"_all"}, MapperPlugin.NOOP_FIELD_FILTER); - ImmutableOpenMap index1 = mappings.get("index1"); - MappingMetaData mappingMetaData = index1.get("_doc"); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index1"}, + MapperPlugin.NOOP_FIELD_FILTER); + MappingMetaData mappingMetaData = mappings.get("index1"); assertSame(originalMappingMetaData, mappingMetaData); } { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - randomBoolean() ? Strings.EMPTY_ARRAY : new String[]{"_all"}, index -> field -> randomBoolean()); - ImmutableOpenMap index1 = mappings.get("index1"); - MappingMetaData mappingMetaData = index1.get("_doc"); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index1"}, + index -> field -> randomBoolean()); + MappingMetaData mappingMetaData = mappings.get("index1"); assertNotSame(originalMappingMetaData, mappingMetaData); } { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - new String[]{"_doc"}, MapperPlugin.NOOP_FIELD_FILTER); - ImmutableOpenMap index1 = mappings.get("index1"); - MappingMetaData mappingMetaData = index1.get("_doc"); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index1"}, + MapperPlugin.NOOP_FIELD_FILTER); + MappingMetaData mappingMetaData = mappings.get("index1"); assertSame(originalMappingMetaData, mappingMetaData); } { - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index1"}, - new String[]{"_doc"}, index -> field -> randomBoolean()); - ImmutableOpenMap index1 = mappings.get("index1"); - MappingMetaData mappingMetaData = index1.get("_doc"); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index1"}, + index -> field -> randomBoolean()); + MappingMetaData mappingMetaData = mappings.get("index1"); assertNotSame(originalMappingMetaData, mappingMetaData); } } @@ -607,9 +598,9 @@ public void testFindMappingsWithFilters() throws IOException { .putMapping("_doc", mapping)).build(); { - ImmutableOpenMap> mappings = metaData.findMappings( + ImmutableOpenMap mappings = metaData.findMappings( new String[]{"index1", "index2", "index3"}, - new String[]{"_doc"}, index -> { + index -> { if (index.equals("index1")) { return field -> field.startsWith("name.") == false && field.startsWith("properties.key.") == false && field.equals("age") == false && field.equals("address.location") == false; @@ -625,11 +616,7 @@ public void testFindMappingsWithFilters() throws IOException { assertIndexMappingsNoFields(mappings, "index2"); assertIndexMappingsNotFiltered(mappings, "index3"); - ImmutableOpenMap index1Mappings = mappings.get("index1"); - assertNotNull(index1Mappings); - - assertEquals(1, index1Mappings.size()); - MappingMetaData docMapping = index1Mappings.get("_doc"); + MappingMetaData docMapping = mappings.get("index1"); assertNotNull(docMapping); Map sourceAsMap = docMapping.getSourceAsMap(); @@ -671,15 +658,13 @@ public void testFindMappingsWithFilters() throws IOException { } { - ImmutableOpenMap> mappings = metaData.findMappings( + ImmutableOpenMap mappings = metaData.findMappings( new String[]{"index1", "index2" , "index3"}, - new String[]{"_doc"}, index -> field -> (index.equals("index3") && field.endsWith("keyword"))); + index -> field -> (index.equals("index3") && field.endsWith("keyword"))); assertIndexMappingsNoFields(mappings, "index1"); assertIndexMappingsNoFields(mappings, "index2"); - ImmutableOpenMap index3 = mappings.get("index3"); - assertEquals(1, index3.size()); - MappingMetaData mappingMetaData = index3.get("_doc"); + MappingMetaData mappingMetaData = mappings.get("index3"); Map sourceAsMap = mappingMetaData.getSourceAsMap(); assertEquals(3, sourceAsMap.size()); assertTrue(sourceAsMap.containsKey("_routing")); @@ -707,9 +692,9 @@ public void testFindMappingsWithFilters() throws IOException { } { - ImmutableOpenMap> mappings = metaData.findMappings( + ImmutableOpenMap mappings = metaData.findMappings( new String[]{"index1", "index2" , "index3"}, - new String[]{"_doc"}, index -> field -> (index.equals("index2"))); + index -> field -> (index.equals("index2"))); assertIndexMappingsNoFields(mappings, "index1"); assertIndexMappingsNoFields(mappings, "index3"); @@ -725,12 +710,9 @@ private IndexMetaData.Builder buildIndexMetaData(String name, String alias, Bool } @SuppressWarnings("unchecked") - private static void assertIndexMappingsNoFields(ImmutableOpenMap> mappings, + private static void assertIndexMappingsNoFields(ImmutableOpenMap mappings, String index) { - ImmutableOpenMap indexMappings = mappings.get(index); - assertNotNull(indexMappings); - assertEquals(1, indexMappings.size()); - MappingMetaData docMapping = indexMappings.get("_doc"); + MappingMetaData docMapping = mappings.get(index); assertNotNull(docMapping); Map sourceAsMap = docMapping.getSourceAsMap(); assertEquals(3, sourceAsMap.size()); @@ -741,13 +723,9 @@ private static void assertIndexMappingsNoFields(ImmutableOpenMap> mappings, + private static void assertIndexMappingsNotFiltered(ImmutableOpenMap mappings, String index) { - ImmutableOpenMap indexMappings = mappings.get(index); - assertNotNull(indexMappings); - - assertEquals(1, indexMappings.size()); - MappingMetaData docMapping = indexMappings.get("_doc"); + MappingMetaData docMapping = mappings.get(index); assertNotNull(docMapping); Map sourceAsMap = docMapping.getSourceAsMap(); diff --git a/server/src/test/java/org/elasticsearch/gateway/MetaDataWriteDataNodesIT.java b/server/src/test/java/org/elasticsearch/gateway/MetaDataWriteDataNodesIT.java index 93bd3a44de919..6933b3a3c22f4 100644 --- a/server/src/test/java/org/elasticsearch/gateway/MetaDataWriteDataNodesIT.java +++ b/server/src/test/java/org/elasticsearch/gateway/MetaDataWriteDataNodesIT.java @@ -110,13 +110,13 @@ public void testMetaWrittenWhenIndexIsClosedAndMetaUpdated() throws Exception { .endObject() .endObject()).get(); - GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings(index).addTypes("_doc").get(); - assertNotNull(((Map) (getMappingsResponse.getMappings().get(index).get("_doc").getSourceAsMap().get("properties"))) + GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings(index).get(); + assertNotNull(((Map) (getMappingsResponse.getMappings().get(index).getSourceAsMap().get("properties"))) .get("integer_field")); // make sure it was also written on red node although index is closed ImmutableOpenMap indicesMetaData = getIndicesMetaDataOnNode(dataNode); - assertNotNull(((Map) (indicesMetaData.get(index).getMappings().get("_doc").getSourceAsMap().get("properties"))) + assertNotNull(((Map) (indicesMetaData.get(index).mapping().getSourceAsMap().get("properties"))) .get("integer_field")); assertThat(indicesMetaData.get(index).getState(), equalTo(IndexMetaData.State.CLOSE)); @@ -137,13 +137,13 @@ public void testMetaWrittenWhenIndexIsClosedAndMetaUpdated() throws Exception { .endObject() .endObject()).get(); - getMappingsResponse = client().admin().indices().prepareGetMappings(index).addTypes("_doc").get(); - assertNotNull(((Map) (getMappingsResponse.getMappings().get(index).get("_doc").getSourceAsMap().get("properties"))) + getMappingsResponse = client().admin().indices().prepareGetMappings(index).get(); + assertNotNull(((Map) (getMappingsResponse.getMappings().get(index).getSourceAsMap().get("properties"))) .get("float_field")); // make sure it was also written on red node although index is closed indicesMetaData = getIndicesMetaDataOnNode(dataNode); - assertNotNull(((Map) (indicesMetaData.get(index).getMappings().get("_doc").getSourceAsMap().get("properties"))) + assertNotNull(((Map) (indicesMetaData.get(index).mapping().getSourceAsMap().get("properties"))) .get("float_field")); assertThat(indicesMetaData.get(index).getState(), equalTo(IndexMetaData.State.CLOSE)); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java index 877cca9cdbb5c..5c674b5046baa 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/DynamicMappingIT.java @@ -22,7 +22,6 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.InternalSettingsPlugin; @@ -73,11 +72,9 @@ public void testConflictingDynamicMappingsBulk() { } private static void assertMappingsHaveField(GetMappingsResponse mappings, String index, String field) throws IOException { - ImmutableOpenMap indexMappings = mappings.getMappings().get("index"); + MappingMetaData indexMappings = mappings.getMappings().get("index"); assertNotNull(indexMappings); - MappingMetaData typeMappings = indexMappings.get("_doc"); - assertNotNull(typeMappings); - Map typeMappingsMap = typeMappings.getSourceAsMap(); + Map typeMappingsMap = indexMappings.getSourceAsMap(); Map properties = (Map) typeMappingsMap.get("properties"); assertTrue("Could not find [" + field + "] in " + typeMappingsMap.toString(), properties.containsKey(field)); } diff --git a/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java b/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java index 2608e16497214..fd8c91bb1e55e 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/FieldFilterMapperPluginTests.java @@ -85,8 +85,8 @@ public void testGetFieldMappings() { //double check that submitting the filtered mappings to an unfiltered index leads to the same get field mappings output //as the one coming from a filtered index with same mappings GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("filtered").get(); - ImmutableOpenMap filtered = getMappingsResponse.getMappings().get("filtered"); - assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filtered.get("_doc").getSourceAsMap())); + MappingMetaData filtered = getMappingsResponse.getMappings().get("filtered"); + assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filtered.getSourceAsMap())); GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("test").setFields("*").get(); assertEquals(1, response.mappings().size()); assertFieldMappings(response.mappings().get("test"), FILTERED_FLAT_FIELDS); @@ -104,8 +104,8 @@ public void testFieldCapabilities() { //double check that submitting the filtered mappings to an unfiltered index leads to the same field_caps output //as the one coming from a filtered index with same mappings GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("filtered").get(); - ImmutableOpenMap filteredMapping = getMappingsResponse.getMappings().get("filtered"); - assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filteredMapping.get("_doc").getSourceAsMap())); + MappingMetaData filteredMapping = getMappingsResponse.getMappings().get("filtered"); + assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filteredMapping.getSourceAsMap())); FieldCapabilitiesResponse test = client().fieldCaps(new FieldCapabilitiesRequest().fields("*").indices("test")).actionGet(); // properties.value is an object field in the new mapping filteredFields.add("properties.value"); @@ -142,12 +142,12 @@ private static void assertFieldMappings(Map> mappings) { + private void assertExpectedMappings(ImmutableOpenMap mappings) { assertEquals(2, mappings.size()); assertNotFiltered(mappings.get("index1")); - ImmutableOpenMap filtered = mappings.get("filtered"); + MappingMetaData filtered = mappings.get("filtered"); assertFiltered(filtered); - assertMappingsAreValid(filtered.get("_doc").getSourceAsMap()); + assertMappingsAreValid(filtered.getSourceAsMap()); } private void assertMappingsAreValid(Map sourceAsMap) { @@ -160,9 +160,7 @@ private void assertMappingsAreValid(Map sourceAsMap) { } @SuppressWarnings("unchecked") - private static void assertFiltered(ImmutableOpenMap mappings) { - assertEquals(1, mappings.size()); - MappingMetaData mappingMetaData = mappings.get("_doc"); + private static void assertFiltered(MappingMetaData mappingMetaData) { assertNotNull(mappingMetaData); Map sourceAsMap = mappingMetaData.getSourceAsMap(); assertEquals(4, sourceAsMap.size()); @@ -207,9 +205,7 @@ private static void assertFiltered(ImmutableOpenMap map } @SuppressWarnings("unchecked") - private static void assertNotFiltered(ImmutableOpenMap mappings) { - assertEquals(1, mappings.size()); - MappingMetaData mappingMetaData = mappings.get("_doc"); + private static void assertNotFiltered(MappingMetaData mappingMetaData) { assertNotNull(mappingMetaData); Map sourceAsMap = mappingMetaData.getSourceAsMap(); assertEquals(4, sourceAsMap.size()); diff --git a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java index d8066977fed8b..7cf592417efaf 100644 --- a/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/index/mapper/MultiFieldsIntegrationIT.java @@ -51,7 +51,7 @@ public void testMultiFields() throws Exception { ); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); Map mappingSource = mappingMetaData.sourceAsMap(); Map titleFields = ((Map) XContentMapValues.extractValue("properties.title.fields", mappingSource)); @@ -79,7 +79,7 @@ public void testMultiFields() throws Exception { ); getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); mappingSource = mappingMetaData.sourceAsMap(); assertThat(((Map) XContentMapValues.extractValue("properties.title", mappingSource)).size(), equalTo(2)); @@ -109,7 +109,7 @@ public void testGeoPointMultiField() throws Exception { ); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); Map mappingSource = mappingMetaData.sourceAsMap(); Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource)); @@ -140,7 +140,7 @@ public void testCompletionMultiField() throws Exception { ); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); Map mappingSource = mappingMetaData.sourceAsMap(); Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource)); @@ -165,7 +165,7 @@ public void testIpMultiField() throws Exception { ); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get(); - MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type"); + MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index"); assertThat(mappingMetaData, not(nullValue())); Map mappingSource = mappingMetaData.sourceAsMap(); Map aField = ((Map) XContentMapValues.extractValue("properties.a", mappingSource)); diff --git a/server/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java b/server/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java index e922fcca9c5a7..13eab9c241aa9 100644 --- a/server/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/indices/IndicesOptionsIntegrationIT.java @@ -538,27 +538,27 @@ public void testPutMapping() throws Exception { } 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()); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), 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()); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), 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()); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), 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()); + assertThat(client().admin().indices().prepareGetMappings("foo").get().mappings().get("foo"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("foobar").get().mappings().get("foobar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("bar").get().mappings().get("bar"), notNullValue()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), 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()); + assertThat(client().admin().indices().prepareGetMappings("barbaz").get().mappings().get("barbaz"), notNullValue()); } public static final class TestPlugin extends Plugin { diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java index c52cd313a8e6c..d94fd12e0b610 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java @@ -53,7 +53,7 @@ public void testGetMappingsWhereThereAreNone() { createIndex("index"); GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet(); assertThat(response.mappings().containsKey("index"), equalTo(true)); - assertThat(response.mappings().get("index").size(), equalTo(0)); + assertNull(response.mappings().get("index")); } private XContentBuilder getMappingForType(String type) throws IOException { @@ -77,50 +77,19 @@ public void testSimpleGetMappings() throws Exception { // Get all mappings GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet(); assertThat(response.mappings().size(), equalTo(2)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - assertThat(response.mappings().get("indexb").size(), equalTo(1)); - assertThat(response.mappings().get("indexb").get("typeA"), notNullValue()); + assertThat(response.mappings().get("indexa"), notNullValue()); + assertThat(response.mappings().get("indexb"), notNullValue()); // Get all mappings, via wildcard support - response = client().admin().indices().prepareGetMappings("*").setTypes("*").execute().actionGet(); + response = client().admin().indices().prepareGetMappings("*").execute().actionGet(); assertThat(response.mappings().size(), equalTo(2)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - assertThat(response.mappings().get("indexb").size(), equalTo(1)); - assertThat(response.mappings().get("indexb").get("typeA"), notNullValue()); + assertThat(response.mappings().get("indexa"), notNullValue()); + assertThat(response.mappings().get("indexb"), notNullValue()); - // Get all typeA mappings in all indices - response = client().admin().indices().prepareGetMappings("*").setTypes("typeA").execute().actionGet(); - assertThat(response.mappings().size(), equalTo(2)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - assertThat(response.mappings().get("indexb").size(), equalTo(1)); - assertThat(response.mappings().get("indexb").get("typeA"), notNullValue()); - - // Get all mappings in indexa + // Get mappings in indexa response = client().admin().indices().prepareGetMappings("indexa").execute().actionGet(); assertThat(response.mappings().size(), equalTo(1)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - - // Get all mappings beginning with A* in indexa - response = client().admin().indices().prepareGetMappings("indexa").setTypes("*A").execute().actionGet(); - assertThat(response.mappings().size(), equalTo(1)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - - // Get all mappings beginning with B* in all indices - response = client().admin().indices().prepareGetMappings().setTypes("B*").execute().actionGet(); - assertThat(response.mappings().size(), equalTo(0)); - - // Get all mappings beginning with B* and A* in all indices - response = client().admin().indices().prepareGetMappings().setTypes("B*", "*A").execute().actionGet(); - assertThat(response.mappings().size(), equalTo(2)); - assertThat(response.mappings().get("indexa").size(), equalTo(1)); - assertThat(response.mappings().get("indexa").get("typeA"), notNullValue()); - assertThat(response.mappings().get("indexb").size(), equalTo(1)); - assertThat(response.mappings().get("indexb").get("typeA"), notNullValue()); + assertThat(response.mappings().get("indexa"), notNullValue()); } public void testGetMappingsWithBlocks() throws IOException { @@ -134,7 +103,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(1)); + assertNotNull(response.mappings().get("test")); } finally { disableIndexBlock("test", block); } diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java index d3037a7853f38..61aba5ce32ec0 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/UpdateMappingIntegrationIT.java @@ -28,7 +28,6 @@ import org.elasticsearch.cluster.action.index.MappingUpdatedAction; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.Priority; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; @@ -129,7 +128,7 @@ public void testUpdateMappingWithoutType() { assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet(); - assertThat(getMappingsResponse.mappings().get("test").get("_doc").source().toString(), + assertThat(getMappingsResponse.mappings().get("test").source().toString(), equalTo("{\"_doc\":{\"properties\":{\"body\":{\"type\":\"text\"},\"date\":{\"type\":\"integer\"}}}}")); } @@ -149,7 +148,7 @@ public void testUpdateMappingWithoutTypeMultiObjects() { assertThat(putMappingResponse.isAcknowledged(), equalTo(true)); GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet(); - assertThat(getMappingsResponse.mappings().get("test").get("_doc").source().toString(), + assertThat(getMappingsResponse.mappings().get("test").source().toString(), equalTo("{\"_doc\":{\"properties\":{\"date\":{\"type\":\"integer\"}}}}")); } @@ -243,9 +242,8 @@ public void testUpdateMappingConcurrently() throws Throwable { assertThat(response.isAcknowledged(), equalTo(true)); GetMappingsResponse getMappingResponse = client2.admin().indices().prepareGetMappings(indexName).get(); - ImmutableOpenMap mappings = getMappingResponse.getMappings().get(indexName); - assertThat(mappings.containsKey(typeName), equalTo(true)); - assertThat(((Map) mappings.get(typeName).getSourceAsMap().get("properties")).keySet(), + MappingMetaData mappings = getMappingResponse.getMappings().get(indexName); + assertThat(((Map) mappings.getSourceAsMap().get("properties")).keySet(), Matchers.hasItem(fieldName)); } } catch (Exception e) { @@ -316,12 +314,10 @@ private void assertConcreteMappingsOnAll(final String index, final String... fie */ private void assertMappingOnMaster(final String index, final String... fieldNames) { GetMappingsResponse response = client().admin().indices().prepareGetMappings(index).get(); - ImmutableOpenMap mappings = response.getMappings().get(index); + MappingMetaData mappings = response.getMappings().get(index); assertThat(mappings, notNullValue()); - MappingMetaData mappingMetaData = mappings.get(MapperService.SINGLE_MAPPING_NAME); - assertThat(mappingMetaData, notNullValue()); - Map mappingSource = mappingMetaData.getSourceAsMap(); + Map mappingSource = mappings.getSourceAsMap(); assertFalse(mappingSource.isEmpty()); assertTrue(mappingSource.containsKey("properties")); @@ -330,7 +326,7 @@ private void assertMappingOnMaster(final String index, final String... fieldName if (fieldName.indexOf('.') != -1) { fieldName = fieldName.replace(".", ".properties."); } - assertThat("field " + fieldName + " doesn't exists in mapping " + mappingMetaData.source().string(), + assertThat("field " + fieldName + " doesn't exists in mapping " + mappings.source().string(), XContentMapValues.extractValue(fieldName, mappingProperties), notNullValue()); } } diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java index 76e9751626bd9..69aa0b0dd9b0c 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRepositoryIT.java @@ -435,7 +435,7 @@ public void testFollowerMappingIsUpdated() throws IOException { clusterStateRequest.metaData(true); clusterStateRequest.indices(followerIndex); MappingMetaData mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() - .get("index2").get("doc"); + .get("index2"); assertThat(XContentMapValues.extractValue("properties.k.type", mappingMetaData.sourceAsMap()), equalTo("long")); } finally { for (MockTransportService transportService : transportServices) { diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java index 5ff897807496f..bd304504937d4 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/IndexFollowingIT.java @@ -365,26 +365,26 @@ public void testSyncMappings() throws Exception { final long firstBatchNumDocs = randomIntBetween(2, 64); for (long i = 0; i < firstBatchNumDocs; i++) { final String source = String.format(Locale.ROOT, "{\"f\":%d}", i); - leaderClient().prepareIndex("index1", "doc", Long.toString(i)).setSource(source, XContentType.JSON).get(); + leaderClient().prepareIndex("index1", "_doc", Long.toString(i)).setSource(source, XContentType.JSON).get(); } assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get() .getHits().getTotalHits().value, equalTo(firstBatchNumDocs))); MappingMetaData mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() - .get("index2").get("doc"); + .get("index2"); assertThat(XContentMapValues.extractValue("properties.f.type", mappingMetaData.sourceAsMap()), equalTo("integer")); assertThat(XContentMapValues.extractValue("properties.k", mappingMetaData.sourceAsMap()), nullValue()); final int secondBatchNumDocs = randomIntBetween(2, 64); for (long i = firstBatchNumDocs; i < firstBatchNumDocs + secondBatchNumDocs; i++) { final String source = String.format(Locale.ROOT, "{\"k\":%d}", i); - leaderClient().prepareIndex("index1", "doc", Long.toString(i)).setSource(source, XContentType.JSON).get(); + leaderClient().prepareIndex("index1", "_doc", Long.toString(i)).setSource(source, XContentType.JSON).get(); } assertBusy(() -> assertThat(followerClient().prepareSearch("index2").get().getHits().getTotalHits().value, equalTo(firstBatchNumDocs + secondBatchNumDocs))); mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() - .get("index2").get("doc"); + .get("index2"); assertThat(XContentMapValues.extractValue("properties.f.type", mappingMetaData.sourceAsMap()), equalTo("integer")); assertThat(XContentMapValues.extractValue("properties.k.type", mappingMetaData.sourceAsMap()), equalTo("long")); pauseFollow("index2"); @@ -408,7 +408,7 @@ public void testNoMappingDefined() throws Exception { pauseFollow("index2"); MappingMetaData mappingMetaData = followerClient().admin().indices().prepareGetMappings("index2").get().getMappings() - .get("index2").get("_doc"); + .get("index2"); assertThat(XContentMapValues.extractValue("properties.f.type", mappingMetaData.sourceAsMap()), equalTo("long")); assertThat(XContentMapValues.extractValue("properties.k", mappingMetaData.sourceAsMap()), nullValue()); } @@ -1052,7 +1052,7 @@ public void testUpdateAnalysisLeaderIndexSettings() throws Exception { GetMappingsRequest getMappingsRequest = new GetMappingsRequest(); getMappingsRequest.indices("follower"); GetMappingsResponse getMappingsResponse = followerClient().admin().indices().getMappings(getMappingsRequest).actionGet(); - MappingMetaData mappingMetaData = getMappingsResponse.getMappings().get("follower").get("doc"); + MappingMetaData mappingMetaData = getMappingsResponse.getMappings().get("follower"); assertThat(XContentMapValues.extractValue("properties.new_field.type", mappingMetaData.sourceAsMap()), equalTo("text")); assertThat(XContentMapValues.extractValue("properties.new_field.analyzer", mappingMetaData.sourceAsMap()), equalTo("my_analyzer")); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java index 1eec2a04be4f9..e0226ff119e42 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/job/persistence/ElasticsearchMappings.java @@ -1189,13 +1189,12 @@ public static XContentBuilder auditMessageMapping() throws IOException { static String[] mappingRequiresUpdate(ClusterState state, String[] concreteIndices, Version minVersion) throws IOException { List indicesToUpdate = new ArrayList<>(); - ImmutableOpenMap> currentMapping = state.metaData().findMappings(concreteIndices, - new String[0], MapperPlugin.NOOP_FIELD_FILTER); + ImmutableOpenMap currentMapping = state.metaData().findMappings(concreteIndices, + MapperPlugin.NOOP_FIELD_FILTER); for (String index : concreteIndices) { - ImmutableOpenMap innerMap = currentMapping.get(index); - if (innerMap != null) { - MappingMetaData metaData = innerMap.valuesIt().next(); + MappingMetaData metaData = currentMapping.get(index); + if (metaData != null) { try { @SuppressWarnings("unchecked") Map meta = (Map) metaData.sourceAsMap().get("_meta"); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java index a54c57aceb3a6..4d3e1d4a23d8a 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java @@ -16,7 +16,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -147,9 +146,7 @@ public void testSnapshotAndRestoreWithNested() throws Exception { private void assertMappings(String sourceIdx, boolean requireRouting, boolean useNested) throws IOException { GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings(sourceIdx).get(); - ImmutableOpenMap mapping = getMappingsResponse - .getMappings().get(sourceIdx); - assertTrue(mapping.containsKey("_doc")); + MappingMetaData mapping = getMappingsResponse.getMappings().get(sourceIdx); String nested = useNested ? ",\"incorrect\":{\"type\":\"object\"},\"nested\":{\"type\":\"nested\",\"properties\":{\"value\":{\"type\":\"long\"}}}" : ""; if (requireRouting) { @@ -157,12 +154,12 @@ private void assertMappings(String sourceIdx, boolean requireRouting, boolean us "\"_meta\":{\"_doc\":{\"_routing\":{\"required\":true}," + "\"properties\":{\"field1\":{\"type\":\"text\"," + "\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}" + nested + - "}}}}}", mapping.get("_doc").source().string()); + "}}}}}", mapping.source().string()); } else { assertEquals("{\"_doc\":{\"enabled\":false," + "\"_meta\":{\"_doc\":{\"properties\":{\"field1\":{\"type\":\"text\"," + "\"fields\":{\"keyword\":{\"type\":\"keyword\",\"ignore_above\":256}}}" + nested + "}}}}}", - mapping.get("_doc").source().string()); + mapping.source().string()); } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java index 22ee0df16c102..23c410917497f 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/security/authz/accesscontrol/FieldSubsetReaderTests.java @@ -1024,10 +1024,10 @@ public void testMappingsFilteringDuelWithSourceFiltering() throws Exception { { FieldPermissionsDefinition definition = new FieldPermissionsDefinition(new String[]{"*inner1"}, Strings.EMPTY_ARRAY); FieldPermissions fieldPermissions = new FieldPermissions(definition); - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index"}, - new String[]{"doc"}, index -> fieldPermissions::grantsAccessTo); - ImmutableOpenMap index = mappings.get("index"); - Map sourceAsMap = index.get("doc").getSourceAsMap(); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index"}, + index -> fieldPermissions::grantsAccessTo); + MappingMetaData index = mappings.get("index"); + Map sourceAsMap = index.getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map) sourceAsMap.get("properties"); assertEquals(2, properties.size()); @@ -1061,10 +1061,10 @@ public void testMappingsFilteringDuelWithSourceFiltering() throws Exception { { FieldPermissionsDefinition definition = new FieldPermissionsDefinition(new String[]{"object*"}, Strings.EMPTY_ARRAY); FieldPermissions fieldPermissions = new FieldPermissions(definition); - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index"}, - new String[]{"doc"}, index -> fieldPermissions::grantsAccessTo); - ImmutableOpenMap index = mappings.get("index"); - Map sourceAsMap = index.get("doc").getSourceAsMap(); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index"}, + index -> fieldPermissions::grantsAccessTo); + MappingMetaData index = mappings.get("index"); + Map sourceAsMap = index.getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map) sourceAsMap.get("properties"); assertEquals(1, properties.size()); @@ -1097,10 +1097,10 @@ public void testMappingsFilteringDuelWithSourceFiltering() throws Exception { { FieldPermissionsDefinition definition = new FieldPermissionsDefinition(new String[]{"object"}, Strings.EMPTY_ARRAY); FieldPermissions fieldPermissions = new FieldPermissions(definition); - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index"}, - new String[]{"doc"}, index -> fieldPermissions::grantsAccessTo); - ImmutableOpenMap index = mappings.get("index"); - Map sourceAsMap = index.get("doc").getSourceAsMap(); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index"}, + index -> fieldPermissions::grantsAccessTo); + MappingMetaData index = mappings.get("index"); + Map sourceAsMap = index.getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map) sourceAsMap.get("properties"); assertEquals(1, properties.size()); @@ -1123,10 +1123,10 @@ public void testMappingsFilteringDuelWithSourceFiltering() throws Exception { { FieldPermissionsDefinition definition = new FieldPermissionsDefinition(new String[]{"nested.inner2"}, Strings.EMPTY_ARRAY); FieldPermissions fieldPermissions = new FieldPermissions(definition); - ImmutableOpenMap> mappings = metaData.findMappings(new String[]{"index"}, - new String[]{"doc"}, index -> fieldPermissions::grantsAccessTo); - ImmutableOpenMap index = mappings.get("index"); - Map sourceAsMap = index.get("doc").getSourceAsMap(); + ImmutableOpenMap mappings = metaData.findMappings(new String[]{"index"}, + index -> fieldPermissions::grantsAccessTo); + MappingMetaData index = mappings.get("index"); + Map sourceAsMap = index.getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map) sourceAsMap.get("properties"); assertEquals(1, properties.size()); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndex.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndex.java index c19472e22a84e..d7e1554125b9d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndex.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndex.java @@ -25,6 +25,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.IndexSortConfig; +import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsConfig; @@ -183,13 +184,10 @@ public static void updateMappingsToDestIndex(Client client, DataFrameAnalyticsCo // We have validated the destination index should match a single index assert getIndexResponse.indices().length == 1; - ImmutableOpenMap mappings = getIndexResponse.getMappings().get(getIndexResponse.indices()[0]); - String type = mappings.keysIt().next(); - Map addedMappings = Map.of(PROPERTIES, Map.of(ID_COPY, Map.of("type", "keyword"))); PutMappingRequest putMappingRequest = new PutMappingRequest(getIndexResponse.indices()); - putMappingRequest.type(type); + putMappingRequest.type(MapperService.SINGLE_MAPPING_NAME); putMappingRequest.source(addedMappings); ClientHelper.executeWithHeadersAsync(analyticsConfig.getHeaders(), ML_ORIGIN, client, PutMappingAction.INSTANCE, putMappingRequest, listener); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java index f007831f7cfa4..34056ece4afe6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java @@ -45,26 +45,16 @@ public static void mergeMappings(Client client, Map headers, Str } static ImmutableOpenMap mergeMappings(GetMappingsResponse getMappingsResponse) { - ImmutableOpenMap> indexToMappings = getMappingsResponse.getMappings(); + ImmutableOpenMap indexToMappings = getMappingsResponse.getMappings(); String type = null; Map mergedMappings = new HashMap<>(); - Iterator>> iterator = indexToMappings.iterator(); + Iterator> iterator = indexToMappings.iterator(); while (iterator.hasNext()) { - ObjectObjectCursor> indexMappings = iterator.next(); - Iterator> typeIterator = indexMappings.value.iterator(); - while (typeIterator.hasNext()) { - ObjectObjectCursor typeMapping = typeIterator.next(); - if (type == null) { - type = typeMapping.key; - } else { - if (type.equals(typeMapping.key) == false) { - throw ExceptionsHelper.badRequestException("source indices contain mappings for different types: [{}, {}]", - type, typeMapping.key); - } - } - Map currentMappings = typeMapping.value.getSourceAsMap(); + MappingMetaData mapping = iterator.next().value; + if (mapping != null) { + Map currentMappings = mapping.getSourceAsMap(); if (currentMappings.containsKey("properties")) { @SuppressWarnings("unchecked") diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java index 777467af2d49b..bcddfdcbf2cbc 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProvider.java @@ -45,7 +45,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; @@ -311,12 +310,10 @@ public void createJobResultIndex(Job job, ClusterState state, final ActionListen // just been created. So we need yet another operation to get the mappings for it. getLatestIndexMappings(indexName, ActionListener.wrap( response -> { - // Expect one index and one type. If this is not the case then it means the + // Expect one index. If this is not the case then it means the // index has been deleted almost immediately after being created, and this is // so unlikely that it's reasonable to fail the whole operation. - ImmutableOpenMap indexMappings = - response.getMappings().iterator().next().value; - MappingMetaData typeMappings = indexMappings.iterator().next().value; + MappingMetaData typeMappings = response.getMappings().iterator().next().value; addTermsAndAliases(typeMappings, indexName, termFields, createAliasListener); }, finalListener::onFailure diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndexTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndexTests.java index 40bba1503cdc7..d82f79adf8108 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndexTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/DataFrameAnalyticsIndexTests.java @@ -119,14 +119,9 @@ public void testCreateDestinationIndex() throws IOException { Map index2Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings", "field_2", "field_2_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("_doc", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("_doc", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java index 670f6e559bd4f..36eb7c3acd17b 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/dataframe/MappingsMergerTests.java @@ -29,14 +29,9 @@ public void testMergeMappings_GivenIndicesWithIdenticalMappings() throws IOExcep Map index2Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings", "field_2", "field_2_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("_doc", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("_doc", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); @@ -54,14 +49,9 @@ public void testMergeMappings_GivenIndicesWithDifferentTypes() throws IOExceptio Map index2Mappings = Map.of("properties", Map.of("field_1", "field_1_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("type_1", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("type_2", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); @@ -80,14 +70,9 @@ public void testMergeMappings_GivenFieldWithDifferentMapping() throws IOExceptio Map index2Mappings = Map.of("properties", Map.of("field_1", "different_field_1_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("_doc", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("_doc", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); @@ -106,14 +91,9 @@ public void testMergeMappings_GivenIndicesWithDifferentMappingsButNoConflicts() Map.of("field_1", "field_1_mappings", "field_3", "field_3_mappings")); MappingMetaData index2MappingMetaData = new MappingMetaData("_doc", index2Mappings); - ImmutableOpenMap.Builder index1MappingsMap = ImmutableOpenMap.builder(); - index1MappingsMap.put("_doc", index1MappingMetaData); - ImmutableOpenMap.Builder index2MappingsMap = ImmutableOpenMap.builder(); - index2MappingsMap.put("_doc", index2MappingMetaData); - - ImmutableOpenMap.Builder> mappings = ImmutableOpenMap.builder(); - mappings.put("index_1", index1MappingsMap.build()); - mappings.put("index_2", index2MappingsMap.build()); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + mappings.put("index_1", index1MappingMetaData); + mappings.put("index_2", index2MappingMetaData); GetMappingsResponse getMappingsResponse = new GetMappingsResponse(mappings.build()); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java index 3c62db210f763..3b1ecf377f8d4 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/integration/JobResultsProviderIT.java @@ -120,12 +120,11 @@ public void testMultipleSimultaneousJobCreations() { String sharedResultsIndex = AnomalyDetectorsIndexFields.RESULTS_INDEX_PREFIX + AnomalyDetectorsIndexFields.RESULTS_INDEX_DEFAULT; GetMappingsRequest request = new GetMappingsRequest().indices(sharedResultsIndex); GetMappingsResponse response = client().execute(GetMappingsAction.INSTANCE, request).actionGet(); - ImmutableOpenMap> indexMappings = response.getMappings(); + ImmutableOpenMap indexMappings = response.getMappings(); assertNotNull(indexMappings); - ImmutableOpenMap typeMappings = indexMappings.get(sharedResultsIndex); + MappingMetaData typeMappings = indexMappings.get(sharedResultsIndex); assertNotNull("expected " + sharedResultsIndex + " in " + indexMappings, typeMappings); - assertEquals("expected 1 type in " + typeMappings, 1, typeMappings.size()); - Map mappings = typeMappings.iterator().next().value.getSourceAsMap(); + Map mappings = typeMappings.getSourceAsMap(); assertNotNull(mappings); @SuppressWarnings("unchecked") Map properties = (Map) mappings.get("properties"); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java index 76b1b459c2165..8b099301a5836 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobResultsProviderTests.java @@ -143,11 +143,10 @@ public void testCreateJobWithExistingIndex() { clientBuilder.preparePutMapping(mock(AcknowledgedResponse.class), Result.TYPE.getPreferredName()); GetMappingsResponse getMappingsResponse = mock(GetMappingsResponse.class); - ImmutableOpenMap typeMappings = ImmutableOpenMap.of(); - ImmutableOpenMap> mappings = - ImmutableOpenMap.>builder() - .fPut(AnomalyDetectorsIndex.jobResultsAliasedName("foo"), typeMappings).build(); + ImmutableOpenMap mappings = + ImmutableOpenMap.builder() + .fPut(AnomalyDetectorsIndex.jobResultsAliasedName("foo"), null).build(); when(getMappingsResponse.mappings()).thenReturn(mappings); clientBuilder.prepareGetMapping(getMappingsResponse); diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java index b18b917113802..c231200e57d6d 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/action/TransportPutRollupJobAction.java @@ -213,7 +213,7 @@ static void updateMapping(RollupJob job, ActionListener li final String indexName = job.getConfig().getRollupIndex(); CheckedConsumer getMappingResponseHandler = getMappingResponse -> { - MappingMetaData mappings = getMappingResponse.getMappings().get(indexName).get(RollupField.TYPE_NAME); + MappingMetaData mappings = getMappingResponse.getMappings().get(indexName); Object m = mappings.getSourceAsMap().get("_meta"); if (m == null) { String msg = "Rollup data cannot be added to existing indices that contain non-rollup data (expected " + diff --git a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java index 9f5359c9424de..bedfe8cd59b68 100644 --- a/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java +++ b/x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/PutJobStateMachineTests.java @@ -197,11 +197,9 @@ public void testNoMetadataInMapping() { doAnswer(invocation -> { GetMappingsResponse response = mock(GetMappingsResponse.class); MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.emptyMap()); - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(job.getConfig().getRollupIndex(), builder.build()); + ImmutableOpenMap.Builder builder2 = ImmutableOpenMap.builder(1); + builder2.put(job.getConfig().getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder2.build()); requestCaptor.getValue().onResponse(response); @@ -235,11 +233,9 @@ public void testMetadataButNotRollup() { Collections.singletonMap(job.getConfig().getId(), job.getConfig())); MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.singletonMap("_meta", m)); - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(job.getConfig().getRollupIndex(), builder.build()); + ImmutableOpenMap.Builder builder2 = ImmutableOpenMap.builder(1); + builder2.put(job.getConfig().getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder2.build()); requestCaptor.getValue().onResponse(response); @@ -272,11 +268,9 @@ public void testNoMappingVersion() { Collections.singletonMap(job.getConfig().getId(), job.getConfig())); MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.singletonMap("_meta", m)); - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(job.getConfig().getRollupIndex(), builder.build()); + ImmutableOpenMap.Builder builder2 = ImmutableOpenMap.builder(1); + builder2.put(job.getConfig().getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder2.build()); requestCaptor.getValue().onResponse(response); @@ -309,11 +303,9 @@ public void testJobAlreadyInMapping() { Collections.singletonMap(job.getConfig().getId(), job.getConfig())); MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.singletonMap("_meta", m)); - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(job.getConfig().getRollupIndex(), builder.build()); + ImmutableOpenMap.Builder builder2 = ImmutableOpenMap.builder(1); + builder2.put(job.getConfig().getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder2.build()); requestCaptor.getValue().onResponse(response); @@ -350,11 +342,9 @@ public void testAddJobToMapping() { Collections.singletonMap(unrelatedJob.getId(), unrelatedJob)); MappingMetaData meta = new MappingMetaData(RollupField.TYPE_NAME, Collections.singletonMap("_meta", m)); - ImmutableOpenMap.Builder builder = ImmutableOpenMap.builder(1); - builder.put(RollupField.TYPE_NAME, meta); - ImmutableOpenMap.Builder> builder2 = ImmutableOpenMap.builder(1); - builder2.put(unrelatedJob.getRollupIndex(), builder.build()); + ImmutableOpenMap.Builder builder2 = ImmutableOpenMap.builder(1); + builder2.put(unrelatedJob.getRollupIndex(), meta); when(response.getMappings()).thenReturn(builder2.build()); requestCaptor.getValue().onResponse(response); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java index ce235895e0fa2..d88827da0f6d6 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/DocumentAndFieldLevelSecurityTests.java @@ -398,9 +398,9 @@ public void testFieldCapabilitiesIsFiltered() { } @SuppressWarnings("unchecked") - private static void assertExpectedFields(ImmutableOpenMap> mappings, + private static void assertExpectedFields(ImmutableOpenMap mappings, String... fields) { - Map sourceAsMap = mappings.get("test").get("type1").getSourceAsMap(); + Map sourceAsMap = mappings.get("test").getSourceAsMap(); assertEquals(1, sourceAsMap.size()); Map properties = (Map)sourceAsMap.get("properties"); assertEquals(fields.length, properties.size()); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java index c3c398baa9992..ff9127fb1eb60 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/integration/KibanaUserRoleIntegTests.java @@ -155,11 +155,10 @@ public void testGetMappings() throws Exception { .indices() .prepareGetMappings("logstash-*") .get(); - ImmutableOpenMap> mappingsMap = response.getMappings(); + ImmutableOpenMap mappingsMap = response.getMappings(); assertNotNull(mappingsMap); assertNotNull(mappingsMap.get(index)); - assertNotNull(mappingsMap.get(index).get(type)); - MappingMetaData mappingMetaData = mappingsMap.get(index).get(type); + MappingMetaData mappingMetaData = mappingsMap.get(index); assertThat(mappingMetaData.getSourceAsMap(), hasKey("properties")); assertThat(mappingMetaData.getSourceAsMap().get("properties"), instanceOf(Map.class)); Map propertiesMap = (Map) mappingMetaData.getSourceAsMap().get("properties"); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index d97415ea8ca9d..2a80b2b4f6747 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -8,7 +8,6 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ObjectPath; import org.elasticsearch.index.query.QueryBuilders; @@ -33,7 +32,6 @@ import java.util.List; import java.util.Map; -import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME; import static org.elasticsearch.search.aggregations.AggregationBuilders.terms; import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -158,11 +156,10 @@ public void testExceptionMapping() { // ensure that enabled is set to false List indexed = new ArrayList<>(); GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings(HistoryStoreField.INDEX_PREFIX + "*").get(); - Iterator> iterator = mappingsResponse.getMappings().valuesIt(); + Iterator iterator = mappingsResponse.getMappings().valuesIt(); while (iterator.hasNext()) { - ImmutableOpenMap mapping = iterator.next(); - assertThat(mapping.containsKey(SINGLE_MAPPING_NAME), is(true)); - Map docMapping = mapping.get(SINGLE_MAPPING_NAME).getSourceAsMap(); + MappingMetaData mapping = iterator.next(); + Map docMapping = mapping.getSourceAsMap(); if (abortAtInput) { Boolean enabled = ObjectPath.eval("properties.result.properties.input.properties.error.enabled", docMapping); indexed.add(enabled); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java index 69d0ea9b0b0e6..d42ebf753a3a9 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; import org.elasticsearch.cluster.metadata.MappingMetaData; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.xpack.core.watcher.execution.ExecutionState; import org.elasticsearch.xpack.core.watcher.history.HistoryStoreField; @@ -20,7 +19,6 @@ import java.util.Map; import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue; -import static org.elasticsearch.index.mapper.MapperService.SINGLE_MAPPING_NAME; import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction; import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder; import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput; @@ -50,11 +48,11 @@ public void testTimeFields() throws Exception { GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get(); assertThat(mappingsResponse, notNullValue()); assertThat(mappingsResponse.getMappings().isEmpty(), is(false)); - for (ObjectObjectCursor> metadatas : mappingsResponse.getMappings()) { + for (ObjectObjectCursor metadatas : mappingsResponse.getMappings()) { if (!metadatas.key.startsWith(HistoryStoreField.INDEX_PREFIX)) { continue; } - MappingMetaData metadata = metadatas.value.get(SINGLE_MAPPING_NAME); + MappingMetaData metadata = metadatas.value; assertThat(metadata, notNullValue()); try { Map source = metadata.getSourceAsMap(); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java index 594bdb6258cc8..82a9cffc35a9d 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/AbstractWatcherIntegrationTestCase.java @@ -263,7 +263,7 @@ private void createWatcherIndicesOrAliases() throws Exception { public void replaceWatcherIndexWithRandomlyNamedIndex(String originalIndexOrAlias, String to) { GetIndexResponse index = client().admin().indices().prepareGetIndex().setIndices(originalIndexOrAlias).get(); - MappingMetaData mapping = index.getMappings().get(index.getIndices()[0]).get(MapperService.SINGLE_MAPPING_NAME); + MappingMetaData mapping = index.getMappings().get(index.getIndices()[0]); Settings settings = index.getSettings().get(index.getIndices()[0]); Settings.Builder newSettings = Settings.builder().put(settings); diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java index 7c9e3107042fc..5aab8a27a1b5b 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HistoryIntegrationTests.java @@ -102,9 +102,8 @@ public void testFailedInputResultWithDotsInFieldNameGetsStored() throws Exceptio assertHitCount(searchResponse, 1); // as fields with dots are allowed in 5.0 again, the mapping must be checked in addition - GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*") - .addTypes(SINGLE_MAPPING_NAME).get(); - byte[] bytes = response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME).source().uncompressed(); + GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); + byte[] bytes = response.getMappings().values().iterator().next().value.source().uncompressed(); XContentSource source = new XContentSource(new BytesArray(bytes), XContentType.JSON); // lets make sure the body fields are disabled if (useChained) { @@ -143,9 +142,8 @@ public void testPayloadInputWithDotsInFieldNameWorks() throws Exception { assertHitCount(searchResponse, 1); // as fields with dots are allowed in 5.0 again, the mapping must be checked in addition - GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*") - .addTypes(SINGLE_MAPPING_NAME).get(); - byte[] bytes = response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME).source().uncompressed(); + GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); + byte[] bytes = response.getMappings().values().iterator().next().value.source().uncompressed(); XContentSource source = new XContentSource(new BytesArray(bytes), XContentType.JSON); // lets make sure the body fields are disabled @@ -201,9 +199,8 @@ public void testThatHistoryContainsStatus() throws Exception { assertThat(lastExecutionSuccesful, is(actionStatus.lastExecution().successful())); // also ensure that the status field is disabled in the watch history - GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*") - .addTypes(SINGLE_MAPPING_NAME).get(); - byte[] bytes = response.getMappings().values().iterator().next().value.get(SINGLE_MAPPING_NAME).source().uncompressed(); + GetMappingsResponse response = client().admin().indices().prepareGetMappings(".watcher-history*").get(); + byte[] bytes = response.getMappings().values().iterator().next().value.source().uncompressed(); XContentSource mappingSource = new XContentSource(new BytesArray(bytes), XContentType.JSON); assertThat(mappingSource.getValue(SINGLE_MAPPING_NAME + ".properties.status.enabled"), is(false)); assertThat(mappingSource.getValue(SINGLE_MAPPING_NAME + ".properties.status.properties.status"), is(nullValue())); From 53f54e3350cf2ee57e78f8957b7b01820e5525aa Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 14 Oct 2019 08:58:07 +0100 Subject: [PATCH 10/18] serialization --- .../action/admin/indices/get/GetIndexResponse.java | 1 - .../org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index 2ce4977a3ab96..f961745225bd6 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -261,7 +261,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws else { builder.startObject("mappings").endObject(); } - builder.endObject(); builder.startObject("settings"); Settings indexSettings = settings.get(index); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java index 34056ece4afe6..eb5b5bad578db 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java @@ -13,6 +13,7 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; @@ -74,9 +75,9 @@ static ImmutableOpenMap mergeMappings(GetMappingsRespon } } - MappingMetaData mappingMetaData = createMappingMetaData(type, mergedMappings); + MappingMetaData mappingMetaData = createMappingMetaData(MapperService.SINGLE_MAPPING_NAME, mergedMappings); ImmutableOpenMap.Builder result = ImmutableOpenMap.builder(); - result.put(type, mappingMetaData); + result.put(MapperService.SINGLE_MAPPING_NAME, mappingMetaData); return result.build(); } From 777c8ebb104dd85a577c7c91594e0be67ae06671 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 14 Oct 2019 09:26:40 +0100 Subject: [PATCH 11/18] Use proper response tests --- .../client/AbstractResponseTestCase.java | 18 ++++ .../client/indices/GetIndexResponseTests.java | 94 ++++++------------- .../indices/GetMappingsResponseTests.java | 69 ++++---------- 3 files changed, 67 insertions(+), 114 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractResponseTestCase.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractResponseTestCase.java index ea110589a4f21..2300a4158096d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractResponseTestCase.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractResponseTestCase.java @@ -19,6 +19,7 @@ package org.elasticsearch.client; import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContent; @@ -29,6 +30,10 @@ import org.elasticsearch.test.ESTestCase; import java.io.IOException; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; /** * Base class for HLRC response parsing tests. @@ -85,4 +90,17 @@ protected ToXContent.Params getParams() { return ToXContent.EMPTY_PARAMS; } + protected static void assertMapEquals(ImmutableOpenMap expected, Map actual) { + Set expectedKeys = new HashSet<>(); + Iterator keysIt = expected.keysIt(); + while (keysIt.hasNext()) { + expectedKeys.add(keysIt.next()); + } + + assertEquals(expectedKeys, actual.keySet()); + for (String key : expectedKeys) { + assertEquals(expected.get(key), actual.get(key)); + } + } + } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java index e6c12e4af1a97..1f5cb0a72525a 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java @@ -20,62 +20,40 @@ package org.elasticsearch.client.indices; import org.apache.lucene.util.CollectionUtil; +import org.elasticsearch.client.AbstractResponseTestCase; import org.elasticsearch.client.GetAliasesResponseTests; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.ToXContent.Params; -import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.RandomCreateIndexGenerator; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.test.ESTestCase; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; -import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; +public class GetIndexResponseTests extends AbstractResponseTestCase { -public class GetIndexResponseTests extends ESTestCase { - - // Because the client-side class does not have a toXContent method, we test xContent serialization by creating - // a random client object, converting it to a server object then serializing it to xContent, and finally - // parsing it back as a client object. We check equality between the original client object, and the parsed one. - public void testFromXContent() throws IOException { - xContentTester( - this::createParser, - GetIndexResponseTests::createTestInstance, - GetIndexResponseTests::toXContent, - GetIndexResponse::fromXContent) - .supportsUnknownFields(false) - .assertToXContentEquivalence(false) - .assertEqualsConsumer(GetIndexResponseTests::assertEqualInstances) - .test(); - } - - private static void assertEqualInstances(GetIndexResponse expected, GetIndexResponse actual) { - assertArrayEquals(expected.getIndices(), actual.getIndices()); - assertEquals(expected.getMappings(), actual.getMappings()); - assertEquals(expected.getSettings(), actual.getSettings()); - assertEquals(expected.getDefaultSettings(), actual.getDefaultSettings()); - assertEquals(expected.getAliases(), actual.getAliases()); - } - - private static GetIndexResponse createTestInstance() { + @Override + protected org.elasticsearch.action.admin.indices.get.GetIndexResponse createServerTestInstance(XContentType xContentType) { String[] indices = generateRandomStringArray(5, 5, false, false); - Map mappings = new HashMap<>(); - Map> aliases = new HashMap<>(); - Map settings = new HashMap<>(); - Map defaultSettings = new HashMap<>(); + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); + ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); IndexScopedSettings indexScopedSettings = IndexScopedSettings.DEFAULT_SCOPED_SETTINGS; boolean includeDefaults = randomBoolean(); for (String index: indices) { @@ -97,7 +75,22 @@ private static GetIndexResponse createTestInstance() { defaultSettings.put(index, indexScopedSettings.diff(settings.get(index), Settings.EMPTY)); } } - return new GetIndexResponse(indices, mappings, aliases, settings, defaultSettings); + return new org.elasticsearch.action.admin.indices.get.GetIndexResponse(indices, + mappings.build(), aliases.build(), settings.build(), defaultSettings.build()); + } + + @Override + protected GetIndexResponse doParseToClientInstance(XContentParser parser) throws IOException { + return GetIndexResponse.fromXContent(parser); + } + + @Override + protected void assertInstances(org.elasticsearch.action.admin.indices.get.GetIndexResponse serverTestInstance, GetIndexResponse clientInstance) { + assertArrayEquals(serverTestInstance.getIndices(), clientInstance.getIndices()); + assertMapEquals(serverTestInstance.getMappings(), clientInstance.getMappings()); + assertMapEquals(serverTestInstance.getSettings(), clientInstance.getSettings()); + assertMapEquals(serverTestInstance.defaultSettings(), clientInstance.getDefaultSettings()); + assertMapEquals(serverTestInstance.getAliases(), clientInstance.getAliases()); } private static MappingMetaData createMappingsForIndex() { @@ -160,31 +153,4 @@ private static Map randomFieldMapping() { return mappings; } - private static void toXContent(GetIndexResponse response, XContentBuilder builder) throws IOException { - // first we need to repackage from GetIndexResponse to org.elasticsearch.action.admin.indices.get.GetIndexResponse - ImmutableOpenMap.Builder allMappings = ImmutableOpenMap.builder(); - ImmutableOpenMap.Builder> aliases = ImmutableOpenMap.builder(); - ImmutableOpenMap.Builder settings = ImmutableOpenMap.builder(); - ImmutableOpenMap.Builder defaultSettings = ImmutableOpenMap.builder(); - - Map indexMappings = response.getMappings(); - for (String index : response.getIndices()) { - allMappings.put(index, indexMappings.get(index)); - aliases.put(index, response.getAliases().get(index)); - settings.put(index, response.getSettings().get(index)); - defaultSettings.put(index, response.getDefaultSettings().get(index)); - } - - org.elasticsearch.action.admin.indices.get.GetIndexResponse serverResponse - = new org.elasticsearch.action.admin.indices.get.GetIndexResponse( - response.getIndices(), - allMappings.build(), - aliases.build(), - settings.build(), - defaultSettings.build()); - - // then we can call its toXContent method, forcing no output of types - Params params = new ToXContent.MapParams(Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "false")); - serverResponse.toXContent(builder, params); - } } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java index 4595cf5cfe6b5..a39f672d484c7 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java @@ -19,54 +19,39 @@ package org.elasticsearch.client.indices; +import org.elasticsearch.client.AbstractResponseTestCase; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.ToXContent.Params; -import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.mapper.MapperService; -import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.test.ESTestCase; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Objects; -import java.util.function.Predicate; -import static org.elasticsearch.client.indices.GetMappingsResponse.MAPPINGS; -import static org.elasticsearch.test.AbstractXContentTestCase.xContentTester; +public class GetMappingsResponseTests extends AbstractResponseTestCase { -public class GetMappingsResponseTests extends ESTestCase { - - // Because the client-side class does not have a toXContent method, we test xContent serialization by creating - // a random client object, converting it to a server object then serializing it to xContent, and finally - // parsing it back as a client object. We check equality between the original client object, and the parsed one. - public void testFromXContent() throws IOException { - xContentTester( - this::createParser, - GetMappingsResponseTests::createTestInstance, - GetMappingsResponseTests::toXContent, - GetMappingsResponse::fromXContent) - .supportsUnknownFields(true) - .assertEqualsConsumer(GetMappingsResponseTests::assertEqualInstances) - .randomFieldsExcludeFilter(randomFieldsExcludeFilter()) - .test(); - } - - private static GetMappingsResponse createTestInstance() { - Map mappings = Collections.singletonMap( - "index-" + randomAlphaOfLength(5), randomMappingMetaData()); - return new GetMappingsResponse(mappings); + @Override + protected org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse createServerTestInstance(XContentType xContentType) { + ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); + int numberOfIndexes = randomIntBetween(1, 5); + for (int i = 0; i < numberOfIndexes; i++) { + mappings.put("index-" + randomAlphaOfLength(5), randomMappingMetaData()); + } + return new org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse(mappings.build()); } - private static void assertEqualInstances(GetMappingsResponse expected, GetMappingsResponse actual) { - assertEquals(expected.mappings(), actual.mappings()); + @Override + protected GetMappingsResponse doParseToClientInstance(XContentParser parser) throws IOException { + return GetMappingsResponse.fromXContent(parser); } - private Predicate randomFieldsExcludeFilter() { - return field -> !field.equals(MAPPINGS.getPreferredName()); + @Override + protected void assertInstances(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse serverTestInstance, GetMappingsResponse clientInstance) { + assertMapEquals(serverTestInstance.getMappings(), clientInstance.mappings()); } public static MappingMetaData randomMappingMetaData() { @@ -99,20 +84,4 @@ private static Map randomFieldMapping() { return mappings; } - private static void toXContent(GetMappingsResponse response, XContentBuilder builder) throws IOException { - Params params = new ToXContent.MapParams( - Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "false")); - ImmutableOpenMap.Builder allMappings = ImmutableOpenMap.builder(); - - for (Map.Entry indexEntry : response.mappings().entrySet()) { - allMappings.put(indexEntry.getKey(), indexEntry.getValue()); - } - - org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse serverResponse = - new org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse(allMappings.build()); - - builder.startObject(); - serverResponse.toXContent(builder, params); - builder.endObject(); - } } From 3ef6360824a231e0980a97ecdd40e2eb56672f53 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 14 Oct 2019 10:09:58 +0100 Subject: [PATCH 12/18] precommit, serialization --- .../client/indices/GetIndexResponseTests.java | 6 ++---- .../client/indices/GetMappingsResponseTests.java | 7 ++++--- .../admin/indices/mapping/get/GetMappingsResponse.java | 3 +++ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java index 1f5cb0a72525a..0a5208bfcaca4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java @@ -37,12 +37,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; public class GetIndexResponseTests extends AbstractResponseTestCase { @@ -85,7 +82,8 @@ protected GetIndexResponse doParseToClientInstance(XContentParser parser) throws } @Override - protected void assertInstances(org.elasticsearch.action.admin.indices.get.GetIndexResponse serverTestInstance, GetIndexResponse clientInstance) { + protected void assertInstances(org.elasticsearch.action.admin.indices.get.GetIndexResponse serverTestInstance, + GetIndexResponse clientInstance) { assertArrayEquals(serverTestInstance.getIndices(), clientInstance.getIndices()); assertMapEquals(serverTestInstance.getMappings(), clientInstance.getMappings()); assertMapEquals(serverTestInstance.getSettings(), clientInstance.getSettings()); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java index a39f672d484c7..0e6d56ff62760 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java @@ -31,8 +31,8 @@ import java.util.Map; import java.util.Objects; -public class GetMappingsResponseTests extends AbstractResponseTestCase { +public class GetMappingsResponseTests + extends AbstractResponseTestCase { @Override protected org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse createServerTestInstance(XContentType xContentType) { @@ -50,7 +50,8 @@ protected GetMappingsResponse doParseToClientInstance(XContentParser parser) thr } @Override - protected void assertInstances(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse serverTestInstance, GetMappingsResponse clientInstance) { + protected void assertInstances(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse serverTestInstance, + GetMappingsResponse clientInstance) { assertMapEquals(serverTestInstance.getMappings(), clientInstance.mappings()); } diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java index 3440492a07ab3..95b36a9535382 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -58,6 +58,9 @@ public GetMappingsResponse(ImmutableOpenMap mappings) { assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got [" + type + "]"; indexMapBuilder.put(index, new MappingMetaData(in)); } + else { + indexMapBuilder.put(index, null); + } } else { boolean hasMapping = in.readBoolean(); From b03506c7a9eb47c13ebf3982b4a03f22d7be0e32 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 16 Oct 2019 10:39:18 +0100 Subject: [PATCH 13/18] feedback --- .../admin/indices/get/GetIndexResponse.java | 83 ++----------------- .../mapping/get/GetMappingsResponse.java | 30 ++----- .../cluster/metadata/MappingMetaData.java | 30 +++++-- .../cluster/metadata/MetaData.java | 7 +- .../mapping/get/GetMappingsResponseTests.java | 20 ++--- 5 files changed, 50 insertions(+), 120 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index f961745225bd6..df2e70e8fd444 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -31,8 +31,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.index.mapper.MapperService; import java.io.IOException; @@ -42,8 +40,6 @@ import java.util.List; import java.util.Objects; -import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken; - /** * A response for a get index action. */ @@ -93,10 +89,9 @@ public GetIndexResponse(String[] indices, assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but got [" + type + "]"; mappingsMapBuilder.put(index, new MappingMetaData(in)); } - } - else { + } else { boolean hasMapping = in.readBoolean(); - mappingsMapBuilder.put(index, hasMapping ? new MappingMetaData(in) : null); + mappingsMapBuilder.put(index, hasMapping ? new MappingMetaData(in) : MappingMetaData.EMPTY_MAPPINGS); } } mappings = mappingsMapBuilder.build(); @@ -205,15 +200,14 @@ public void writeTo(StreamOutput out) throws IOException { for (ObjectObjectCursor indexEntry : mappings) { out.writeString(indexEntry.key); if (out.getVersion().before(Version.V_8_0_0)) { - out.writeVInt(indexEntry.value == null ? 0 : 1); + out.writeVInt(indexEntry.value == MappingMetaData.EMPTY_MAPPINGS ? 0 : 1); if (indexEntry.value != null) { out.writeString(MapperService.SINGLE_MAPPING_NAME); indexEntry.value.writeTo(out); } - } - else { - out.writeBoolean(indexEntry.value != null); - if (indexEntry.value != null) { + } else { + out.writeBoolean(indexEntry.value != MappingMetaData.EMPTY_MAPPINGS); + if (indexEntry.value != MappingMetaData.EMPTY_MAPPINGS) { indexEntry.value.writeTo(out); } } @@ -255,12 +249,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.endObject(); MappingMetaData indexMappings = mappings.get(index); - if (indexMappings != null) { - builder.field("mappings", indexMappings.sourceAsMap()); - } - else { - builder.startObject("mappings").endObject(); - } + builder.field("mappings", indexMappings.sourceAsMap()); builder.startObject("settings"); Settings indexSettings = settings.get(index); @@ -283,64 +272,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } - private static List parseAliases(XContentParser parser) throws IOException { - List indexAliases = new ArrayList<>(); - // We start at START_OBJECT since parseIndexEntry ensures that - while (parser.nextToken() != Token.END_OBJECT) { - ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation); - indexAliases.add(AliasMetaData.Builder.fromXContent(parser)); - } - return indexAliases; - } - - private static IndexEntry parseIndexEntry(XContentParser parser) throws IOException { - List indexAliases = null; - MappingMetaData indexMappings = null; - Settings indexSettings = null; - Settings indexDefaultSettings = null; - // We start at START_OBJECT since fromXContent ensures that - while (parser.nextToken() != Token.END_OBJECT) { - ensureExpectedToken(Token.FIELD_NAME, parser.currentToken(), parser::getTokenLocation); - parser.nextToken(); - if (parser.currentToken() == Token.START_OBJECT) { - switch (parser.currentName()) { - case "aliases": - indexAliases = parseAliases(parser); - break; - case "mappings": - indexMappings = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, parser.map()); - break; - case "settings": - indexSettings = Settings.fromXContent(parser); - break; - case "defaults": - indexDefaultSettings = Settings.fromXContent(parser); - break; - default: - parser.skipChildren(); - } - } else if (parser.currentToken() == Token.START_ARRAY) { - parser.skipChildren(); - } - } - return new IndexEntry(indexAliases, indexMappings, indexSettings, indexDefaultSettings); - } - - // This is just an internal container to make stuff easier for returning - private static class IndexEntry { - List indexAliases = new ArrayList<>(); - MappingMetaData indexMappings = null; - Settings indexSettings = Settings.EMPTY; - Settings indexDefaultSettings = Settings.EMPTY; - IndexEntry(List indexAliases, MappingMetaData indexMappings, - Settings indexSettings, Settings indexDefaultSettings) { - if (indexAliases != null) this.indexAliases = indexAliases; - if (indexMappings != null) this.indexMappings = indexMappings; - if (indexSettings != null) this.indexSettings = indexSettings; - if (indexDefaultSettings != null) this.indexDefaultSettings = indexDefaultSettings; - } - } - @Override public String toString() { return Strings.toString(this); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java index 95b36a9535382..c2906fb80c54b 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -57,14 +57,12 @@ public GetMappingsResponse(ImmutableOpenMap mappings) { String type = in.readString(); assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected type [_doc] but got [" + type + "]"; indexMapBuilder.put(index, new MappingMetaData(in)); + } else { + indexMapBuilder.put(index, MappingMetaData.EMPTY_MAPPINGS); } - else { - indexMapBuilder.put(index, null); - } - } - else { + } else { boolean hasMapping = in.readBoolean(); - indexMapBuilder.put(index, hasMapping ? new MappingMetaData(in) : null); + indexMapBuilder.put(index, hasMapping ? new MappingMetaData(in) : MappingMetaData.EMPTY_MAPPINGS); } } mappings = indexMapBuilder.build(); @@ -84,15 +82,14 @@ public void writeTo(StreamOutput out) throws IOException { for (ObjectObjectCursor indexEntry : mappings) { out.writeString(indexEntry.key); if (out.getVersion().before(Version.V_8_0_0)) { - out.writeVInt(indexEntry.value == null ? 0 : 1); + out.writeVInt(indexEntry.value == MappingMetaData.EMPTY_MAPPINGS ? 0 : 1); if (indexEntry.value != null) { out.writeString(MapperService.SINGLE_MAPPING_NAME); indexEntry.value.writeTo(out); } - } - else { - out.writeBoolean(indexEntry.value != null); - if (indexEntry.value != null) { + } else { + out.writeBoolean(indexEntry.value != MappingMetaData.EMPTY_MAPPINGS); + if (indexEntry.value != MappingMetaData.EMPTY_MAPPINGS) { indexEntry.value.writeTo(out); } } @@ -101,18 +98,9 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - for (final ObjectObjectCursor indexEntry : getMappings()) { builder.startObject(indexEntry.key); - { - MappingMetaData mappings = indexEntry.value; - if (mappings == null) { - // no mappings yet - builder.startObject(MAPPINGS.getPreferredName()).endObject(); - } else { - builder.field(MAPPINGS.getPreferredName(), mappings.sourceAsMap()); - } - } + builder.field(MAPPINGS.getPreferredName(), indexEntry.value.sourceAsMap()); builder.endObject(); } return builder; diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java index 8b58615cb12e1..6d62f220af824 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MappingMetaData.java @@ -32,6 +32,8 @@ import org.elasticsearch.index.mapper.DocumentMapper; import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Collections; import java.util.Map; import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeBooleanValue; @@ -41,6 +43,8 @@ */ public class MappingMetaData extends AbstractDiffable { + public static final MappingMetaData EMPTY_MAPPINGS = new MappingMetaData("_doc", Collections.emptyMap()); + public static class Routing { public static final Routing EMPTY = new Routing(false); @@ -75,7 +79,7 @@ public int hashCode() { private final CompressedXContent source; - private Routing routing; + private final Routing routing; public MappingMetaData(DocumentMapper docMapper) { this.type = docMapper.type(); @@ -83,6 +87,7 @@ public MappingMetaData(DocumentMapper docMapper) { this.routing = new Routing(docMapper.routingFieldMapper().required()); } + @SuppressWarnings("unchecked") public MappingMetaData(CompressedXContent mapping) { this.source = mapping; Map mappingMap = XContentHelper.convertToMap(mapping.compressedReference(), true).v2(); @@ -90,21 +95,28 @@ public MappingMetaData(CompressedXContent mapping) { throw new IllegalStateException("Can't derive type from mapping, no root type: " + mapping.string()); } this.type = mappingMap.keySet().iterator().next(); - initMappers((Map) mappingMap.get(this.type)); + this.routing = initRouting((Map) mappingMap.get(this.type)); } - public MappingMetaData(String type, Map mapping) throws IOException { + @SuppressWarnings("unchecked") + public MappingMetaData(String type, Map mapping) { this.type = type; - XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping); - this.source = new CompressedXContent(BytesReference.bytes(mappingBuilder)); + try { + XContentBuilder mappingBuilder = XContentFactory.jsonBuilder().map(mapping); + this.source = new CompressedXContent(BytesReference.bytes(mappingBuilder)); + } + catch (IOException e) { + throw new UncheckedIOException(e); // XContent exception, should never happen + } Map withoutType = mapping; if (mapping.size() == 1 && mapping.containsKey(type)) { withoutType = (Map) mapping.get(type); } - initMappers(withoutType); + this.routing = initRouting(withoutType); } - private void initMappers(Map withoutType) { + @SuppressWarnings("unchecked") + private Routing initRouting(Map withoutType) { if (withoutType.containsKey("_routing")) { boolean required = false; Map routingNode = (Map) withoutType.get("_routing"); @@ -120,9 +132,9 @@ private void initMappers(Map withoutType) { } } } - this.routing = new Routing(required); + return new Routing(required); } else { - this.routing = Routing.EMPTY; + return Routing.EMPTY; } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java index a2e0f76e7f0eb..55e08d7a86b96 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -393,8 +393,11 @@ public ImmutableOpenMap findMappings(String[] concreteI } @SuppressWarnings("unchecked") - private static MappingMetaData filterFields(MappingMetaData mappingMetaData, Predicate fieldPredicate) throws IOException { - if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE || mappingMetaData == null) { + private static MappingMetaData filterFields(MappingMetaData mappingMetaData, Predicate fieldPredicate) { + if (mappingMetaData == null) { + return MappingMetaData.EMPTY_MAPPINGS; + } + if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) { return mappingMetaData; } Map sourceAsMap = XContentHelper.convertToMap(mappingMetaData.source().compressedReference(), true).v2(); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java index e25ebde1cb143..f1167bf94ab0e 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java @@ -56,20 +56,16 @@ protected GetMappingsResponse mutateInstance(GetMappingsResponse instance) throw } public static MappingMetaData createMappingsForIndex() { - try { - Map mappings = new HashMap<>(); - if (rarely() == false) { // rarely have no fields - mappings.put("field", randomFieldMapping()); - if (randomBoolean()) { - mappings.put("field2", randomFieldMapping()); - } - String typeName = MapperService.SINGLE_MAPPING_NAME; - return new MappingMetaData(typeName, mappings); + Map mappings = new HashMap<>(); + if (rarely() == false) { // rarely have no fields + mappings.put("field", randomFieldMapping()); + if (randomBoolean()) { + mappings.put("field2", randomFieldMapping()); } - return new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, mappings); - } catch (IOException e) { - throw new AssertionError("shouldn't have failed " + e); + String typeName = MapperService.SINGLE_MAPPING_NAME; + return new MappingMetaData(typeName, mappings); } + return new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, mappings); } @Override From e8bdb169cfb221d2c8ca1b009381e3d15dbec561 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 16 Oct 2019 11:05:31 +0100 Subject: [PATCH 14/18] compilation --- .../client/indices/GetIndexResponseTests.java | 15 ++----- .../GetIndexTemplatesResponseTests.java | 33 ++++++-------- .../indices/GetMappingsResponseTests.java | 6 +-- .../EnrichPolicyMaintenanceService.java | 5 +-- .../xpack/enrich/EnrichPolicyRunner.java | 10 ++--- .../xpack/enrich/EnrichPolicyRunnerTests.java | 44 +++++++++---------- .../xpack/ml/dataframe/MappingsMerger.java | 7 +-- 7 files changed, 46 insertions(+), 74 deletions(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java index 0a5208bfcaca4..8296b3bce03f1 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexResponseTests.java @@ -93,12 +93,7 @@ protected void assertInstances(org.elasticsearch.action.admin.indices.get.GetInd private static MappingMetaData createMappingsForIndex() { int typeCount = rarely() ? 0 : 1; - MappingMetaData mmd; - try { - mmd = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, Collections.emptyMap()); - } catch (IOException e) { - throw new RuntimeException(e); - } + MappingMetaData mmd = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, Collections.emptyMap()); for (int i = 0; i < typeCount; i++) { if (rarely() == false) { // rarely have no fields Map mappings = new HashMap<>(); @@ -107,12 +102,8 @@ private static MappingMetaData createMappingsForIndex() { mappings.put("field2-" + i, randomFieldMapping()); } - try { - String typeName = MapperService.SINGLE_MAPPING_NAME; - mmd = new MappingMetaData(typeName, mappings); - } catch (IOException e) { - fail("shouldn't have failed " + e); - } + String typeName = MapperService.SINGLE_MAPPING_NAME; + mmd = new MappingMetaData(typeName, mappings); } } return mmd; diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java index d94d8572f3de9..be063c500305d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetIndexTemplatesResponseTests.java @@ -37,7 +37,6 @@ import org.elasticsearch.test.ESTestCase; import java.io.IOException; -import java.io.UncheckedIOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -55,12 +54,12 @@ import static org.hamcrest.Matchers.equalTo; public class GetIndexTemplatesResponseTests extends ESTestCase { - + static final String mappingString = "{\"properties\":{" + "\"f1\": {\"type\":\"text\"}," + "\"f2\": {\"type\":\"keyword\"}" + "}}"; - + public void testFromXContent() throws IOException { xContentTester(this::createParser, @@ -147,7 +146,7 @@ private Predicate randomFieldsExcludeFilter() { ; } - private static void assertEqualInstances(GetIndexTemplatesResponse expectedInstance, GetIndexTemplatesResponse newInstance) { + private static void assertEqualInstances(GetIndexTemplatesResponse expectedInstance, GetIndexTemplatesResponse newInstance) { assertEquals(expectedInstance, newInstance); // Check there's no doc types at the root of the mapping Map expectedMap = XContentHelper.convertToMap( @@ -157,10 +156,10 @@ private static void assertEqualInstances(GetIndexTemplatesResponse expectedInsta if(mappingMD != null) { Map mappingAsMap = mappingMD.sourceAsMap(); assertEquals(expectedMap, mappingAsMap); - } + } } - } - + } + static GetIndexTemplatesResponse createTestInstance() { List templates = new ArrayList<>(); int numTemplates = between(0, 10); @@ -181,13 +180,9 @@ static GetIndexTemplatesResponse createTestInstance() { templateBuilder.version(between(0, 100)); } if (randomBoolean()) { - try { - Map map = XContentHelper.convertToMap(new BytesArray(mappingString), true, XContentType.JSON).v2(); - MappingMetaData mapping = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, map); - templateBuilder.mapping(mapping); - } catch (IOException ex) { - throw new UncheckedIOException(ex); - } + Map map = XContentHelper.convertToMap(new BytesArray(mappingString), true, XContentType.JSON).v2(); + MappingMetaData mapping = new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, map); + templateBuilder.mapping(mapping); } templates.add(templateBuilder.build()); } @@ -196,20 +191,20 @@ static GetIndexTemplatesResponse createTestInstance() { // As the client class GetIndexTemplatesResponse doesn't have toXContent method, adding this method here only for the test static void toXContent(GetIndexTemplatesResponse response, XContentBuilder builder) throws IOException { - + //Create a server-side counterpart for the client-side class and call toXContent on it - + List serverIndexTemplates = new ArrayList<>(); List clientIndexTemplates = response.getIndexTemplates(); for (IndexTemplateMetaData clientITMD : clientIndexTemplates) { - org.elasticsearch.cluster.metadata.IndexTemplateMetaData.Builder serverTemplateBuilder = + org.elasticsearch.cluster.metadata.IndexTemplateMetaData.Builder serverTemplateBuilder = org.elasticsearch.cluster.metadata.IndexTemplateMetaData.builder(clientITMD.name()); serverTemplateBuilder.patterns(clientITMD.patterns()); Iterator aliases = clientITMD.aliases().valuesIt(); aliases.forEachRemaining((a)->serverTemplateBuilder.putAlias(a)); - + serverTemplateBuilder.settings(clientITMD.settings()); serverTemplateBuilder.order(clientITMD.order()); serverTemplateBuilder.version(clientITMD.version()); @@ -219,7 +214,7 @@ static void toXContent(GetIndexTemplatesResponse response, XContentBuilder build serverIndexTemplates.add(serverTemplateBuilder.build()); } - org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse serverResponse = new + org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse serverResponse = new org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse(serverIndexTemplates); serverResponse.toXContent(builder, ToXContent.EMPTY_PARAMS); } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java index 0e6d56ff62760..7529c9e7c58fd 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/indices/GetMappingsResponseTests.java @@ -65,11 +65,7 @@ public static MappingMetaData randomMappingMetaData() { } } - try { - return new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, mappings); - } catch (IOException e) { - throw new RuntimeException(e); - } + return new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, mappings); } private static Map randomFieldMapping() { diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyMaintenanceService.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyMaintenanceService.java index c11bd6e9a68c9..0c734083755b6 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyMaintenanceService.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyMaintenanceService.java @@ -18,13 +18,11 @@ import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.component.LifecycleListener; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException; import org.elasticsearch.common.xcontent.ObjectPath; -import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.threadpool.Scheduler; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.enrich.EnrichPolicy; @@ -169,8 +167,7 @@ public void onFailure(Exception e) { private boolean shouldRemoveIndex(GetIndexResponse getIndexResponse, Map policies, String indexName) { // Find the policy on the index logger.debug("Checking if should remove enrich index [{}]", indexName); - ImmutableOpenMap indexMapping = getIndexResponse.getMappings().get(indexName); - MappingMetaData mappingMetaData = indexMapping.get(MapperService.SINGLE_MAPPING_NAME); + MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName); Map mapping = mappingMetaData.getSourceAsMap(); String policyName = ObjectPath.eval(MAPPING_POLICY_FIELD_PATH, mapping); // Check if index has a corresponding policy diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java index 16acc0427ac64..1770338476ac6 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java @@ -119,16 +119,14 @@ public void onFailure(Exception e) { } private Map getMappings(final GetIndexResponse getIndexResponse, final String sourceIndexName) { - ImmutableOpenMap> mappings = getIndexResponse.mappings(); - ImmutableOpenMap indexMapping = mappings.get(sourceIndexName); - if (indexMapping.keys().size() == 0) { + ImmutableOpenMap mappings = getIndexResponse.mappings(); + MappingMetaData indexMapping = mappings.get(sourceIndexName); + if (indexMapping == null) { throw new ElasticsearchException( "Enrich policy execution for [{}] failed. No mapping available on source [{}] included in [{}]", policyName, sourceIndexName, policy.getIndices()); } - assert indexMapping.keys().size() == 1 : "Expecting only one type per index"; - MappingMetaData typeMapping = indexMapping.iterator().next().value; - return typeMapping.sourceAsMap(); + return indexMapping.sourceAsMap(); } private void validateMappings(final GetIndexResponse getIndexResponse) { diff --git a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunnerTests.java b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunnerTests.java index 1c8c411dd482e..1d5a2dc7e1a36 100644 --- a/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunnerTests.java +++ b/x-pack/plugin/enrich/src/test/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunnerTests.java @@ -5,16 +5,6 @@ */ package org.elasticsearch.xpack.enrich; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; - import org.elasticsearch.ElasticsearchException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.LatchedActionListener; @@ -37,10 +27,10 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.common.xcontent.smile.SmileXContent; -import org.elasticsearch.index.engine.Segment; import org.elasticsearch.common.xcontent.json.JsonXContent; +import org.elasticsearch.common.xcontent.smile.SmileXContent; import org.elasticsearch.index.IndexNotFoundException; +import org.elasticsearch.index.engine.Segment; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.index.reindex.ReindexPlugin; @@ -60,6 +50,16 @@ import org.junit.AfterClass; import org.junit.BeforeClass; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; + import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; @@ -145,7 +145,7 @@ public void testRunner() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); validateMappingMetadata(mapping, policyName, policy); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); @@ -230,7 +230,7 @@ public void testRunnerGeoMatchType() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); validateMappingMetadata(mapping, policyName, policy); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); @@ -328,7 +328,7 @@ public void testRunnerMultiSource() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); validateMappingMetadata(mapping, policyName, policy); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); @@ -435,7 +435,7 @@ public void testRunnerMultiSourceDocIdCollisions() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); assertNotNull(properties); @@ -542,7 +542,7 @@ public void testRunnerMultiSourceEnrichKeyCollisions() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); assertNotNull(properties); @@ -806,7 +806,7 @@ public void testRunnerObjectSourceMapping() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); validateMappingMetadata(mapping, policyName, policy); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); @@ -929,7 +929,7 @@ public void testRunnerExplicitObjectSourceMapping() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); validateMappingMetadata(mapping, policyName, policy); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); @@ -1060,7 +1060,7 @@ public void testRunnerTwoObjectLevelsSourceMapping() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); validateMappingMetadata(mapping, policyName, policy); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); @@ -1182,7 +1182,7 @@ public void testRunnerDottedKeyNameSourceMapping() throws Exception { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); validateMappingMetadata(mapping, policyName, policy); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); @@ -1338,7 +1338,7 @@ protected void ensureSingleSegment(String destinationIndexName, int attempt) { assertThat(settings.get("index.auto_expand_replicas"), is(equalTo("0-all"))); // Validate Mapping - Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).get("_doc").sourceAsMap(); + Map mapping = enrichIndex.getMappings().get(createdEnrichIndex).sourceAsMap(); validateMappingMetadata(mapping, policyName, policy); assertThat(mapping.get("dynamic"), is("false")); Map properties = (Map) mapping.get("properties"); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java index eb5b5bad578db..c573f193cf01a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/dataframe/MappingsMerger.java @@ -17,7 +17,6 @@ import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; -import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -82,10 +81,6 @@ static ImmutableOpenMap mergeMappings(GetMappingsRespon } private static MappingMetaData createMappingMetaData(String type, Map mappings) { - try { - return new MappingMetaData(type, Collections.singletonMap("properties", mappings)); - } catch (IOException e) { - throw ExceptionsHelper.serverError("Failed to parse mappings: " + mappings); - } + return new MappingMetaData(type, Collections.singletonMap("properties", mappings)); } } From c8b64b3607733904e90706c5e5e6044d7160de2b Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 16 Oct 2019 11:41:14 +0100 Subject: [PATCH 15/18] still need to deal with nulls in certain cases --- .../action/admin/indices/get/GetIndexResponse.java | 6 +++++- .../admin/indices/mapping/get/GetMappingsResponse.java | 10 +++++++--- .../indices/mapping/SimpleGetMappingsIT.java | 3 ++- .../elasticsearch/xpack/enrich/EnrichPolicyRunner.java | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index df2e70e8fd444..8a22cba7a3ca9 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -249,7 +249,11 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.endObject(); MappingMetaData indexMappings = mappings.get(index); - builder.field("mappings", indexMappings.sourceAsMap()); + if (indexMappings == null) { + builder.startObject("mappings").endObject(); + } else { + builder.field("mappings", indexMappings.sourceAsMap()); + } builder.startObject("settings"); Settings indexSettings = settings.get(index); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java index c2906fb80c54b..568a6c5a2a45e 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -99,9 +99,13 @@ public void writeTo(StreamOutput out) throws IOException { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { for (final ObjectObjectCursor indexEntry : getMappings()) { - builder.startObject(indexEntry.key); - builder.field(MAPPINGS.getPreferredName(), indexEntry.value.sourceAsMap()); - builder.endObject(); + if (indexEntry.value != null) { + builder.startObject(indexEntry.key); + builder.field(MAPPINGS.getPreferredName(), indexEntry.value.sourceAsMap()); + builder.endObject(); + } else { + builder.startObject(MAPPINGS.getPreferredName()).endObject(); + } } return builder; } diff --git a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java index d94fd12e0b610..42d1b921481f6 100644 --- a/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java +++ b/server/src/test/java/org/elasticsearch/indices/mapping/SimpleGetMappingsIT.java @@ -21,6 +21,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; +import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.Priority; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.plugins.Plugin; @@ -53,7 +54,7 @@ public void testGetMappingsWhereThereAreNone() { createIndex("index"); GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet(); assertThat(response.mappings().containsKey("index"), equalTo(true)); - assertNull(response.mappings().get("index")); + assertEquals(MappingMetaData.EMPTY_MAPPINGS, response.mappings().get("index")); } private XContentBuilder getMappingForType(String type) throws IOException { diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java index 1770338476ac6..736b3c7681f1c 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java @@ -121,7 +121,7 @@ public void onFailure(Exception e) { private Map getMappings(final GetIndexResponse getIndexResponse, final String sourceIndexName) { ImmutableOpenMap mappings = getIndexResponse.mappings(); MappingMetaData indexMapping = mappings.get(sourceIndexName); - if (indexMapping == null) { + if (indexMapping == null || indexMapping == MappingMetaData.EMPTY_MAPPINGS) { throw new ElasticsearchException( "Enrich policy execution for [{}] failed. No mapping available on source [{}] included in [{}]", policyName, sourceIndexName, policy.getIndices()); From 645de20b96b3fafdd273f240277b752a71b769aa Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Wed, 16 Oct 2019 13:40:16 +0100 Subject: [PATCH 16/18] test failures --- .../org/elasticsearch/action/admin/indices/get/GetIndexIT.java | 3 +-- .../src/test/resources/rest-api-spec/test/rollup/put_job.yml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java index 6c39d6f38fb6d..3c5ff9132c704 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java @@ -45,7 +45,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; @ESIntegTestCase.SuiteScopeTestCase public class GetIndexIT extends ESIntegTestCase { @@ -243,7 +242,7 @@ private void assertEmptyOrOnlyDefaultMappings(GetIndexResponse response, String assertThat(mappings, notNullValue()); assertThat(mappings.size(), equalTo(1)); MappingMetaData indexMappings = mappings.get(indexName); - assertThat(indexMappings, nullValue()); + assertEquals(indexMappings, MappingMetaData.EMPTY_MAPPINGS); } private void assertAliases(GetIndexResponse response, String indexName) { diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml index deb53a9d05d71..27b637ba7081d 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/rollup/put_job.yml @@ -140,7 +140,7 @@ setup: indices.create: index: non-rollup - do: - catch: /foo/ + catch: /Rollup data cannot be added to existing indices that contain non-rollup data/ headers: Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser rollup.put_job: From 0e5323d7689bb8802f8b1f0d7ba49c3e5e3483f5 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Thu, 17 Oct 2019 09:20:28 +0100 Subject: [PATCH 17/18] feedback --- .../action/admin/indices/get/GetIndexResponse.java | 5 ++++- .../action/admin/indices/get/GetIndexIT.java | 10 ++++++++++ .../elasticsearch/xpack/enrich/EnrichPolicyRunner.java | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java index 8a22cba7a3ca9..9485499614f3f 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/get/GetIndexResponse.java @@ -89,6 +89,9 @@ public GetIndexResponse(String[] indices, assert MapperService.SINGLE_MAPPING_NAME.equals(type) : "Expected [_doc] but got [" + type + "]"; mappingsMapBuilder.put(index, new MappingMetaData(in)); } + else { + mappingsMapBuilder.put(index, MappingMetaData.EMPTY_MAPPINGS); + } } else { boolean hasMapping = in.readBoolean(); mappingsMapBuilder.put(index, hasMapping ? new MappingMetaData(in) : MappingMetaData.EMPTY_MAPPINGS); @@ -201,7 +204,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(indexEntry.key); if (out.getVersion().before(Version.V_8_0_0)) { out.writeVInt(indexEntry.value == MappingMetaData.EMPTY_MAPPINGS ? 0 : 1); - if (indexEntry.value != null) { + if (indexEntry.value != MappingMetaData.EMPTY_MAPPINGS) { out.writeString(MapperService.SINGLE_MAPPING_NAME); indexEntry.value.writeTo(out); } diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java index 3c5ff9132c704..5726e405f613b 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/get/GetIndexIT.java @@ -22,6 +22,7 @@ import com.carrotsearch.hppc.cursors.ObjectObjectCursor; import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.get.GetIndexRequest.Feature; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; @@ -77,6 +78,15 @@ public void testSimpleUnknownIndex() { } } + public void testUnknownIndexWithAllowNoIndices() { + GetIndexResponse response = client().admin().indices().prepareGetIndex() + .addIndices("missing_idx").setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN).get(); + assertThat(response.indices(), notNullValue()); + assertThat(response.indices().length, equalTo(0)); + assertThat(response.mappings(), notNullValue()); + assertThat(response.mappings().size(), equalTo(0)); + } + public void testEmpty() { GetIndexResponse response = client().admin().indices().prepareGetIndex().addIndices("empty_idx").get(); String[] indices = response.indices(); diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java index 736b3c7681f1c..cbd18755718cc 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPolicyRunner.java @@ -121,7 +121,7 @@ public void onFailure(Exception e) { private Map getMappings(final GetIndexResponse getIndexResponse, final String sourceIndexName) { ImmutableOpenMap mappings = getIndexResponse.mappings(); MappingMetaData indexMapping = mappings.get(sourceIndexName); - if (indexMapping == null || indexMapping == MappingMetaData.EMPTY_MAPPINGS) { + if (indexMapping == MappingMetaData.EMPTY_MAPPINGS) { throw new ElasticsearchException( "Enrich policy execution for [{}] failed. No mapping available on source [{}] included in [{}]", policyName, sourceIndexName, policy.getIndices()); From 9f93b0e48a719d06a9afa78c00879da754a0aa50 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 21 Oct 2019 09:32:42 +0100 Subject: [PATCH 18/18] BWC --- .../action/admin/indices/mapping/get/GetMappingsResponse.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java index 568a6c5a2a45e..30b939d627e38 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponse.java @@ -83,7 +83,7 @@ public void writeTo(StreamOutput out) throws IOException { out.writeString(indexEntry.key); if (out.getVersion().before(Version.V_8_0_0)) { out.writeVInt(indexEntry.value == MappingMetaData.EMPTY_MAPPINGS ? 0 : 1); - if (indexEntry.value != null) { + if (indexEntry.value != MappingMetaData.EMPTY_MAPPINGS) { out.writeString(MapperService.SINGLE_MAPPING_NAME); indexEntry.value.writeTo(out); }