Skip to content

Commit b369611

Browse files
dzane17jainankitk
andauthored
Add successfulSearchShardIndices in searchRequestContext before onRequestEnd (opensearch-project#15967)
Signed-off-by: David Zane <davizane@amazon.com> Signed-off-by: Ankit Jain <akjain@amazon.com> Co-authored-by: Ankit Jain <akjain@amazon.com>
1 parent 94222f1 commit b369611

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

CHANGELOG.md

+1
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
- [Workload Management] QueryGroup resource cancellation framework changes ([#15651](https://github.com/opensearch-project/OpenSearch/pull/15651))
1010
- Fallback to Remote cluster-state on Term-Version check mismatch - ([#15424](https://github.com/opensearch-project/OpenSearch/pull/15424))
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
- Remove identity-related feature flagged code from the RestController ([#15430](https://github.com/opensearch-project/OpenSearch/pull/15430))
1314

1415
### Dependencies

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

+3
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

+14
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)