-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce async search status API GET /_async_search/status/<id> The API is restricted to the monitoring_user role. For a running async search, the response is: ```js { "id" : <id>, "is_running" : true, "start_time_in_millis" : 1583945890986, "expiration_time_in_millis" : 1584377890986, "_shards" : { "total" : 562, "successful" : 188, "skipped" : 0, "failed" : 0 } } ``` For a completed async search, the response is: ```js { "id" : <id> "is_running" : false, "expiration_time_in_millis" : 1584377890986 } ``` ---- Techincal details: We first try to retrieve the status of the async search from tasks. If this doesn't succeed, we retrieve it from an index: .async-search. In case of retrieving from the index, we assume that the async search is completed, and a shorter response for the status is returned. Closes #57537
- Loading branch information
1 parent
48db3f2
commit faafd18
Showing
15 changed files
with
710 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...n/async-search/src/main/java/org/elasticsearch/xpack/search/RestGetAsyncStatusAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.search; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestStatusToXContentListener; | ||
import org.elasticsearch.xpack.core.async.GetAsyncStatusRequest; | ||
import org.elasticsearch.xpack.core.search.action.GetAsyncStatusAction; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Arrays.asList; | ||
import static java.util.Collections.unmodifiableList; | ||
import static org.elasticsearch.rest.RestRequest.Method.GET; | ||
|
||
public class RestGetAsyncStatusAction extends BaseRestHandler { | ||
@Override | ||
public List<Route> routes() { | ||
return unmodifiableList(asList(new Route(GET, "/_async_search/status/{id}"))); | ||
} | ||
|
||
|
||
@Override | ||
public String getName() { | ||
return "async_search_status_action"; | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
GetAsyncStatusRequest statusRequest = new GetAsyncStatusRequest(request.param("id")); | ||
return channel -> client.execute(GetAsyncStatusAction.INSTANCE, statusRequest, new RestStatusToXContentListener<>(channel)); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...nc-search/src/main/java/org/elasticsearch/xpack/search/TransportGetAsyncStatusAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.search; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.ActionListenerResponseHandler; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.HandledTransportAction; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportRequestOptions; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.XPackPlugin; | ||
import org.elasticsearch.xpack.core.async.AsyncStatusService; | ||
import org.elasticsearch.xpack.core.async.AsyncTaskIndexService; | ||
import org.elasticsearch.xpack.core.async.GetAsyncStatusRequest; | ||
import org.elasticsearch.xpack.core.search.action.AsyncStatusResponse; | ||
import org.elasticsearch.xpack.core.search.action.GetAsyncStatusAction; | ||
|
||
import static org.elasticsearch.xpack.core.ClientHelper.ASYNC_SEARCH_ORIGIN; | ||
|
||
public class TransportGetAsyncStatusAction extends HandledTransportAction<GetAsyncStatusRequest, AsyncStatusResponse> { | ||
private final TransportService transportService; | ||
private final AsyncStatusService<AsyncSearchTask, AsyncStatusResponse> statusService; | ||
|
||
@Inject | ||
public TransportGetAsyncStatusAction(TransportService transportService, | ||
ActionFilters actionFilters, | ||
ClusterService clusterService, | ||
NamedWriteableRegistry registry, | ||
Client client, | ||
ThreadPool threadPool) { | ||
super(GetAsyncStatusAction.NAME, transportService, actionFilters, GetAsyncStatusRequest::new); | ||
this.transportService = transportService; | ||
AsyncTaskIndexService<AsyncStatusResponse> store = new AsyncTaskIndexService<>(XPackPlugin.ASYNC_RESULTS_INDEX, clusterService, | ||
threadPool.getThreadContext(), client, ASYNC_SEARCH_ORIGIN, AsyncStatusResponse::new, registry); | ||
this.statusService = new AsyncStatusService<>(store, AsyncSearchTask.class, AsyncSearchTask::getStatusResponse, | ||
AsyncStatusResponse::getCompletedSearchStatusResponse, transportService.getTaskManager(), clusterService); | ||
} | ||
|
||
@Override | ||
protected void doExecute(Task task, GetAsyncStatusRequest request, ActionListener<AsyncStatusResponse> listener) { | ||
DiscoveryNode node = statusService.getNode(request.getId()); | ||
if (node == null || statusService.isLocalNode(node)) { | ||
statusService.retrieveStatus(request, listener); | ||
} else { | ||
TransportRequestOptions.Builder builder = TransportRequestOptions.builder(); | ||
transportService.sendRequest(node, GetAsyncStatusAction.NAME, request, builder.build(), | ||
new ActionListenerResponseHandler<>(listener, AsyncStatusResponse::new, ThreadPool.Names.SAME)); | ||
} | ||
} | ||
} |
Oops, something went wrong.