Skip to content

Commit

Permalink
Merge commit '9f611dd' into stateless_threadpools
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Brooks committed Nov 16, 2023
2 parents f21519b + 9f611dd commit 9fa2df5
Show file tree
Hide file tree
Showing 173 changed files with 7,071 additions and 4,042 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchScrollRequest;
import org.elasticsearch.action.support.ActiveShardCount;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
Expand Down Expand Up @@ -241,7 +240,7 @@ static Request search(SearchRequest searchRequest, String searchEndpoint) throws
return request;
}

static void addSearchRequestParams(Params params, SearchRequest searchRequest) {
private static void addSearchRequestParams(Params params, SearchRequest searchRequest) {
params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true");
params.withRouting(searchRequest.routing());
params.withPreference(searchRequest.preference());
Expand All @@ -268,69 +267,44 @@ static void addSearchRequestParams(Params params, SearchRequest searchRequest) {
}
}

static Request searchScroll(SearchScrollRequest searchScrollRequest) throws IOException {
Request request = new Request(HttpPost.METHOD_NAME, "/_search/scroll");
request.setEntity(createEntity(searchScrollRequest, REQUEST_BODY_CONTENT_TYPE));
return request;
}

static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType) throws IOException {
return createEntity(toXContent, xContentType, ToXContent.EMPTY_PARAMS);
}

static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType, ToXContent.Params toXContentParams)
private static HttpEntity createEntity(ToXContent toXContent, XContentType xContentType, ToXContent.Params toXContentParams)
throws IOException {
BytesRef source = XContentHelper.toXContent(toXContent, xContentType, toXContentParams, false).toBytesRef();
return new NByteArrayEntity(source.bytes, source.offset, source.length, createContentType(xContentType));
}

@Deprecated
static String endpoint(String index, String type, String id) {
private static String endpoint(String index, String type, String id) {
return new EndpointBuilder().addPathPart(index, type, id).build();
}

static String endpoint(String index, String id) {
private static String endpoint(String index, String id) {
return new EndpointBuilder().addPathPart(index, "_doc", id).build();
}

@Deprecated
static String endpoint(String index, String type, String id, String endpoint) {
return new EndpointBuilder().addPathPart(index, type, id).addPathPartAsIs(endpoint).build();
}

static String endpoint(String[] indices, String endpoint) {
private static String endpoint(String[] indices, String endpoint) {
return new EndpointBuilder().addCommaSeparatedPathParts(indices).addPathPartAsIs(endpoint).build();
}

@Deprecated
static String endpoint(String[] indices, String[] types, String endpoint) {
return new EndpointBuilder().addCommaSeparatedPathParts(indices)
.addCommaSeparatedPathParts(types)
.addPathPartAsIs(endpoint)
.build();
}

@Deprecated
static String endpoint(String[] indices, String endpoint, String type) {
return new EndpointBuilder().addCommaSeparatedPathParts(indices).addPathPartAsIs(endpoint).addPathPart(type).build();
}

/**
* Returns a {@link ContentType} from a given {@link XContentType}.
*
* @param xContentType the {@link XContentType}
* @return the {@link ContentType}
*/
@SuppressForbidden(reason = "Only allowed place to convert a XContentType to a ContentType")
public static ContentType createContentType(final XContentType xContentType) {
private static ContentType createContentType(final XContentType xContentType) {
return ContentType.create(xContentType.mediaTypeWithoutParameters(), (Charset) null);
}

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

Params() {}
Expand Down Expand Up @@ -478,7 +452,7 @@ Params withIgnoreUnavailable(boolean ignoreUnavailable) {
*
* @return the {@link IndexRequest}'s content type
*/
static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable XContentType xContentType) {
private static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable XContentType xContentType) {
XContentType requestContentType = indexRequest.getContentType();
if (requestContentType.canonical() != XContentType.JSON && requestContentType.canonical() != XContentType.SMILE) {
throw new IllegalArgumentException(
Expand All @@ -505,7 +479,7 @@ static XContentType enforceSameContentType(IndexRequest indexRequest, @Nullable
/**
* Utility class to build request's endpoint given its parts as strings
*/
static class EndpointBuilder {
private static class EndpointBuilder {

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

Expand All @@ -532,7 +506,7 @@ EndpointBuilder addPathPartAsIs(String... parts) {
return this;
}

String build() {
private String build() {
return joiner.toString();
}

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

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

/**
* Creates a {@link RestHighLevelClient} given the low level {@link RestClientBuilder} that allows to build the
* {@link RestClient} to be used to perform requests.
*/
public RestHighLevelClient(RestClientBuilder restClientBuilder) {
this(restClientBuilder.build(), RestClient::close, Collections.emptyList());
}

/**
* Creates a {@link RestHighLevelClient} given the low level {@link RestClient} that it should use to perform requests and
* a list of entries that allow to parse custom response sections added to Elasticsearch through plugins.
Expand Down Expand Up @@ -331,23 +298,6 @@ public final IndexResponse index(IndexRequest indexRequest, RequestOptions optio
return performRequestAndParseEntity(indexRequest, RequestConverters::index, options, IndexResponse::fromXContent, emptySet());
}

/**
* Executes a search request using the Search API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
* @param searchRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
*/
public final SearchResponse search(SearchRequest searchRequest, RequestOptions options) throws IOException {
return performRequestAndParseEntity(
searchRequest,
r -> RequestConverters.search(r, "_search"),
options,
SearchResponse::fromXContent,
emptySet()
);
}

/**
* Asynchronously executes a search using the Search API.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Search API on elastic.co</a>
Expand All @@ -368,27 +318,7 @@ public final Cancellable searchAsync(SearchRequest searchRequest, RequestOptions
}

/**
* Executes a search using the Search Scroll API.
* See <a
* href="https://www.elastic.co/guide/en/elasticsearch/reference/master/search-request-body.html#request-body-search-scroll">Search
* Scroll API on elastic.co</a>
* @param searchScrollRequest the request
* @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized
* @return the response
*/
public final SearchResponse scroll(SearchScrollRequest searchScrollRequest, RequestOptions options) throws IOException {
return performRequestAndParseEntity(
searchScrollRequest,
RequestConverters::searchScroll,
options,
SearchResponse::fromXContent,
emptySet()
);
}

/**
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions. The Validation
* layer has been added to the ReST client, and requests should extend {@link Validatable} instead of {@link ActionRequest}.
* @deprecated If creating a new HLRC ReST API call, consider creating new actions instead of reusing server actions.
*/
@Deprecated
private <Req extends ActionRequest, Resp> Resp performRequestAndParseEntity(
Expand All @@ -402,8 +332,7 @@ private <Req extends ActionRequest, Resp> Resp performRequestAndParseEntity(
}

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

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

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

This file was deleted.

This file was deleted.

6 changes: 6 additions & 0 deletions docs/changelog/101826.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 101826
summary: Support keyed histograms
area: Aggregations
type: enhancement
issues:
- 100242
Loading

0 comments on commit 9fa2df5

Please sign in to comment.