Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove type filter from GetMappings API #47364

Merged
merged 26 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
de8411a
Remove types from GetMappings request and response
romseygeek Oct 1, 2019
e8e8ca9
test failures
romseygeek Oct 2, 2019
97f5d3a
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 2, 2019
04341c8
null check
romseygeek Oct 2, 2019
4a053c3
null checks - need to work out what to do here
romseygeek Oct 3, 2019
b584dbe
Deal correctly with null mappings
romseygeek Oct 3, 2019
de90da4
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 3, 2019
8edbc27
imports
romseygeek Oct 3, 2019
51382b9
Fix ml mapping merger
romseygeek Oct 4, 2019
5bfc3ba
tests
romseygeek Oct 4, 2019
292c045
GetMappingsResponse and GetIndexResponse don't return types in mappings
romseygeek Oct 13, 2019
b911f14
Merge branch 'types-removal/get-mappings-response' into types-removal…
romseygeek Oct 13, 2019
53f54e3
serialization
romseygeek Oct 14, 2019
777c8eb
Use proper response tests
romseygeek Oct 14, 2019
6227bcb
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 14, 2019
3ef6360
precommit, serialization
romseygeek Oct 14, 2019
b392317
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 16, 2019
b03506c
feedback
romseygeek Oct 16, 2019
e8bdb16
compilation
romseygeek Oct 16, 2019
c8b64b3
still need to deal with nulls in certain cases
romseygeek Oct 16, 2019
645de20
test failures
romseygeek Oct 16, 2019
0e5323d
feedback
romseygeek Oct 17, 2019
80374dc
Merge branch 'master' into types-removal/getmappings
elasticmachine Oct 17, 2019
0e9a3dd
Merge branch 'master' into types-removal/getmappings
elasticmachine Oct 20, 2019
9f93b0e
BWC
romseygeek Oct 21, 2019
8a90d94
Merge remote-tracking branch 'origin/master' into types-removal/getma…
romseygeek Oct 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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