Skip to content

Commit 29aa74b

Browse files
authored
More miscellaneous tidying towards removing the HLRC (#102175)
1 parent 59b730d commit 29aa74b

File tree

4 files changed

+16
-228
lines changed

4 files changed

+16
-228
lines changed

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

+11-37
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.action.bulk.BulkRequest;
1919
import org.elasticsearch.action.index.IndexRequest;
2020
import org.elasticsearch.action.search.SearchRequest;
21-
import org.elasticsearch.action.search.SearchScrollRequest;
2221
import org.elasticsearch.action.support.ActiveShardCount;
2322
import org.elasticsearch.action.support.IndicesOptions;
2423
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
@@ -241,7 +240,7 @@ static Request search(SearchRequest searchRequest, String searchEndpoint) throws
241240
return request;
242241
}
243242

244-
static void addSearchRequestParams(Params params, SearchRequest searchRequest) {
243+
private static void addSearchRequestParams(Params params, SearchRequest searchRequest) {
245244
params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true");
246245
params.withRouting(searchRequest.routing());
247246
params.withPreference(searchRequest.preference());
@@ -268,69 +267,44 @@ static void addSearchRequestParams(Params params, SearchRequest searchRequest) {
268267
}
269268
}
270269

271-
static Request searchScroll(SearchScrollRequest searchScrollRequest) throws IOException {
272-
Request request = new Request(HttpPost.METHOD_NAME, "/_search/scroll");
273-
request.setEntity(createEntity(searchScrollRequest, REQUEST_BODY_CONTENT_TYPE));
274-
return request;
275-
}
276-
277-
static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
270+
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
278271
return createEntity(toXContent, xContentType, ToXContent.EMPTY_PARAMS);
279272
}
280273

281-
static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType, ToXContent.Params toXContentParams)
274+
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType, ToXContent.Params toXContentParams)
282275
throws IOException {
283276
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, toXContentParams, false).toBytesRef();
284277
return new NByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));
285278
}
286279

