[PURIFY] remove all trace of x-pack async-search (#10)
This commit removes all trace of Elastic licensed asyc-search Signed-off-by: Peter Nied <petern@amazon.com>
This commit is contained in:
parent
204122aae4
commit
479dd4b42a
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.client.asyncsearch.AsyncSearchResponse;
|
||||
import org.elasticsearch.client.asyncsearch.DeleteAsyncSearchRequest;
|
||||
import org.elasticsearch.client.asyncsearch.GetAsyncSearchRequest;
|
||||
import org.elasticsearch.client.asyncsearch.SubmitAsyncSearchRequest;
|
||||
import org.elasticsearch.client.core.AcknowledgedResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.util.Collections.emptySet;
|
||||
|
||||
public class AsyncSearchClient {
|
||||
private final RestHighLevelClient restHighLevelClient;
|
||||
|
||||
AsyncSearchClient(RestHighLevelClient restHighLevelClient) {
|
||||
this.restHighLevelClient = restHighLevelClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit a new async search request.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html"> the docs</a> for more.
|
||||
* @param request 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
|
||||
*/
|
||||
public AsyncSearchResponse submit(SubmitAsyncSearchRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, AsyncSearchRequestConverters::submitAsyncSearch, options,
|
||||
AsyncSearchResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously submit a new async search request.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html"> the docs</a> for more.
|
||||
* <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-ilm-ilm-get-lifecycle-policy.html">
|
||||
* the docs</a> for more.
|
||||
* @param request 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
|
||||
* @return cancellable that may be used to cancel the request
|
||||
*/
|
||||
public Cancellable submitAsync(SubmitAsyncSearchRequest request, RequestOptions options,
|
||||
ActionListener<AsyncSearchResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, AsyncSearchRequestConverters::submitAsyncSearch, options,
|
||||
AsyncSearchResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an async search request.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html"> the docs</a> for more.
|
||||
*
|
||||
*/
|
||||
public AsyncSearchResponse get(GetAsyncSearchRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, AsyncSearchRequestConverters::getAsyncSearch, options,
|
||||
AsyncSearchResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously get an async search request.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html"> the docs</a> for more.
|
||||
* @param request 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
|
||||
* @return cancellable that may be used to cancel the request
|
||||
*/
|
||||
public Cancellable getAsync(GetAsyncSearchRequest request, RequestOptions options,
|
||||
ActionListener<AsyncSearchResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, AsyncSearchRequestConverters::getAsyncSearch, options,
|
||||
AsyncSearchResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an async search request.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html"> the docs</a> for more.
|
||||
* @param request 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
|
||||
*/
|
||||
public AcknowledgedResponse delete(DeleteAsyncSearchRequest request, RequestOptions options) throws IOException {
|
||||
return restHighLevelClient.performRequestAndParseEntity(request, AsyncSearchRequestConverters::deleteAsyncSearch, options,
|
||||
AcknowledgedResponse::fromXContent, emptySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronously delete an async search request.
|
||||
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html"> the docs</a> for more.
|
||||
* @param request 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
|
||||
* @return cancellable that may be used to cancel the request
|
||||
*/
|
||||
public Cancellable deleteAsync(DeleteAsyncSearchRequest request, RequestOptions options,
|
||||
ActionListener<AcknowledgedResponse> listener) {
|
||||
return restHighLevelClient.performRequestAsyncAndParseEntity(request, AsyncSearchRequestConverters::deleteAsyncSearch, options,
|
||||
AcknowledgedResponse::fromXContent, listener, emptySet());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.elasticsearch.client.RequestConverters.Params;
|
||||
import org.elasticsearch.client.asyncsearch.DeleteAsyncSearchRequest;
|
||||
import org.elasticsearch.client.asyncsearch.GetAsyncSearchRequest;
|
||||
import org.elasticsearch.client.asyncsearch.SubmitAsyncSearchRequest;
|
||||
import org.elasticsearch.rest.action.search.RestSearchAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.client.RequestConverters.REQUEST_BODY_CONTENT_TYPE;
|
||||
|
||||
final class AsyncSearchRequestConverters {
|
||||
|
||||
static Request submitAsyncSearch(SubmitAsyncSearchRequest asyncSearchRequest) throws IOException {
|
||||
String endpoint = new RequestConverters.EndpointBuilder().addCommaSeparatedPathParts(
|
||||
asyncSearchRequest.getIndices())
|
||||
.addPathPartAsIs("_async_search").build();
|
||||
Request request = new Request(HttpPost.METHOD_NAME, endpoint);
|
||||
Params params = new RequestConverters.Params();
|
||||
// add all typical search params and search request source as body
|
||||
addSearchRequestParams(params, asyncSearchRequest);
|
||||
if (asyncSearchRequest.getSearchSource() != null) {
|
||||
request.setEntity(RequestConverters.createEntity(asyncSearchRequest.getSearchSource(), REQUEST_BODY_CONTENT_TYPE));
|
||||
}
|
||||
// set async search submit specific parameters
|
||||
if (asyncSearchRequest.isKeepOnCompletion() != null) {
|
||||
params.putParam("keep_on_completion", asyncSearchRequest.isKeepOnCompletion().toString());
|
||||
}
|
||||
if (asyncSearchRequest.getKeepAlive() != null) {
|
||||
params.putParam("keep_alive", asyncSearchRequest.getKeepAlive().getStringRep());
|
||||
}
|
||||
if (asyncSearchRequest.getWaitForCompletionTimeout() != null) {
|
||||
params.putParam("wait_for_completion_timeout", asyncSearchRequest.getWaitForCompletionTimeout().getStringRep());
|
||||
}
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static void addSearchRequestParams(Params params, SubmitAsyncSearchRequest request) {
|
||||
params.putParam(RestSearchAction.TYPED_KEYS_PARAM, "true");
|
||||
params.withRouting(request.getRouting());
|
||||
params.withPreference(request.getPreference());
|
||||
params.withIndicesOptions(request.getIndicesOptions());
|
||||
params.withSearchType(request.getSearchType().name().toLowerCase(Locale.ROOT));
|
||||
params.withMaxConcurrentShardRequests(request.getMaxConcurrentShardRequests());
|
||||
if (request.getRequestCache() != null) {
|
||||
params.withRequestCache(request.getRequestCache());
|
||||
}
|
||||
if (request.getAllowPartialSearchResults() != null) {
|
||||
params.withAllowPartialResults(request.getAllowPartialSearchResults());
|
||||
}
|
||||
if (request.getBatchedReduceSize() != null) {
|
||||
params.withBatchedReduceSize(request.getBatchedReduceSize());
|
||||
}
|
||||
}
|
||||
|
||||
static Request getAsyncSearch(GetAsyncSearchRequest asyncSearchRequest) {
|
||||
String endpoint = new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_async_search")
|
||||
.addPathPart(asyncSearchRequest.getId())
|
||||
.build();
|
||||
Request request = new Request(HttpGet.METHOD_NAME, endpoint);
|
||||
Params params = new RequestConverters.Params();
|
||||
if (asyncSearchRequest.getKeepAlive() != null) {
|
||||
params.putParam("keep_alive", asyncSearchRequest.getKeepAlive().getStringRep());
|
||||
}
|
||||
if (asyncSearchRequest.getWaitForCompletion() != null) {
|
||||
params.putParam("wait_for_completion_timeout", asyncSearchRequest.getWaitForCompletion().getStringRep());
|
||||
}
|
||||
request.addParameters(params.asMap());
|
||||
return request;
|
||||
}
|
||||
|
||||
static Request deleteAsyncSearch(DeleteAsyncSearchRequest deleteAsyncSearchRequest) {
|
||||
String endpoint = new RequestConverters.EndpointBuilder()
|
||||
.addPathPartAsIs("_async_search")
|
||||
.addPathPart(deleteAsyncSearchRequest.getId())
|
||||
.build();
|
||||
return new Request(HttpDelete.METHOD_NAME, endpoint);
|
||||
}
|
||||
}
|
|
@ -271,7 +271,6 @@ public class RestHighLevelClient implements Closeable {
|
|||
private final RollupClient rollupClient = new RollupClient(this);
|
||||
private final CcrClient ccrClient = new CcrClient(this);
|
||||
private final TransformClient transformClient = new TransformClient(this);
|
||||
private final AsyncSearchClient asyncSearchClient = new AsyncSearchClient(this);
|
||||
|
||||
/**
|
||||
* Creates a {@link RestHighLevelClient} given the low level {@link RestClientBuilder} that allows to build the
|
||||
|
@ -442,16 +441,6 @@ public class RestHighLevelClient implements Closeable {
|
|||
return ilmClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper for the {@link RestHighLevelClient} that provides methods for accessing the Elastic Index Async Search APIs.
|
||||
* <p>
|
||||
* See the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/async-search.html"> X-Pack APIs on elastic.co</a>
|
||||
* for more information.
|
||||
*/
|
||||
public AsyncSearchClient asyncSearch() {
|
||||
return asyncSearchClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides methods for accessing the Elastic Licensed Migration APIs that
|
||||
* are shipped with the default distribution of Elasticsearch. All of
|
||||
|
|
|
@ -1,200 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.client.asyncsearch;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentParser.Token;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg;
|
||||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
||||
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
|
||||
|
||||
/**
|
||||
* A response of an async search request.
|
||||
*/
|
||||
public class AsyncSearchResponse implements ToXContentObject {
|
||||
@Nullable
|
||||
private final String id;
|
||||
@Nullable
|
||||
private final SearchResponse searchResponse;
|
||||
@Nullable
|
||||
private final ElasticsearchException error;
|
||||
private final boolean isRunning;
|
||||
private final boolean isPartial;
|
||||
|
||||
private final long startTimeMillis;
|
||||
private final long expirationTimeMillis;
|
||||
|
||||
/**
|
||||
* Creates an {@link AsyncSearchResponse} with the arguments that are always present in the server response
|
||||
*/
|
||||
AsyncSearchResponse(boolean isPartial,
|
||||
boolean isRunning,
|
||||
long startTimeMillis,
|
||||
long expirationTimeMillis,
|
||||
@Nullable String id,
|
||||
@Nullable SearchResponse searchResponse,
|
||||
@Nullable ElasticsearchException error) {
|
||||
this.isPartial = isPartial;
|
||||
this.isRunning = isRunning;
|
||||
this.startTimeMillis = startTimeMillis;
|
||||
this.expirationTimeMillis = expirationTimeMillis;
|
||||
this.id = id;
|
||||
this.searchResponse = searchResponse;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the async search request or null if the response is not stored in the cluster.
|
||||
*/
|
||||
@Nullable
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current {@link SearchResponse} or <code>null</code> if not available.
|
||||
*
|
||||
* See {@link #isPartial()} to determine whether the response contains partial or complete
|
||||
* results.
|
||||
*/
|
||||
public SearchResponse getSearchResponse() {
|
||||
return searchResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the failure reason or null if the query is running or has completed normally.
|
||||
*/
|
||||
public ElasticsearchException getFailure() {
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the {@link SearchResponse} contains partial
|
||||
* results computed from a subset of the total shards.
|
||||
*/
|
||||
public boolean isPartial() {
|
||||
return isPartial;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the search is still running in the cluster.
|
||||
*
|
||||
* A value of <code>false</code> indicates that the response is final
|
||||
* even if {@link #isPartial()} returns <code>true</code>. In such case,
|
||||
* the partial response represents the status of the search before a
|
||||
* non-recoverable failure.
|
||||
*/
|
||||
public boolean isRunning() {
|
||||
return isRunning;
|
||||
}
|
||||
|
||||
/**
|
||||
* When this response was created as a timestamp in milliseconds since epoch.
|
||||
*/
|
||||
public long getStartTime() {
|
||||
return startTimeMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* When this response will expired as a timestamp in milliseconds since epoch.
|
||||
*/
|
||||
public long getExpirationTime() {
|
||||
return expirationTimeMillis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
if (id != null) {
|
||||
builder.field("id", id);
|
||||
}
|
||||
builder.field("is_partial", isPartial);
|
||||
builder.field("is_running", isRunning);
|
||||
builder.field("start_time_in_millis", startTimeMillis);
|
||||
builder.field("expiration_time_in_millis", expirationTimeMillis);
|
||||
|
||||
if (searchResponse != null) {
|
||||
builder.field("response");
|
||||
searchResponse.toXContent(builder, params);
|
||||
}
|
||||
if (error != null) {
|
||||
builder.startObject("error");
|
||||
error.toXContent(builder, params);
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static final ParseField ID_FIELD = new ParseField("id");
|
||||
public static final ParseField IS_PARTIAL_FIELD = new ParseField("is_partial");
|
||||
public static final ParseField IS_RUNNING_FIELD = new ParseField("is_running");
|
||||
public static final ParseField START_TIME_FIELD = new ParseField("start_time_in_millis");
|
||||
public static final ParseField EXPIRATION_FIELD = new ParseField("expiration_time_in_millis");
|
||||
public static final ParseField RESPONSE_FIELD = new ParseField("response");
|
||||
public static final ParseField ERROR_FIELD = new ParseField("error");
|
||||
|
||||
public static final ConstructingObjectParser<AsyncSearchResponse, Void> PARSER = new ConstructingObjectParser<>(
|
||||
"submit_async_search_response", true,
|
||||
args -> new AsyncSearchResponse(
|
||||
(boolean) args[0],
|
||||
(boolean) args[1],
|
||||
(long) args[2],
|
||||
(long) args[3],
|
||||
(String) args[4],
|
||||
(SearchResponse) args[5],
|
||||
(ElasticsearchException) args[6]));
|
||||
static {
|
||||
PARSER.declareBoolean(constructorArg(), IS_PARTIAL_FIELD);
|
||||
PARSER.declareBoolean(constructorArg(), IS_RUNNING_FIELD);
|
||||
PARSER.declareLong(constructorArg(), START_TIME_FIELD);
|
||||
PARSER.declareLong(constructorArg(), EXPIRATION_FIELD);
|
||||
PARSER.declareString(optionalConstructorArg(), ID_FIELD);
|
||||
PARSER.declareObject(optionalConstructorArg(), (p, c) -> AsyncSearchResponse.parseSearchResponse(p),
|
||||
RESPONSE_FIELD);
|
||||
PARSER.declareObject(optionalConstructorArg(), (p, c) -> ElasticsearchException.fromXContent(p), ERROR_FIELD);
|
||||
}
|
||||
|
||||
private static SearchResponse parseSearchResponse(XContentParser p) throws IOException {
|
||||
// we should be before the opening START_OBJECT of the response
|
||||
ensureExpectedToken(Token.START_OBJECT, p.currentToken(), p);
|
||||
p.nextToken();
|
||||
return SearchResponse.innerFromXContent(p);
|
||||
}
|
||||
|
||||
public static AsyncSearchResponse fromXContent(XContentParser parser) {
|
||||
return PARSER.apply(parser, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Strings.toString(this);
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.elasticsearch.client.asyncsearch;
|
||||
|
||||
import org.elasticsearch.client.Validatable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DeleteAsyncSearchRequest implements Validatable {
|
||||
|
||||
private final String id;
|
||||
|
||||
public DeleteAsyncSearchRequest(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DeleteAsyncSearchRequest request = (DeleteAsyncSearchRequest) o;
|
||||
return Objects.equals(getId(), request.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getId());
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.elasticsearch.client.asyncsearch;
|
||||
|
||||
import org.elasticsearch.client.Validatable;
|
||||
import org.elasticsearch.client.ValidationException;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public class GetAsyncSearchRequest implements Validatable {
|
||||
|
||||
private TimeValue waitForCompletion;
|
||||
private TimeValue keepAlive;
|
||||
|
||||
private final String id;
|
||||
|
||||
public GetAsyncSearchRequest(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public TimeValue getWaitForCompletion() {
|
||||
return waitForCompletion;
|
||||
}
|
||||
|
||||
public void setWaitForCompletion(TimeValue waitForCompletion) {
|
||||
this.waitForCompletion = waitForCompletion;
|
||||
}
|
||||
|
||||
public TimeValue getKeepAlive() {
|
||||
return keepAlive;
|
||||
}
|
||||
|
||||
public void setKeepAlive(TimeValue keepAlive) {
|
||||
this.keepAlive = keepAlive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ValidationException> validate() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
GetAsyncSearchRequest request = (GetAsyncSearchRequest) o;
|
||||
return Objects.equals(getId(), request.getId())
|
||||
&& Objects.equals(getKeepAlive(), request.getKeepAlive())
|
||||
&& Objects.equals(getWaitForCompletion(), request.getWaitForCompletion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getId(), getKeepAlive(), getWaitForCompletion());
|
||||
}
|
||||
}
|
|
@ -1,278 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.elasticsearch.client.asyncsearch;
|
||||
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.Validatable;
|
||||
import org.elasticsearch.client.ValidationException;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* A request to track asynchronously the progress of a search against one or more indices.
|
||||
*/
|
||||
public class SubmitAsyncSearchRequest implements Validatable {
|
||||
|
||||
public static long MIN_KEEP_ALIVE = TimeValue.timeValueMinutes(1).millis();
|
||||
|
||||
private TimeValue waitForCompletionTimeout;
|
||||
private Boolean keepOnCompletion;
|
||||
private TimeValue keepAlive;
|
||||
private final SearchRequest searchRequest;
|
||||
// The following is optional and will only be sent down with the request if explicitely set by the user
|
||||
private Integer batchedReduceSize;
|
||||
|
||||
/**
|
||||
* Creates a new request
|
||||
*/
|
||||
public SubmitAsyncSearchRequest(SearchSourceBuilder source, String... indices) {
|
||||
this.searchRequest = new SearchRequest(indices, source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the target indices
|
||||
*/
|
||||
public String[] getIndices() {
|
||||
return this.searchRequest.indices();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the minimum time that the request should wait before returning a partial result (defaults to 1 second).
|
||||
*/
|
||||
public TimeValue getWaitForCompletionTimeout() {
|
||||
return waitForCompletionTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum time that the request should wait before returning a partial result (defaults to 1 second).
|
||||
*/
|
||||
public void setWaitForCompletionTimeout(TimeValue waitForCompletionTimeout) {
|
||||
this.waitForCompletionTimeout = waitForCompletionTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the resource resource should be kept on completion or failure (defaults to false).
|
||||
*/
|
||||
public Boolean isKeepOnCompletion() {
|
||||
return keepOnCompletion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the resource should be kept on completion or failure (defaults to false).
|
||||
*/
|
||||
public void setKeepOnCompletion(boolean keepOnCompletion) {
|
||||
this.keepOnCompletion = keepOnCompletion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of time after which the result will expire (defaults to 5 days).
|
||||
*/
|
||||
public TimeValue getKeepAlive() {
|
||||
return keepAlive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount of time after which the result will expire (defaults to 5 days).
|
||||
*/
|
||||
public void setKeepAlive(TimeValue keepAlive) {
|
||||
this.keepAlive = keepAlive;
|
||||
}
|
||||
|
||||
// setters for request parameters of the wrapped SearchRequest
|
||||
/**
|
||||
* Set the routing value to control the shards that the search will be executed on.
|
||||
* A comma separated list of routing values to control the shards the search will be executed on.
|
||||
*/
|
||||
public void setRouting(String routing) {
|
||||
this.searchRequest.routing(routing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the routing values to control the shards that the search will be executed on.
|
||||
*/
|
||||
public void setRoutings(String... routings) {
|
||||
this.searchRequest.routing(routings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the routing value to control the shards that the search will be executed on.
|
||||
*/
|
||||
public String getRouting() {
|
||||
return this.searchRequest.routing();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the preference to execute the search. Defaults to randomize across shards. Can be set to
|
||||
* {@code _local} to prefer local shards or a custom value, which guarantees that the same order
|
||||
* will be used across different requests.
|
||||
*/
|
||||
public void setPreference(String preference) {
|
||||
this.searchRequest.preference(preference);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the preference to execute the search.
|
||||
*/
|
||||
public String getPreference() {
|
||||
return this.searchRequest.preference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies what type of requested indices to ignore and how to deal with indices wildcard expressions.
|
||||
*/
|
||||
public void setIndicesOptions(IndicesOptions indicesOptions) {
|
||||
this.searchRequest.indicesOptions(indicesOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the indices Options.
|
||||
*/
|
||||
public IndicesOptions getIndicesOptions() {
|
||||
return this.searchRequest.indicesOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* The search type to execute, defaults to {@link SearchType#DEFAULT}.
|
||||
*/
|
||||
public void setSearchType(SearchType searchType) {
|
||||
this.searchRequest.searchType(searchType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the search type to execute, defaults to {@link SearchType#DEFAULT}.
|
||||
*/
|
||||
public SearchType getSearchType() {
|
||||
return this.searchRequest.searchType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if this request should allow partial results. (If method is not called,
|
||||
* will default to the cluster level setting).
|
||||
*/
|
||||
public void setAllowPartialSearchResults(boolean allowPartialSearchResults) {
|
||||
this.searchRequest.allowPartialSearchResults(allowPartialSearchResults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if this request should allow partial results.
|
||||
*/
|
||||
public Boolean getAllowPartialSearchResults() {
|
||||
return this.searchRequest.allowPartialSearchResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional. Sets the number of shard results that should be reduced at once on the coordinating node.
|
||||
* This value should be used as a protection mechanism to reduce the memory overhead per search
|
||||
* request if the potential number of shards in the request can be large. Defaults to 5.
|
||||
*/
|
||||
public void setBatchedReduceSize(int batchedReduceSize) {
|
||||
this.batchedReduceSize = batchedReduceSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of shard results that should be reduced at once on the coordinating node.
|
||||
* Returns {@code null} if unset.
|
||||
*/
|
||||
public Integer getBatchedReduceSize() {
|
||||
return this.batchedReduceSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if this request should use the request cache or not, assuming that it can (for
|
||||
* example, if "now" is used, it will never be cached).
|
||||
* By default (if not set) this is turned on for {@link SubmitAsyncSearchRequest}.
|
||||
*/
|
||||
public void setRequestCache(Boolean requestCache) {
|
||||
this.searchRequest.requestCache(requestCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if this request should use the request cache or not, if set.
|
||||
* This defaults to `true` on the server side if unset in the client.
|
||||
*/
|
||||
public Boolean getRequestCache() {
|
||||
return this.searchRequest.requestCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of shard requests that should be executed concurrently on a single node.
|
||||
* The default is {@code 5}.
|
||||
*/
|
||||
public int getMaxConcurrentShardRequests() {
|
||||
return this.searchRequest.getMaxConcurrentShardRequests();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the number of shard requests that should be executed concurrently on a single node.
|
||||
* The default is {@code 5}.
|
||||
*/
|
||||
public void setMaxConcurrentShardRequests(int maxConcurrentShardRequests) {
|
||||
this.searchRequest.setMaxConcurrentShardRequests(maxConcurrentShardRequests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the source of the {@link SearchSourceBuilder} initially used on this request.
|
||||
*/
|
||||
public SearchSourceBuilder getSearchSource() {
|
||||
return this.searchRequest.source();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ValidationException> validate() {
|
||||
final ValidationException validationException = new ValidationException();
|
||||
if (searchRequest.isSuggestOnly()) {
|
||||
validationException.addValidationError("suggest-only queries are not supported");
|
||||
}
|
||||
if (keepAlive != null && keepAlive.getMillis() < MIN_KEEP_ALIVE) {
|
||||
validationException.addValidationError("[keep_alive] must be greater than 1 minute, got: " + keepAlive.toString());
|
||||
}
|
||||
if (validationException.validationErrors().isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(validationException);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SubmitAsyncSearchRequest request = (SubmitAsyncSearchRequest) o;
|
||||
return Objects.equals(searchRequest, request.searchRequest)
|
||||
&& Objects.equals(getKeepAlive(), request.getKeepAlive())
|
||||
&& Objects.equals(getWaitForCompletionTimeout(), request.getWaitForCompletionTimeout())
|
||||
&& Objects.equals(isKeepOnCompletion(), request.isKeepOnCompletion());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(searchRequest, getKeepAlive(), getWaitForCompletionTimeout(), isKeepOnCompletion());
|
||||
}
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client;
|
||||
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.client.asyncsearch.DeleteAsyncSearchRequest;
|
||||
import org.elasticsearch.client.asyncsearch.GetAsyncSearchRequest;
|
||||
import org.elasticsearch.client.asyncsearch.SubmitAsyncSearchRequest;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.rest.action.search.RestSearchAction;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static org.elasticsearch.client.RequestConvertersTests.createTestSearchSourceBuilder;
|
||||
import static org.elasticsearch.client.RequestConvertersTests.setRandomIndicesOptions;
|
||||
|
||||
public class AsyncSearchRequestConvertersTests extends ESTestCase {
|
||||
|
||||
public void testSubmitAsyncSearch() throws Exception {
|
||||
String[] indices = RequestConvertersTests.randomIndicesNames(0, 5);
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
SearchSourceBuilder searchSourceBuilder = createTestSearchSourceBuilder();
|
||||
SubmitAsyncSearchRequest submitRequest = new SubmitAsyncSearchRequest(searchSourceBuilder, indices);
|
||||
|
||||
// the following parameters might be overwritten by random ones later,
|
||||
// but we need to set these since they are the default we send over http
|
||||
setRandomSearchParams(submitRequest, expectedParams);
|
||||
setRandomIndicesOptions(submitRequest::setIndicesOptions, submitRequest::getIndicesOptions, expectedParams);
|
||||
|
||||
if (randomBoolean()) {
|
||||
boolean keepOnCompletion = randomBoolean();
|
||||
submitRequest.setKeepOnCompletion(keepOnCompletion);
|
||||
expectedParams.put("keep_on_completion", Boolean.toString(keepOnCompletion));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
TimeValue keepAlive = TimeValue.parseTimeValue(randomTimeValue(), "test");
|
||||
submitRequest.setKeepAlive(keepAlive);
|
||||
expectedParams.put("keep_alive", keepAlive.getStringRep());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
TimeValue waitForCompletionTimeout = TimeValue.parseTimeValue(randomTimeValue(), "test");
|
||||
submitRequest.setWaitForCompletionTimeout(waitForCompletionTimeout);
|
||||
expectedParams.put("wait_for_completion_timeout", waitForCompletionTimeout.getStringRep());
|
||||
}
|
||||
|
||||
Request request = AsyncSearchRequestConverters.submitAsyncSearch(submitRequest);
|
||||
StringJoiner endpoint = new StringJoiner("/", "/", "");
|
||||
String index = String.join(",", indices);
|
||||
if (Strings.hasLength(index)) {
|
||||
endpoint.add(index);
|
||||
}
|
||||
endpoint.add("_async_search");
|
||||
assertEquals(HttpPost.METHOD_NAME, request.getMethod());
|
||||
assertEquals(endpoint.toString(), request.getEndpoint());
|
||||
assertEquals(expectedParams, request.getParameters());
|
||||
RequestConvertersTests.assertToXContentBody(searchSourceBuilder, request.getEntity());
|
||||
}
|
||||
|
||||
private static void setRandomSearchParams(SubmitAsyncSearchRequest request, Map<String, String> expectedParams) {
|
||||
expectedParams.put(RestSearchAction.TYPED_KEYS_PARAM, "true");
|
||||
if (randomBoolean()) {
|
||||
request.setRouting(randomAlphaOfLengthBetween(3, 10));
|
||||
expectedParams.put("routing", request.getRouting());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
request.setPreference(randomAlphaOfLengthBetween(3, 10));
|
||||
expectedParams.put("preference", request.getPreference());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
request.setSearchType(randomFrom(SearchType.CURRENTLY_SUPPORTED));
|
||||
}
|
||||
expectedParams.put("search_type", request.getSearchType().name().toLowerCase(Locale.ROOT));
|
||||
if (randomBoolean()) {
|
||||
request.setAllowPartialSearchResults(randomBoolean());
|
||||
expectedParams.put("allow_partial_search_results", Boolean.toString(request.getAllowPartialSearchResults()));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
request.setRequestCache(randomBoolean());
|
||||
expectedParams.put("request_cache", Boolean.toString(request.getRequestCache()));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
request.setBatchedReduceSize(randomIntBetween(2, Integer.MAX_VALUE));
|
||||
expectedParams.put("batched_reduce_size", Integer.toString(request.getBatchedReduceSize()));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
request.setMaxConcurrentShardRequests(randomIntBetween(1, Integer.MAX_VALUE));
|
||||
}
|
||||
expectedParams.put("max_concurrent_shard_requests", Integer.toString(request.getMaxConcurrentShardRequests()));
|
||||
}
|
||||
|
||||
public void testGetAsyncSearch() throws Exception {
|
||||
String id = randomAlphaOfLengthBetween(5, 10);
|
||||
Map<String, String> expectedParams = new HashMap<>();
|
||||
GetAsyncSearchRequest submitRequest = new GetAsyncSearchRequest(id);
|
||||
if (randomBoolean()) {
|
||||
TimeValue keepAlive = TimeValue.parseTimeValue(randomTimeValue(), "test");
|
||||
submitRequest.setKeepAlive(keepAlive);
|
||||
expectedParams.put("keep_alive", keepAlive.getStringRep());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
TimeValue waitForCompletion = TimeValue.parseTimeValue(randomTimeValue(), "test");
|
||||
submitRequest.setWaitForCompletion(waitForCompletion);
|
||||
expectedParams.put("wait_for_completion_timeout", waitForCompletion.getStringRep());
|
||||
}
|
||||
|
||||
Request request = AsyncSearchRequestConverters.getAsyncSearch(submitRequest);
|
||||
String endpoint = "/_async_search/" + id;
|
||||
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
|
||||
assertEquals(endpoint.toString(), request.getEndpoint());
|
||||
assertEquals(expectedParams, request.getParameters());
|
||||
}
|
||||
|
||||
public void testDeleteAsyncSearch() throws Exception {
|
||||
String id = randomAlphaOfLengthBetween(5, 10);
|
||||
DeleteAsyncSearchRequest deleteRequest = new DeleteAsyncSearchRequest(id);
|
||||
|
||||
Request request = AsyncSearchRequestConverters.deleteAsyncSearch(deleteRequest);
|
||||
assertEquals(HttpDelete.METHOD_NAME, request.getMethod());
|
||||
assertEquals("/_async_search/" + id, request.getEndpoint());
|
||||
assertTrue(request.getParameters().isEmpty());
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client.asyncsearch;
|
||||
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.core.AcknowledgedResponse;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AsyncSearchIT extends ESRestHighLevelClientTestCase {
|
||||
|
||||
public void testAsyncSearch() throws IOException {
|
||||
String index = "test-index";
|
||||
createIndex(index, Settings.EMPTY);
|
||||
|
||||
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery());
|
||||
SubmitAsyncSearchRequest submitRequest = new SubmitAsyncSearchRequest(sourceBuilder, index);
|
||||
submitRequest.setKeepOnCompletion(true);
|
||||
AsyncSearchResponse submitResponse = highLevelClient().asyncSearch().submit(submitRequest, RequestOptions.DEFAULT);
|
||||
assertNotNull(submitResponse.getId());
|
||||
assertFalse(submitResponse.isPartial());
|
||||
assertTrue(submitResponse.getStartTime() > 0);
|
||||
assertTrue(submitResponse.getExpirationTime() > 0);
|
||||
assertNotNull(submitResponse.getSearchResponse());
|
||||
if (submitResponse.isRunning() == false) {
|
||||
assertFalse(submitResponse.isPartial());
|
||||
} else {
|
||||
assertTrue(submitResponse.isPartial());
|
||||
}
|
||||
|
||||
GetAsyncSearchRequest getRequest = new GetAsyncSearchRequest(submitResponse.getId());
|
||||
AsyncSearchResponse getResponse = highLevelClient().asyncSearch().get(getRequest, RequestOptions.DEFAULT);
|
||||
while (getResponse.isRunning()) {
|
||||
getResponse = highLevelClient().asyncSearch().get(getRequest, RequestOptions.DEFAULT);
|
||||
}
|
||||
|
||||
assertFalse(getResponse.isRunning());
|
||||
assertFalse(getResponse.isPartial());
|
||||
assertTrue(getResponse.getStartTime() > 0);
|
||||
assertTrue(getResponse.getExpirationTime() > 0);
|
||||
assertNotNull(getResponse.getSearchResponse());
|
||||
|
||||
DeleteAsyncSearchRequest deleteRequest = new DeleteAsyncSearchRequest(submitResponse.getId());
|
||||
AcknowledgedResponse deleteAsyncSearchResponse = highLevelClient().asyncSearch().delete(deleteRequest,
|
||||
RequestOptions.DEFAULT);
|
||||
assertNotNull(deleteAsyncSearchResponse);
|
||||
assertNotNull(deleteAsyncSearchResponse.isAcknowledged());
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.elasticsearch.client.asyncsearch;
|
||||
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse.Clusters;
|
||||
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
import org.elasticsearch.client.AbstractResponseTestCase;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.search.internal.InternalSearchResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
public class AsyncSearchResponseTests
|
||||
extends AbstractResponseTestCase<org.elasticsearch.xpack.core.search.action.AsyncSearchResponse, AsyncSearchResponse> {
|
||||
|
||||
@Override
|
||||
protected org.elasticsearch.xpack.core.search.action.AsyncSearchResponse createServerTestInstance(XContentType xContentType) {
|
||||
boolean isPartial = randomBoolean();
|
||||
boolean isRunning = randomBoolean();
|
||||
long startTimeMillis = randomLongBetween(0, Long.MAX_VALUE);
|
||||
long expirationTimeMillis = randomLongBetween(0, Long.MAX_VALUE);
|
||||
String id = randomBoolean() ? null : randomAlphaOfLength(10);
|
||||
ElasticsearchException error = randomBoolean() ? null : new ElasticsearchException(randomAlphaOfLength(10));
|
||||
// add search response, minimal object is okay since the full randomization of parsing is tested in SearchResponseTests
|
||||
SearchResponse searchResponse = randomBoolean() ? null
|
||||
: new SearchResponse(InternalSearchResponse.empty(), randomAlphaOfLength(10), 1, 1, 0, randomIntBetween(0, 10000),
|
||||
ShardSearchFailure.EMPTY_ARRAY, Clusters.EMPTY);
|
||||
org.elasticsearch.xpack.core.search.action.AsyncSearchResponse testResponse =
|
||||
new org.elasticsearch.xpack.core.search.action.AsyncSearchResponse(id, searchResponse, error, isPartial, isRunning,
|
||||
startTimeMillis, expirationTimeMillis);
|
||||
return testResponse;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AsyncSearchResponse doParseToClientInstance(XContentParser parser) throws IOException {
|
||||
return AsyncSearchResponse.fromXContent(parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void assertInstances(org.elasticsearch.xpack.core.search.action.AsyncSearchResponse expected, AsyncSearchResponse parsed) {
|
||||
assertNotSame(parsed, expected);
|
||||
assertEquals(expected.getId(), parsed.getId());
|
||||
assertEquals(expected.isRunning(), parsed.isRunning());
|
||||
assertEquals(expected.isPartial(), parsed.isPartial());
|
||||
assertEquals(expected.getStartTime(), parsed.getStartTime());
|
||||
assertEquals(expected.getExpirationTime(), parsed.getExpirationTime());
|
||||
// we cannot directly compare error since Exceptions are wrapped differently on parsing, but we can check original message
|
||||
if (expected.getFailure() != null) {
|
||||
assertThat(parsed.getFailure().getMessage(), containsString(expected.getFailure().getMessage()));
|
||||
} else {
|
||||
assertNull(parsed.getFailure());
|
||||
}
|
||||
// we don't need to check the complete parsed search response since this is done elsewhere
|
||||
// only spot-check some randomized properties for equality here
|
||||
if (expected.getSearchResponse() != null) {
|
||||
assertEquals(expected.getSearchResponse().getTook(), parsed.getSearchResponse().getTook());
|
||||
assertEquals(expected.getSearchResponse().getScrollId(), parsed.getSearchResponse().getScrollId());
|
||||
} else {
|
||||
assertNull(parsed.getSearchResponse());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client.asyncsearch;
|
||||
|
||||
import org.elasticsearch.client.ValidationException;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class SubmitAsyncSearchRequestTests extends ESTestCase {
|
||||
|
||||
public void testValidation() {
|
||||
{
|
||||
SearchSourceBuilder source = new SearchSourceBuilder();
|
||||
SubmitAsyncSearchRequest request = new SubmitAsyncSearchRequest(source, "test");
|
||||
Optional<ValidationException> validation = request.validate();
|
||||
assertFalse(validation.isPresent());
|
||||
}
|
||||
{
|
||||
SearchSourceBuilder source = new SearchSourceBuilder().suggest(new SuggestBuilder());
|
||||
SubmitAsyncSearchRequest request = new SubmitAsyncSearchRequest(source, "test");
|
||||
Optional<ValidationException> validation = request.validate();
|
||||
assertTrue(validation.isPresent());
|
||||
assertEquals(1, validation.get().validationErrors().size());
|
||||
assertEquals("suggest-only queries are not supported", validation.get().validationErrors().get(0));
|
||||
}
|
||||
{
|
||||
SubmitAsyncSearchRequest request = new SubmitAsyncSearchRequest(new SearchSourceBuilder(), "test");
|
||||
request.setKeepAlive(new TimeValue(1));
|
||||
Optional<ValidationException> validation = request.validate();
|
||||
assertTrue(validation.isPresent());
|
||||
assertEquals(1, validation.get().validationErrors().size());
|
||||
assertEquals("[keep_alive] must be greater than 1 minute, got: 1ms", validation.get().validationErrors().get(0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,238 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.client.documentation;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.LatchedActionListener;
|
||||
import org.elasticsearch.client.ESRestHighLevelClientTestCase;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.asyncsearch.AsyncSearchResponse;
|
||||
import org.elasticsearch.client.asyncsearch.DeleteAsyncSearchRequest;
|
||||
import org.elasticsearch.client.asyncsearch.GetAsyncSearchRequest;
|
||||
import org.elasticsearch.client.asyncsearch.SubmitAsyncSearchRequest;
|
||||
import org.elasticsearch.client.core.AcknowledgedResponse;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.junit.Before;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Documentation for Async Search APIs in the high level java client.
|
||||
* Code wrapped in {@code tag} and {@code end} tags is included in the docs.
|
||||
*/
|
||||
public class AsyncSearchDocumentationIT extends ESRestHighLevelClientTestCase {
|
||||
|
||||
@Before void setUpIndex() throws IOException {
|
||||
CreateIndexResponse createIndexResponse = highLevelClient().indices().create(new CreateIndexRequest("my-index"),
|
||||
RequestOptions.DEFAULT);
|
||||
assertTrue(createIndexResponse.isAcknowledged());
|
||||
}
|
||||
|
||||
public void testSubmitAsyncSearch() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
|
||||
// tag::asyncsearch-submit-request
|
||||
SearchSourceBuilder searchSource = new SearchSourceBuilder()
|
||||
.query(QueryBuilders.matchAllQuery()); // <1>
|
||||
String[] indices = new String[] { "my-index" }; // <2>
|
||||
SubmitAsyncSearchRequest request
|
||||
= new SubmitAsyncSearchRequest(searchSource, indices);
|
||||
// end::asyncsearch-submit-request
|
||||
|
||||
// tag::asyncsearch-submit-request-arguments
|
||||
request.setWaitForCompletionTimeout(TimeValue.timeValueSeconds(30)); // <1>
|
||||
request.setKeepAlive(TimeValue.timeValueMinutes(15)); // <2>
|
||||
request.setKeepOnCompletion(false); // <3>
|
||||
// end::asyncsearch-submit-request-arguments
|
||||
|
||||
// tag::asyncsearch-submit-execute
|
||||
AsyncSearchResponse response = client.asyncSearch()
|
||||
.submit(request, RequestOptions.DEFAULT); // <1>
|
||||
// end::asyncsearch-submit-execute
|
||||
|
||||
assertNotNull(response);
|
||||
assertNull(response.getFailure());
|
||||
|
||||
// tag::asyncsearch-submit-response
|
||||
response.getSearchResponse(); // <1>
|
||||
response.getId(); // <2>
|
||||
response.isPartial(); // <3>
|
||||
response.isRunning(); // <4>
|
||||
response.getStartTime(); // <5>
|
||||
response.getExpirationTime(); // <6>
|
||||
response.getFailure(); // <7>
|
||||
// end::asyncsearch-submit-response
|
||||
|
||||
|
||||
// tag::asyncsearch-submit-listener
|
||||
ActionListener<AsyncSearchResponse> listener =
|
||||
new ActionListener<AsyncSearchResponse>() {
|
||||
@Override
|
||||
public void onResponse(AsyncSearchResponse response) {
|
||||
// <1>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::asyncsearch-submit-listener
|
||||
|
||||
// Replace the empty listener by a blocking listener in test
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::asyncsearch-submit-execute-async
|
||||
client.asyncSearch()
|
||||
.submitAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::asyncsearch-submit-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
public void testGetAsyncSearch() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
SearchSourceBuilder searchSource = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery());
|
||||
String[] indices = new String[] { "my-index" };
|
||||
SubmitAsyncSearchRequest submitRequest = new SubmitAsyncSearchRequest(searchSource, indices);
|
||||
submitRequest.setKeepOnCompletion(true);
|
||||
AsyncSearchResponse submitResponse = client.asyncSearch().submit(submitRequest, RequestOptions.DEFAULT);
|
||||
String id = submitResponse.getId();
|
||||
|
||||
// tag::asyncsearch-get-request
|
||||
GetAsyncSearchRequest request = new GetAsyncSearchRequest(id);
|
||||
// end::asyncsearch-get-request
|
||||
|
||||
// tag::asyncsearch-get-request-arguments
|
||||
request.setWaitForCompletion(TimeValue.timeValueSeconds(30)); // <1>
|
||||
request.setKeepAlive(TimeValue.timeValueMinutes(15)); // <2>
|
||||
// end::asyncsearch-get-request-arguments
|
||||
|
||||
// tag::asyncsearch-get-execute
|
||||
AsyncSearchResponse response = client.asyncSearch()
|
||||
.get(request, RequestOptions.DEFAULT); // <1>
|
||||
// end::asyncsearch-get-execute
|
||||
|
||||
assertNotNull(response);
|
||||
assertNull(response.getFailure());
|
||||
|
||||
// tag::asyncsearch-get-response
|
||||
response.getSearchResponse(); // <1>
|
||||
response.getId(); // <2>
|
||||
response.isPartial(); // <3>
|
||||
response.isRunning(); // <4>
|
||||
response.getStartTime(); // <5>
|
||||
response.getExpirationTime(); // <6>
|
||||
response.getFailure(); // <7>
|
||||
// end::asyncsearch-get-response
|
||||
|
||||
|
||||
// tag::asyncsearch-get-listener
|
||||
ActionListener<AsyncSearchResponse> listener =
|
||||
new ActionListener<AsyncSearchResponse>() {
|
||||
@Override
|
||||
public void onResponse(AsyncSearchResponse response) {
|
||||
// <1>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::asyncsearch-get-listener
|
||||
|
||||
// Replace the empty listener by a blocking listener in test
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::asyncsearch-get-execute-async
|
||||
client.asyncSearch()
|
||||
.getAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::asyncsearch-get-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
client.asyncSearch().delete(new DeleteAsyncSearchRequest(id), RequestOptions.DEFAULT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void testDeleteAsyncSearch() throws Exception {
|
||||
RestHighLevelClient client = highLevelClient();
|
||||
SearchSourceBuilder searchSource = new SearchSourceBuilder().query(QueryBuilders.matchAllQuery());
|
||||
String[] indices = new String[] { "my-index" };
|
||||
SubmitAsyncSearchRequest submitRequest = new SubmitAsyncSearchRequest(searchSource, indices);
|
||||
submitRequest.setKeepOnCompletion(true);
|
||||
AsyncSearchResponse submitResponse = client.asyncSearch().submit(submitRequest, RequestOptions.DEFAULT);
|
||||
String id = submitResponse.getId();
|
||||
|
||||
// tag::asyncsearch-delete-request
|
||||
DeleteAsyncSearchRequest request = new DeleteAsyncSearchRequest(id);
|
||||
// end::asyncsearch-delete-request
|
||||
|
||||
// tag::asyncsearch-delete-execute
|
||||
AcknowledgedResponse response = client.asyncSearch() // <1>
|
||||
.delete(new DeleteAsyncSearchRequest(id),
|
||||
RequestOptions.DEFAULT);
|
||||
// end::asyncsearch-delete-execute
|
||||
|
||||
assertNotNull(response);
|
||||
assertTrue(response.isAcknowledged());
|
||||
|
||||
// tag::asyncsearch-delete-response
|
||||
response.isAcknowledged(); // <1>
|
||||
// end::asyncsearch-delete-response
|
||||
|
||||
|
||||
// tag::asyncsearch-delete-listener
|
||||
ActionListener<AcknowledgedResponse> listener =
|
||||
new ActionListener<AcknowledgedResponse>() {
|
||||
@Override
|
||||
public void onResponse(AcknowledgedResponse response) {
|
||||
// <1>
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
// <2>
|
||||
}
|
||||
};
|
||||
// end::asyncsearch-delete-listener
|
||||
|
||||
// Replace the empty listener by a blocking listener in test
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
listener = new LatchedActionListener<>(listener, latch);
|
||||
|
||||
// tag::asyncsearch-delete-execute-async
|
||||
client.asyncSearch()
|
||||
.deleteAsync(request, RequestOptions.DEFAULT, listener); // <1>
|
||||
// end::asyncsearch-delete-execute-async
|
||||
|
||||
assertTrue(latch.await(30L, TimeUnit.SECONDS));
|
||||
|
||||
}
|
||||
}
|
|
@ -122,8 +122,6 @@ def projectPathsToExclude = [
|
|||
':test:logger-usage',
|
||||
':x-pack:license-tools',
|
||||
':x-pack:plugin:analytics',
|
||||
':x-pack:plugin:async-search',
|
||||
':x-pack:plugin:async-search:qa',
|
||||
':x-pack:plugin:ccr',
|
||||
':x-pack:plugin:ccr:qa',
|
||||
':x-pack:plugin:core',
|
||||
|
|
|
@ -1333,7 +1333,6 @@ public abstract class ESRestTestCase extends ESTestCase {
|
|||
case ".logstash-management":
|
||||
case "security_audit_log":
|
||||
case ".slm-history":
|
||||
case ".async-search":
|
||||
case "saml-service-provider":
|
||||
case "ilm-history":
|
||||
case "logs":
|
||||
|
|
Loading…
Reference in New Issue