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/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/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..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 @@ -20,19 +20,17 @@ 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; @@ -43,39 +41,16 @@ import java.util.Map; import java.util.Objects; -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,17 +72,28 @@ 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() { 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<>(); @@ -116,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; @@ -160,36 +142,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()) { - 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()); - 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/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 0601609a8a766..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 @@ -19,54 +19,40 @@ 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() { @@ -79,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() { @@ -99,22 +81,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()) { - ImmutableOpenMap.Builder mappings = ImmutableOpenMap.builder(); - mappings.put(MapperService.SINGLE_MAPPING_NAME, indexEntry.getValue()); - allMappings.put(indexEntry.getKey(), mappings.build()); - } - - 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(); - } } 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/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 fc8a5f439b27c..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 @@ -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; @@ -31,34 +31,28 @@ 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; 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 +78,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 { + mappingsMapBuilder.put(index, MappingMetaData.EMPTY_MAPPINGS); + } + } else { + boolean hasMapping = in.readBoolean(); + mappingsMapBuilder.put(index, hasMapping ? new MappingMetaData(in) : MappingMetaData.EMPTY_MAPPINGS); } - mappingsMapBuilder.put(key, mappingEntryBuilder.build()); } mappings = mappingsMapBuilder.build(); @@ -133,11 +136,11 @@ public String[] getIndices() { return indices(); } - public ImmutableOpenMap> mappings() { + public ImmutableOpenMap mappings() { return mappings; } - public ImmutableOpenMap> getMappings() { + public ImmutableOpenMap getMappings() { return mappings(); } @@ -197,12 +200,19 @@ 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 == MappingMetaData.EMPTY_MAPPINGS ? 0 : 1); + if (indexEntry.value != MappingMetaData.EMPTY_MAPPINGS) { + out.writeString(MapperService.SINGLE_MAPPING_NAME); + indexEntry.value.writeTo(out); + } + } else { + out.writeBoolean(indexEntry.value != MappingMetaData.EMPTY_MAPPINGS); + if (indexEntry.value != MappingMetaData.EMPTY_MAPPINGS) { + indexEntry.value.writeTo(out); + } } } out.writeVInt(aliases.size()); @@ -241,30 +251,11 @@ 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(); + MappingMetaData indexMappings = mappings.get(index); + if (indexMappings == null) { + builder.startObject("mappings").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()); - } + builder.field("mappings", indexMappings.sourceAsMap()); } builder.startObject("settings"); @@ -288,120 +279,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 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; - 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 = parseMappings(parser); - 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<>(); - ImmutableOpenMap indexMappings = ImmutableOpenMap.of(); - Settings indexSettings = Settings.EMPTY; - Settings indexDefaultSettings = Settings.EMPTY; - IndexEntry(List indexAliases, ImmutableOpenMap 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; - } - } - - 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..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 @@ -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,120 +30,82 @@ 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 { + indexMapBuilder.put(index, MappingMetaData.EMPTY_MAPPINGS); + } + } else { + boolean hasMapping = in.readBoolean(); + indexMapBuilder.put(index, hasMapping ? new MappingMetaData(in) : MappingMetaData.EMPTY_MAPPINGS); } - 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); - } - } - } - - 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); + if (out.getVersion().before(Version.V_8_0_0)) { + out.writeVInt(indexEntry.value == MappingMetaData.EMPTY_MAPPINGS ? 0 : 1); + if (indexEntry.value != MappingMetaData.EMPTY_MAPPINGS) { + out.writeString(MapperService.SINGLE_MAPPING_NAME); + indexEntry.value.writeTo(out); + } + } else { + out.writeBoolean(indexEntry.value != MappingMetaData.EMPTY_MAPPINGS); + if (indexEntry.value != MappingMetaData.EMPTY_MAPPINGS) { + 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()) { - 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()); - } - } else { - builder.startObject(MAPPINGS.getPreferredName()); - { - for (final ObjectObjectCursor typeEntry : indexEntry.value) { - builder.field(typeEntry.key, typeEntry.value.sourceAsMap()); - } - } - builder.endObject(); - } + for (final ObjectObjectCursor indexEntry : getMappings()) { + if (indexEntry.value != null) { + builder.startObject(indexEntry.key); + builder.field(MAPPINGS.getPreferredName(), indexEntry.value.sourceAsMap()); + builder.endObject(); + } else { + builder.startObject(MAPPINGS.getPreferredName()).endObject(); } - builder.endObject(); } return builder; } 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 { + 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 0b14c692d53a5..55e08d7a86b96 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetaData.java @@ -367,61 +367,36 @@ private ImmutableOpenMap> 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 { + private static MappingMetaData filterFields(MappingMetaData mappingMetaData, Predicate fieldPredicate) { + if (mappingMetaData == null) { + return MappingMetaData.EMPTY_MAPPINGS; + } if (fieldPredicate == MapperPlugin.NOOP_FIELD_PREDICATE) { return mappingMetaData; } 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..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(); @@ -230,24 +240,19 @@ 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); - assertThat(indexMappings, notNullValue()); - assertThat(indexMappings.size(), equalTo(0)); + MappingMetaData indexMappings = mappings.get(indexName); + assertEquals(indexMappings, MappingMetaData.EMPTY_MAPPINGS); } 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..776b6ff11288c 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,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); @@ -87,21 +75,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..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 @@ -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,23 @@ 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++) { - if (rarely() == false) { // rarely have no fields - Map mappings = new HashMap<>(); - mappings.put("field-" + i, 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); - } + public static MappingMetaData createMappingsForIndex() { + 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); } - 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")); + return new MappingMetaData(MapperService.SINGLE_MAPPING_NAME, mappings); } @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..75115960e67e4 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,6 @@ 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)); // we need to delete in order to create a fresh new index with another type client.admin().indices().prepareDelete("twitter").get(); @@ -95,9 +91,9 @@ 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"); + MappingMetaData 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..7cddf10b33755 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,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 +586,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 +604,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 +646,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 +680,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 +698,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 +711,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..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)); - assertThat(response.mappings().get("index").size(), equalTo(0)); + assertEquals(MappingMetaData.EMPTY_MAPPINGS, response.mappings().get("index")); } 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()); + 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 +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)); + 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/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..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 @@ -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 == MappingMetaData.EMPTY_MAPPINGS) { 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/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..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 @@ -13,10 +13,10 @@ 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; -import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; @@ -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") @@ -84,17 +74,13 @@ 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(); } 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)); } } 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..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 @@ -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; @@ -29,14 +28,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()); @@ -47,32 +41,6 @@ public void testMergeMappings_GivenIndicesWithIdenticalMappings() throws IOExcep 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 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()); - - 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); @@ -80,14 +48,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 +69,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 5fc608da9fe91..bde16f7e9ac07 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 254ced6e54bde..e99abb225defa 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/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: 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()));