Skip to content

Commit c8565fe

Browse files
Deprecate types in get field mapping API (elastic#37667)
- Add deprecation warning to RestGetFieldMappingAction - Add two new java HRLC classes GetFieldMappingsRequest and GetFieldMappingsResponse. These classes use new typeless forms of a request and response, and differ in that from the server versions. Relates to elastic#35190
1 parent f45b5fe commit c8565fe

File tree

13 files changed

+591
-33
lines changed

13 files changed

+591
-33
lines changed

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

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
3838
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
3939
import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
40-
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
41-
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse;
40+
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
41+
import org.elasticsearch.client.indices.GetFieldMappingsResponse;
4242
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
4343
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
4444
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
@@ -241,11 +241,16 @@ public void getMappingAsync(GetMappingsRequest getMappingsRequest, RequestOption
241241
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
242242
* @return the response
243243
* @throws IOException in case there is a problem sending the request or parsing back the response
244+
*
245+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The method
246+
* {@link #getFieldMapping(GetFieldMappingsRequest, RequestOptions)} should be used instead, which accepts a new request object.
244247
*/
245-
public GetFieldMappingsResponse getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest,
246-
RequestOptions options) throws IOException {
247-
return restHighLevelClient.performRequestAndParseEntity(getFieldMappingsRequest, IndicesRequestConverters::getFieldMapping, options,
248-
GetFieldMappingsResponse::fromXContent, emptySet());
248+
@Deprecated
249+
public org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse getFieldMapping(
250+
org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest getFieldMappingsRequest,
251+
RequestOptions options) throws IOException {
252+
return restHighLevelClient.performRequestAndParseEntity(getFieldMappingsRequest, IndicesRequestConverters::getFieldMapping,
253+
options, org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse::fromXContent, emptySet());
249254
}
250255

251256
/**
@@ -255,9 +260,45 @@ public GetFieldMappingsResponse getFieldMapping(GetFieldMappingsRequest getField
255260
* @param getFieldMappingsRequest the request
256261
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
257262
* @param listener the listener to be notified upon request completion
263+
*
264+
* @deprecated This method uses an old request object which still refers to types, a deprecated feature. The
265+
* method {@link #getFieldMappingAsync(GetFieldMappingsRequest, RequestOptions, ActionListener)} should be used instead,
266+
* which accepts a new request object.
267+
*/
268+
@Deprecated
269+
public void getFieldMappingAsync(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest getFieldMappingsRequest,
270+
RequestOptions options,
271+
ActionListener<org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse> listener) {
272+
restHighLevelClient.performRequestAsyncAndParseEntity(getFieldMappingsRequest, IndicesRequestConverters::getFieldMapping, options,
273+
org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse::fromXContent, listener, emptySet());
274+
}
275+
276+
/**
277+
* Retrieves the field mappings on an index or indices using the Get Field Mapping API.
278+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html">
279+
* Get Field Mapping API on elastic.co</a>
280+
* @param getFieldMappingsRequest the request
281+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
282+
* @return the response
283+
* @throws IOException in case there is a problem sending the request or parsing back the response
284+
*/
285+
public GetFieldMappingsResponse getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest,
286+
RequestOptions options) throws IOException {
287+
return restHighLevelClient.performRequestAndParseEntity(getFieldMappingsRequest, IndicesRequestConverters::getFieldMapping,
288+
options, GetFieldMappingsResponse::fromXContent, emptySet()
289+
);
290+
}
291+
292+
/**
293+
* Asynchronously retrieves the field mappings on an index or indices using the Get Field Mapping API.
294+
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html">
295+
* Get Field Mapping API on elastic.co</a>
296+
* @param getFieldMappingsRequest the request
297+
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
298+
* @param listener the listener to be notified upon request completion
258299
*/
259-
public void getFieldMappingAsync(GetFieldMappingsRequest getFieldMappingsRequest, RequestOptions options,
260-
ActionListener<GetFieldMappingsResponse> listener) {
300+
public void getFieldMappingAsync(GetFieldMappingsRequest getFieldMappingsRequest,
301+
RequestOptions options, ActionListener<GetFieldMappingsResponse> listener) {
261302
restHighLevelClient.performRequestAsyncAndParseEntity(getFieldMappingsRequest, IndicesRequestConverters::getFieldMapping, options,
262303
GetFieldMappingsResponse::fromXContent, listener, emptySet());
263304
}

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.elasticsearch.action.admin.indices.flush.SyncedFlushRequest;
3636
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
3737
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
38-
import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest;
38+
import org.elasticsearch.client.indices.GetFieldMappingsRequest;
3939
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
4040
import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
4141
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
@@ -165,7 +165,28 @@ static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOExcep
165165
return request;
166166
}
167167

168-
static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest) throws IOException {
168+
static Request getFieldMapping(GetFieldMappingsRequest getFieldMappingsRequest) {
169+
String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
170+
String[] fields = getFieldMappingsRequest.fields() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.fields();
171+
172+
String endpoint = new RequestConverters.EndpointBuilder()
173+
.addCommaSeparatedPathParts(indices)
174+
.addPathPartAsIs("_mapping")
175+
.addPathPartAsIs("field")
176+
.addCommaSeparatedPathParts(fields)
177+
.build();
178+
179+
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
180+
181+
RequestConverters.Params parameters = new RequestConverters.Params(request);
182+
parameters.withIndicesOptions(getFieldMappingsRequest.indicesOptions());
183+
parameters.withIncludeDefaults(getFieldMappingsRequest.includeDefaults());
184+
parameters.withLocal(getFieldMappingsRequest.local());
185+
186+
return request;
187+
}
188+
189+
static Request getFieldMapping(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest getFieldMappingsRequest) {
169190
String[] indices = getFieldMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.indices();
170191
String[] types = getFieldMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.types();
171192
String[] fields = getFieldMappingsRequest.fields() == null ? Strings.EMPTY_ARRAY : getFieldMappingsRequest.fields();
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.client.indices;
21+
22+
import org.elasticsearch.action.support.IndicesOptions;
23+
import org.elasticsearch.client.Validatable;
24+
import org.elasticsearch.common.Strings;
25+
26+
/** Request the mappings of specific fields */
27+
public class GetFieldMappingsRequest implements Validatable {
28+
29+
private boolean local = false;
30+
31+
private String[] fields = Strings.EMPTY_ARRAY;
32+
33+
private boolean includeDefaults = false;
34+
35+
private String[] indices = Strings.EMPTY_ARRAY;
36+
37+
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
38+
39+
/**
40+
* Indicate whether the receiving node should operate based on local index information or forward requests,
41+
* where needed, to other nodes. If running locally, request will not raise errors if running locally &amp; missing indices.
42+
*/
43+
public GetFieldMappingsRequest local(boolean local) {
44+
this.local = local;
45+
return this;
46+
}
47+
48+
public boolean local() {
49+
return local;
50+
}
51+
52+
public GetFieldMappingsRequest indices(String... indices) {
53+
this.indices = indices;
54+
return this;
55+
}
56+
57+
public GetFieldMappingsRequest indicesOptions(IndicesOptions indicesOptions) {
58+
this.indicesOptions = indicesOptions;
59+
return this;
60+
}
61+
62+
public String[] indices() {
63+
return indices;
64+
}
65+
66+
public IndicesOptions indicesOptions() {
67+
return indicesOptions;
68+
}
69+
70+
/** @param fields a list of fields to retrieve the mapping for */
71+
public GetFieldMappingsRequest fields(String... fields) {
72+
this.fields = fields;
73+
return this;
74+
}
75+
76+
public String[] fields() {
77+
return fields;
78+
}
79+
80+
public boolean includeDefaults() {
81+
return includeDefaults;
82+
}
83+
84+
/** Indicates whether default mapping settings should be returned */
85+
public GetFieldMappingsRequest includeDefaults(boolean includeDefaults) {
86+
this.includeDefaults = includeDefaults;
87+
return this;
88+
}
89+
90+
}

0 commit comments

Comments
 (0)