Skip to content

Commit a37fc20

Browse files
dzane17jainankitk
andcommitted
Add successfulSearchShardIndices in searchRequestContext before onRequestEnd (#15967)
Signed-off-by: David Zane <[email protected]> Signed-off-by: Ankit Jain <[email protected]> Co-authored-by: Ankit Jain <[email protected]> (cherry picked from commit b369611)
1 parent dd5c31b commit a37fc20

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
- Add path prefix support to hashed prefix snapshots ([#15664](https://github.com/opensearch-project/OpenSearch/pull/15664))
1010
- [Workload Management] QueryGroup resource cancellation framework changes ([#15651](https://github.com/opensearch-project/OpenSearch/pull/15651))
1111
- Implement WithFieldName interface in ValuesSourceAggregationBuilder & FieldSortBuilder ([#15916](https://github.com/opensearch-project/OpenSearch/pull/15916))
12+
- Add successfulSearchShardIndices in searchRequestContext ([#15967](https://github.com/opensearch-project/OpenSearch/pull/15967))
1213

1314
### Dependencies
1415
- Bump `org.apache.logging.log4j:log4j-core` from 2.23.1 to 2.24.0 ([#15858](https://github.com/opensearch-project/OpenSearch/pull/15858))

server/src/main/java/org/opensearch/action/search/AbstractSearchAsyncAction.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ public void sendSearchResponse(InternalSearchResponse internalSearchResponse, At
754754
}
755755
searchRequestContext.setTotalHits(internalSearchResponse.hits().getTotalHits());
756756
searchRequestContext.setShardStats(results.getNumShards(), successfulOps.get(), skippedOps.get(), failures.length);
757+
searchRequestContext.setSuccessfulSearchShardIndices(
758+
results.getSuccessfulResults().map(result -> result.getSearchShardTarget().getIndex()).collect(Collectors.toSet())
759+
);
757760
onPhaseEnd(searchRequestContext);
758761
onRequestEnd(searchRequestContext);
759762
listener.onResponse(buildSearchResponse(internalSearchResponse, failures, scrollId, searchContextId));

server/src/main/java/org/opensearch/action/search/SearchRequestContext.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121
import java.util.Locale;
2222
import java.util.Map;
23+
import java.util.Set;
2324
import java.util.concurrent.LinkedBlockingQueue;
2425
import java.util.function.Supplier;
2526

@@ -36,6 +37,7 @@ public class SearchRequestContext {
3637
private final Map<String, Long> phaseTookMap;
3738
private TotalHits totalHits;
3839
private final EnumMap<ShardStatsFieldNames, Integer> shardStats;
40+
private Set<String> successfulSearchShardIndices;
3941

4042
private final SearchRequest searchRequest;
4143
private final LinkedBlockingQueue<TaskResourceInfo> phaseResourceUsage;
@@ -141,6 +143,18 @@ public List<TaskResourceInfo> getPhaseResourceUsage() {
141143
public SearchRequest getRequest() {
142144
return searchRequest;
143145
}
146+
147+
void setSuccessfulSearchShardIndices(Set<String> successfulSearchShardIndices) {
148+
this.successfulSearchShardIndices = successfulSearchShardIndices;
149+
}
150+
151+
/**
152+
* @return A {@link List} of {@link String} representing the names of the indices that were
153+
* successfully queried at the shard level.
154+
*/
155+
public Set<String> getSuccessfulSearchShardIndices() {
156+
return successfulSearchShardIndices;
157+
}
144158
}
145159

146160
enum ShardStatsFieldNames {

0 commit comments

Comments
 (0)