287-
@Deprecated
288-
static String endpoint(String index, String type, String id) {
280+
private static String endpoint(String index, String type, String id) {
289281
return new EndpointBuilder().addPathPart(index, type, id).build();
290282
}
291283

292-
static String endpoint(String index, String id) {
284+
private static String endpoint(String index, String id) {
293285
return new EndpointBuilder().addPathPart(index, "_doc", id).build();
294286
}
295287

296-
@Deprecated
297-
static String endpoint(String index, String type, String id, String endpoint) {
298-
return new EndpointBuilder().addPathPart(index, type, id).addPathPartAsIs(endpoint).build();
299-
}
300-
301-
static String endpoint(String[] indices, String endpoint) {
288+
private static String endpoint(String[] indices, String endpoint) {
302289
return new EndpointBuilder().addCommaSeparatedPathParts(indices).addPathPartAsIs(endpoint).build();
303290
}
304291

305-
@Deprecated
306-
static String endpoint(String[] indices, String[] types, String endpoint) {
307-
return new EndpointBuilder().addCommaSeparatedPathParts(indices)
308-
.addCommaSeparatedPathParts(types)
309-
.addPathPartAsIs(endpoint)
310-
.build();
311-
}
312-
313-
@Deprecated
314-
static String endpoint(String[] indices, String endpoint, String type) {
315-
return new EndpointBuilder().addCommaSeparatedPathParts(indices).addPathPartAsIs(endpoint).addPathPart(type).build();
316-
}
317-
318292
/**
319293
* Returns a {@link ContentType} from a given {@link XContentType}.
320294
*
321295
* @param xContentType the {@link XContentType}
322296
* @return the {@link ContentType}
323297
*/
324298
@SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType")
325-
public static ContentType createContentType(final XContentType xContentType) {
299+
private static ContentType createContentType(final XContentType xContentType) {
326300
return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null);
327301
}
328302

329303
/**
330304
* Utility class to help with common parameter names and patterns. Wraps
331305
* a {@link Request} and adds the parameters to it directly.
332306
*/
333-
static class Params {
307+
private static class Params {
334308
private final Map<String, String> parameters = new HashMap<>();
335309

336310
Params() {}
@@ -478,7 +452,7 @@ Params withIgnoreUnavailable(boolean ignoreUnavailable) {
478452
*
479453
* @return the {@link IndexRequest}'s content type
480454
*/
481-
static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable XContentType xContentType) {
455+
private static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable XContentType xContentType) {
482456
XContentType requestContentType = indexRequest.getContentType();
483457
if (requestContentType.canonical() != XContentType.JSON && requestContentType.canonical() != XContentType.SMILE) {
484458
throw new IllegalArgumentException(
@@ -505,7 +479,7 @@ static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable
505479
/**
506480
* Utility class to build request's endpoint given its parts as strings
507481
*/
508-
static class EndpointBuilder {
482+
private static class EndpointBuilder {
509483

510484
private final StringJoiner joiner = new StringJoiner("/", "/", "");
511485

@@ -532,7 +506,7 @@ EndpointBuilder addPathPartAsIs(String... parts) {
532506
return this;
533507
}
534508

535-
String build() {
509+
private String build() {
536510
return joiner.toString();
537511
}
538512

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

+5-78
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.action.index.IndexResponse;
2424
import org.elasticsearch.action.search.SearchRequest;
2525
import org.elasticsearch.action.search.SearchResponse;
26-
import org.elasticsearch.action.search.SearchScrollRequest;
2726
import org.elasticsearch.action.support.PlainActionFuture;
2827
import org.elasticsearch.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder;
2928
import org.elasticsearch.aggregations.bucket.adjacency.ParsedAdjacencyMatrix;
@@ -159,7 +158,6 @@
159158
import java.io.Closeable;
160159
import java.io.IOException;
161160
import java.util.ArrayList;
162-
import java.util.Collections;
163161
import java.util.HashMap;
164162
import java.util.List;
165163
import java.util.Map;
@@ -180,29 +178,6 @@
180178
* High level REST client that wraps an instance of the low level {@link RestClient} and allows to build requests and read responses. The
181179
* {@link RestClient} instance is internally built based on the provided {@link RestClientBuilder} and it gets closed automatically when
182180
* closing the {@link RestHighLevelClient} instance that wraps it.
183-
* <p>
184-
*
185-
* In case an already existing instance of a low-level REST client needs to be provided, this class can be subclassed and the
186-
* {@link #RestHighLevelClient(RestClient, CheckedConsumer, List)} constructor can be used.
187-
* <p>
188-
*
189-
* This class can also be sub-classed to expose additional client methods that make use of endpoints added to Elasticsearch through plugins,
190-
* or to add support for custom response sections, again added to Elasticsearch through plugins.
191-
* <p>
192-
*
193-
* The majority of the methods in this class come in two flavors, a blocking and an asynchronous version (e.g.
194-
* {@link #search(SearchRequest, RequestOptions)} and {@link #searchAsync(SearchRequest, RequestOptions, ActionListener)}, where the later
195-
* takes an implementation of an {@link ActionListener} as an argument that needs to implement methods that handle successful responses and
196-
* failure scenarios. Most of the blocking calls can throw an {@link IOException} or an unchecked {@link ElasticsearchException} in the
197-
* following cases:
198-
*
199-
* <ul>
200-
* <li>an {@link IOException} is usually thrown in case of failing to parse the REST response in the high-level REST client, the request
201-
* times out or similar cases where there is no response coming back from the Elasticsearch server</li>
202-
* <li>an {@link ElasticsearchException} is usually thrown in case where the server returns a 4xx or 5xx error code. The high-level client
203-
* then tries to parse the response body error details into a generic ElasticsearchException and suppresses the original
204-
* {@link ResponseException}</li>
205-
* </ul>
206181
*
207182
* @deprecated The High Level Rest Client is deprecated in favor of the
208183
* <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/introduction.html">
@@ -216,7 +191,7 @@ public class RestHighLevelClient implements Closeable {
216191
/**
217192
* Environment variable determining whether to send the 7.x compatibility header
218193
*/
219-
public static final String API_VERSIONING_ENV_VARIABLE = "ELASTIC_CLIENT_APIVERSIONING";
194+
private static final String API_VERSIONING_ENV_VARIABLE = "ELASTIC_CLIENT_APIVERSIONING";
220195

221196
// To be called using performClientRequest and performClientRequestAsync to ensure version compatibility check
222197
private final RestClient client;
@@ -227,14 +202,6 @@ public class RestHighLevelClient implements Closeable {
227202
/** Do not access directly but through getVersionValidationFuture() */
228203
private volatile ListenableFuture<Optional<String>> versionValidationFuture;
229204

230-
/**
231-
* Creates a {@link RestHighLevelClient} given the low level {@link RestClientBuilder} that allows to build the
232-
* {@link RestClient} to be used to perform requests.
233-
*/
234-
public RestHighLevelClient(RestClientBuilder restClientBuilder) {
235-
this(restClientBuilder.build(), RestClient::close, Collections.emptyList());
236-
}
237-
238205
/**
239206
* Creates a {@link RestHighLevelClient} given the low level {@link RestClient} that it should use to perform requests and
240207
* a list of entries that allow to parse custom response sections added to Elasticsearch through plugins.
@@ -331,23 +298,6 @@ public final IndexResponse index(IndexRequest indexRequest, RequestOptions optio
331298
return performRequestAndParseEntity(indexRequest, RequestConverters::index, options, IndexResponse::fromXContent, emptySet());
332299
}
333300

334-
/**
335-
* Executes a search request using the Search API.
336-
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
337-
* @param searchRequest the request
338-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
339-
* @return the response
340-
*/
341-
public final SearchResponse search(SearchRequest searchRequest, RequestOptions options) throws IOException {
342-
return performRequestAndParseEntity(
343-
searchRequest,
344-
r -> RequestConverters.search(r, "_search"),
345-
options,
346-
SearchResponse::fromXContent,
347-
emptySet()
348-
);
349-
}
350-
351301
/**
352302
* Asynchronously executes a search using the Search API.
353303
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
@@ -368,27 +318,7 @@ public final Cancellable searchAsync(SearchRequest searchRequest, RequestOptions
368318
}
369319

370320
/**
371-
* Executes a search using the Search Scroll API.
372-
* See <a
373-
* href="https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-body.html#request-body-search-scroll">Search
374-
* Scroll API on elastic.co</a>
375-
* @param searchScrollRequest the request
376-
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
377-
* @return the response
378-
*/
379-
public final SearchResponse scroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
380-
return performRequestAndParseEntity(
381-
searchScrollRequest,
382-
RequestConverters::searchScroll,
383-
options,
384-
SearchResponse::fromXContent,
385-
emptySet()
386-
);
387-
}
388-
389-
/**
390-
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
391-
* layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
321+
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions.
392322
*/
393323
@Deprecated
394324
private <Req extends ActionRequest, Resp> Resp performRequestAndParseEntity(
@@ -402,8 +332,7 @@ private <Req extends ActionRequest, Resp> Resp performRequestAndParseEntity(
402332
}
403333

404334
/**
405-
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
406-
* layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
335+
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions.
407336
*/
408337
@Deprecated
409338
private <Req extends ActionRequest, Resp> Resp performRequest(
@@ -458,8 +387,7 @@ private <Req, Resp> Resp internalPerformRequest(
458387
}
459388

460389
/**
461-
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
462-
* layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
390+
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions.
463391
* @return Cancellable instance that may be used to cancel the request
464392
*/
465393
@Deprecated
@@ -482,8 +410,7 @@ private <Req extends ActionRequest, Resp> Cancellable performRequestAsyncAndPars
482410
}
483411

484412
/**
485-
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
486-
* layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
413+
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions.
487414
* @return Cancellable instance that may be used to cancel the request
488415
*/
489416
@Deprecated

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

-30
This file was deleted.

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

-83
This file was deleted.

0 commit comments

Comments
 (0)