Skip to content

Commit

Permalink
Remove type filter from GetMappings API (#47364)
Browse files Browse the repository at this point in the history
This commit removes the types filter from the GetMappings API, which is no longer
useful seeing as we can only have a single mapping type per index. It also changes
the structure of GetMappingsResponse and GetIndexResponse to remove the extra
nesting of mappings below the no-longer-relevant type name, and removes the types
methods from the equivalent request classes.

Relates to #41059
  • Loading branch information
romseygeek authored Oct 21, 2019
1 parent 49c2538 commit afeee4b
Show file tree
Hide file tree
Showing 57 changed files with 450 additions and 1,228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html">
* Get Mapping API on elastic.co</a>
* @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 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html">
* Get Mapping API on elastic.co</a>
* @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<org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse> 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 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html">
Expand Down Expand Up @@ -679,42 +630,6 @@ public Cancellable getAsync(GetIndexRequest getIndexRequest, RequestOptions opti
GetIndexResponse::fromXContent, listener, emptySet());
}

/**
* Retrieve information about one or more indexes
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
* Indices Get Index API on elastic.co</a>
* @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 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
* Indices Get Index API on elastic.co</a>
* @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<org.elasticsearch.action.admin.indices.get.GetIndexResponse> 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 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -85,4 +90,17 @@ protected ToXContent.Params getParams() {
return ToXContent.EMPTY_PARAMS;
}

protected static <T> void assertMapEquals(ImmutableOpenMap<String, T> expected, Map<String, T> actual) {
Set<String> expectedKeys = new HashSet<>();
Iterator<String> 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));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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();

Expand Down
Loading

0 comments on commit afeee4b

Please sign in to comment.