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