forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a listener to track the progress of a search request locally
This commit adds a function in NodeClient that allows to track the progress of a search request locally. Progress is tracked through a SearchProgressListener that exposes query and fetch responses as well as partial and final reduces. This new method can be used by modules/plugins inside a node in order to track the progress of a local search request. Relates elastic#49091
- Loading branch information
Showing
17 changed files
with
657 additions
and
31 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
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
29 changes: 29 additions & 0 deletions
29
server/src/main/java/org/elasticsearch/action/search/SearchProgressActionListener.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,29 @@ | ||
/* | ||
* 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.action.search; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
|
||
/** | ||
* An {@link ActionListener} for search requests that allows to track progress of the {@link SearchAction}. | ||
* See {@link SearchProgressListener}. | ||
*/ | ||
public abstract class SearchProgressActionListener extends SearchProgressListener implements ActionListener<SearchResponse> { | ||
} |
111 changes: 111 additions & 0 deletions
111
server/src/main/java/org/elasticsearch/action/search/SearchProgressListener.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,111 @@ | ||
/* | ||
* 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.action.search; | ||
|
||
import org.apache.lucene.search.TotalHits; | ||
import org.elasticsearch.cluster.routing.GroupShardsIterator; | ||
import org.elasticsearch.search.SearchPhaseResult; | ||
import org.elasticsearch.search.aggregations.InternalAggregations; | ||
import org.elasticsearch.search.fetch.FetchSearchResult; | ||
import org.elasticsearch.search.query.QuerySearchResult; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
/** | ||
* A listener that allows to track progress of the {@link SearchAction}. | ||
*/ | ||
abstract class SearchProgressListener { | ||
/** | ||
* Executed when shards are ready to be queried. | ||
* | ||
* @param shards The list of shards to query. | ||
* @param fetchPhase <code>true</code> if the search needs a fetch phase, <code>false</code> otherwise. | ||
**/ | ||
public void onListShards(List<SearchShard> shards, boolean fetchPhase) {} | ||
|
||
/** | ||
* Executed when a shard returns a query result. | ||
* | ||
* @param result The query result. | ||
*/ | ||
public void onQueryResult(QuerySearchResult result) {} | ||
|
||
/** | ||
* Executed when a shard reports a query failure. | ||
* | ||
* @param shardIndex The index of the shard in the list provided by onListShards. | ||
* @param exc The cause of the failure. | ||
*/ | ||
public void onQueryFailure(int shardIndex, Exception exc) { } | ||
|
||
/** | ||
* Executed when a partial reduce is created. The number of partial reduce can be controlled via | ||
* {@link SearchRequest#setBatchedReduceSize(int)}. | ||
* | ||
* @param shards The list of shards that are part of this reduce. | ||
* @param totalHits The total number of hits in this reduce. | ||
* @param aggs The partial result for aggregations. | ||
* @param version The version number for this reduce. | ||
*/ | ||
public void onPartialReduce(List<SearchShard> shards, TotalHits totalHits, InternalAggregations aggs, int version) {} | ||
|
||
/** | ||
* Executed once when the final reduce is created. | ||
* | ||
* @param shards The list of shards that are part of this reduce. | ||
* @param totalHits The total number of hits in this reduce. | ||
* @param aggs The final result for aggregations. | ||
*/ | ||
public void onReduce(List<SearchShard> shards, TotalHits totalHits, InternalAggregations aggs) {} | ||
|
||
/** | ||
* Executed when a shard returns a query result. | ||
* | ||
* @param result The fetch result. | ||
*/ | ||
public void onFetchResult(FetchSearchResult result) {} | ||
|
||
/** | ||
* Executed when a shard reports a fetch failure. | ||
* | ||
* @param shardIndex The index of the shard in the list provided by onListShards. | ||
* @param exc The cause of the failure. | ||
*/ | ||
public void onFetchFailure(int shardIndex, Exception exc) {} | ||
|
||
final List<SearchShard> searchShards(List<? extends SearchPhaseResult> results) { | ||
return results.stream() | ||
.filter(Objects::nonNull) | ||
.map(SearchPhaseResult::getSearchShardTarget) | ||
.map(e -> new SearchShard(e.getClusterAlias(), e.getShardId())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
final List<SearchShard> searchShards(GroupShardsIterator<SearchShardIterator> its) { | ||
return StreamSupport.stream(its.spliterator(), false) | ||
.map(e -> new SearchShard(e.getClusterAlias(), e.shardId())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public static final SearchProgressListener NOOP = new SearchProgressListener() {}; | ||
} |
Oops, something went wrong.