Skip to content

Commit afeee4b

Browse files
authored
Remove type filter from GetMappings API (#47364)
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
1 parent 49c2538 commit afeee4b

File tree

57 files changed

+450
-1228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+450
-1228
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesClient.java

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -297,55 +297,6 @@ public Cancellable getMappingAsync(GetMappingsRequest getMappingsRequest, Reques
297297
emptySet());
298298
}
299299

300-
/**
301-
* Retrieves the mappings on an index or indices using the Get Mapping API.
302-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html">
303-
* Get Mapping API on elastic.co</a>
304-
* @param getMappingsRequest the request
305-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
306-
* @return the response
307-
* @throws IOException in case there is a problem sending the request or parsing back the response
308-
*
309-
* @deprecated This method uses old request and response objects which still refer to types, a deprecated
310-
* feature. The method {@link #getMapping(GetMappingsRequest, RequestOptions)} should be used instead, which
311-
* accepts a new request object.
312-
*/
313-
@Deprecated
314-
public org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse getMapping(
315-
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest,
316-
RequestOptions options) throws IOException {
317-
return restHighLevelClient.performRequestAndParseEntity(getMappingsRequest,
318-
IndicesRequestConverters::getMappings,
319-
options,
320-
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent,
321-
emptySet());
322-
}
323-
324-
/**
325-
* Asynchronously retrieves the mappings on an index on indices using the Get Mapping API.
326-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html">
327-
* Get Mapping API on elastic.co</a>
328-
* @param getMappingsRequest the request
329-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
330-
* @param listener the listener to be notified upon request completion
331-
*
332-
* @deprecated This method uses old request and response objects which still refer to types, a deprecated feature.
333-
* The method {@link #getMapping(GetMappingsRequest, RequestOptions)} should be used instead, which accepts a new
334-
* request object.
335-
* @return cancellable that may be used to cancel the request
336-
*/
337-
@Deprecated
338-
public Cancellable getMappingAsync(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest,
339-
RequestOptions options,
340-
ActionListener<org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse> listener) {
341-
return restHighLevelClient.performRequestAsyncAndParseEntity(getMappingsRequest,
342-
IndicesRequestConverters::getMappings,
343-
options,
344-
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse::fromXContent,
345-
listener,
346-
emptySet());
347-
}
348-
349300
/**
350301
* Retrieves the field mappings on an index or indices using the Get Field Mapping API.
351302
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html">
@@ -679,42 +630,6 @@ public Cancellable getAsync(GetIndexRequest getIndexRequest, RequestOptions opti
679630
GetIndexResponse::fromXContent, listener, emptySet());
680631
}
681632

682-
/**
683-
* Retrieve information about one or more indexes
684-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
685-
* Indices Get Index API on elastic.co</a>
686-
* @param getIndexRequest the request
687-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
688-
* @return the response
689-
* @throws IOException in case there is a problem sending the request or parsing back the response
690-
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
691-
* {@link #get(GetIndexRequest, RequestOptions)} should be used instead, which accepts a new request object.
692-
*/
693-
@Deprecated
694-
public org.elasticsearch.action.admin.indices.get.GetIndexResponse get(
695-
org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest, RequestOptions options) throws IOException {
696-
return restHighLevelClient.performRequestAndParseEntity(getIndexRequest, IndicesRequestConverters::getIndex, options,
697-
org.elasticsearch.action.admin.indices.get.GetIndexResponse::fromXContent, emptySet());
698-
}
699-
700-
/**
701-
* Retrieve information about one or more indexes
702-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">
703-
* Indices Get Index API on elastic.co</a>
704-
* @param getIndexRequest the request
705-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
706-
* @param listener the listener to be notified upon request completion
707-
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
708-
* {@link #getAsync(GetIndexRequest, RequestOptions, ActionListener)} should be used instead, which accepts a new request object.
709-
* @return cancellable that may be used to cancel the request
710-
*/
711-
@Deprecated
712-
public Cancellable getAsync(org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest, RequestOptions options,
713-
ActionListener<org.elasticsearch.action.admin.indices.get.GetIndexResponse> listener) {
714-
return restHighLevelClient.performRequestAsyncAndParseEntity(getIndexRequest, IndicesRequestConverters::getIndex, options,
715-
org.elasticsearch.action.admin.indices.get.GetIndexResponse::fromXContent, listener, emptySet());
716-
}
717-
718633
/**
719634
* Force merge one or more indices using the Force Merge API.
720635
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html">

client/rest-high-level/src/main/java/org/elasticsearch/client/IndicesRequestConverters.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -189,22 +189,6 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) {
189189
return request;
190190
}
191191

192-
@Deprecated
193-
static Request getMappings(org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingsRequest) {
194-
String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();
195-
String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types();
196-
197-
Request request = new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping", types));
198-
199-
RequestConverters.Params parameters = new RequestConverters.Params();
200-
parameters.withMasterTimeout(getMappingsRequest.masterNodeTimeout());
201-
parameters.withIndicesOptions(getMappingsRequest.indicesOptions());
202-
parameters.withLocal(getMappingsRequest.local());
203-
parameters.putParam(INCLUDE_TYPE_NAME_PARAMETER, "true");
204-
request.addParameters(parameters.asMap());
205-
return request;
206-
}
207-
208192
static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest) {
209193
String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
210194
String[] fields = getFieldMappingsRequest.fields() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.fields();

client/rest-high-level/src/test/java/org/elasticsearch/client/AbstractResponseTestCase.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.elasticsearch.client;
2020

2121
import org.elasticsearch.common.bytes.BytesReference;
22+
import org.elasticsearch.common.collect.ImmutableOpenMap;
2223
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
2324
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
2425
import org.elasticsearch.common.xcontent.ToXContent;
@@ -29,6 +30,10 @@
2930
import org.elasticsearch.test.ESTestCase;
3031

3132
import java.io.IOException;
33+
import java.util.HashSet;
34+
import java.util.Iterator;
35+
import java.util.Map;
36+
import java.util.Set;
3237

3338
/**
3439
* Base class for HLRC response parsing tests.
@@ -85,4 +90,17 @@ protected ToXContent.Params getParams() {
8590
return ToXContent.EMPTY_PARAMS;
8691
}
8792

93+
protected static <T> void assertMapEquals(ImmutableOpenMap<String, T> expected, Map<String, T> actual) {
94+
Set<String> expectedKeys = new HashSet<>();
95+
Iterator<String> keysIt = expected.keysIt();
96+
while (keysIt.hasNext()) {
97+
expectedKeys.add(keysIt.next());
98+
}
99+
100+
assertEquals(expectedKeys, actual.keySet());
101+
for (String key : expectedKeys) {
102+
assertEquals(expected.get(key), actual.get(key));
103+
}
104+
}
105+
88106
}

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesClientIT.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
import org.elasticsearch.rest.RestStatus;
101101
import org.elasticsearch.rest.action.admin.indices.RestCreateIndexAction;
102102
import org.elasticsearch.rest.action.admin.indices.RestGetIndexTemplateAction;
103-
import org.elasticsearch.rest.action.admin.indices.RestGetIndicesAction;
104103
import org.elasticsearch.rest.action.admin.indices.RestPutIndexTemplateAction;
105104
import org.elasticsearch.rest.action.admin.indices.RestRolloverIndexAction;
106105

@@ -451,33 +450,6 @@ public void testGetIndex() throws IOException {
451450
assertEquals("integer", fieldMapping.get("type"));
452451
}
453452

454-
@SuppressWarnings("unchecked")
455-
public void testGetIndexWithTypes() throws IOException {
456-
String indexName = "get_index_test";
457-
Settings basicSettings = Settings.builder()
458-
.put(SETTING_NUMBER_OF_SHARDS, 1)
459-
.put(SETTING_NUMBER_OF_REPLICAS, 0)
460-
.build();
461-
String mappings = "\"properties\":{\"field-1\":{\"type\":\"integer\"}}";
462-
createIndex(indexName, basicSettings, mappings);
463-
464-
org.elasticsearch.action.admin.indices.get.GetIndexRequest getIndexRequest =
465-
new org.elasticsearch.action.admin.indices.get.GetIndexRequest().indices(indexName).includeDefaults(false);
466-
org.elasticsearch.action.admin.indices.get.GetIndexResponse getIndexResponse = execute(getIndexRequest,
467-
highLevelClient().indices()::get, highLevelClient().indices()::getAsync,
468-
expectWarnings(RestGetIndicesAction.TYPES_DEPRECATION_MESSAGE));
469-
470-
// default settings should be null
471-
assertNull(getIndexResponse.getSetting(indexName, "index.refresh_interval"));
472-
assertEquals("1", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_SHARDS));
473-
assertEquals("0", getIndexResponse.getSetting(indexName, SETTING_NUMBER_OF_REPLICAS));
474-
assertNotNull(getIndexResponse.getMappings().get(indexName));
475-
MappingMetaData mappingMetaData = getIndexResponse.getMappings().get(indexName).get("_doc");
476-
assertNotNull(mappingMetaData);
477-
assertEquals("_doc", mappingMetaData.type());
478-
assertEquals("{\"properties\":{\"field-1\":{\"type\":\"integer\"}}}", mappingMetaData.source().string());
479-
}
480-
481453
@SuppressWarnings("unchecked")
482454
public void testGetIndexWithDefaults() throws IOException {
483455
String indexName = "get_index_test";

client/rest-high-level/src/test/java/org/elasticsearch/client/IndicesRequestConvertersTests.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -288,50 +288,6 @@ public void testGetMapping() {
288288
Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod()));
289289
}
290290

291-
public void testGetMappingWithTypes() {
292-
org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest getMappingRequest =
293-
new org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest();
294-
295-
String[] indices = Strings.EMPTY_ARRAY;
296-
if (randomBoolean()) {
297-
indices = RequestConvertersTests.randomIndicesNames(0, 5);
298-
getMappingRequest.indices(indices);
299-
} else if (randomBoolean()) {
300-
getMappingRequest.indices((String[]) null);
301-
}
302-
303-
String type = null;
304-
if (randomBoolean()) {
305-
type = randomAlphaOfLengthBetween(3, 10);
306-
getMappingRequest.types(type);
307-
} else if (randomBoolean()) {
308-
getMappingRequest.types((String[]) null);
309-
}
310-
311-
Map<String, String> expectedParams = new HashMap<>();
312-
313-
RequestConvertersTests.setRandomIndicesOptions(getMappingRequest::indicesOptions,
314-
getMappingRequest::indicesOptions, expectedParams);
315-
RequestConvertersTests.setRandomMasterTimeout(getMappingRequest, expectedParams);
316-
RequestConvertersTests.setRandomLocal(getMappingRequest::local, expectedParams);
317-
expectedParams.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
318-
319-
Request request = IndicesRequestConverters.getMappings(getMappingRequest);
320-
StringJoiner endpoint = new StringJoiner("/", "/", "");
321-
String index = String.join(",", indices);
322-
if (Strings.hasLength(index)) {
323-
endpoint.add(index);
324-
}
325-
endpoint.add("_mapping");
326-
if (type != null) {
327-
endpoint.add(type);
328-
}
329-
Assert.assertThat(endpoint.toString(), equalTo(request.getEndpoint()));
330-
331-
Assert.assertThat(expectedParams, equalTo(request.getParameters()));
332-
Assert.assertThat(HttpGet.METHOD_NAME, equalTo(request.getMethod()));
333-
}
334-
335291
public void testGetFieldMapping() {
336292
GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest();
337293

0 commit comments

Comments
 (0)