Skip to content

Commit

Permalink
Add successfulSearchShardIndices in searchRequestContext before onReq…
Browse files Browse the repository at this point in the history
…uestEnd (#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>
(cherry picked from commit b369611)
  • Loading branch information
dzane17 committed Sep 19, 2024
1 parent dd5c31b commit a37fc20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add path prefix support to hashed prefix snapshots ([#15664](https://github.com/opensearch-project/OpenSearch/pull/15664))
- [Workload Management] QueryGroup resource cancellation framework changes ([#15651](https://github.com/opensearch-project/OpenSearch/pull/15651))
- Implement WithFieldName interface in ValuesSourceAggregationBuilder & FieldSortBuilder ([#15916](https://github.com/opensearch-project/OpenSearch/pull/15916))
- Add successfulSearchShardIndices in searchRequestContext ([#15967](https://github.com/opensearch-project/OpenSearch/pull/15967))

### Dependencies
- Bump `org.apache.logging.log4j:log4j-core` from 2.23.1 to 2.24.0 ([#15858](https://github.com/opensearch-project/OpenSearch/pull/15858))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,9 @@ public void sendSearchResponse(InternalSearchResponse internalSearchResponse, At
}
searchRequestContext.setTotalHits(internalSearchResponse.hits().getTotalHits());
searchRequestContext.setShardStats(results.getNumShards(), successfulOps.get(), skippedOps.get(), failures.length);
searchRequestContext.setSuccessfulSearchShardIndices(
results.getSuccessfulResults().map(result -> result.getSearchShardTarget().getIndex()).collect(Collectors.toSet())
);
onPhaseEnd(searchRequestContext);
onRequestEnd(searchRequestContext);
listener.onResponse(buildSearchResponse(internalSearchResponse, failures, scrollId, searchContextId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Supplier;

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

private final SearchRequest searchRequest;
private final LinkedBlockingQueue<TaskResourceInfo> phaseResourceUsage;
Expand Down Expand Up @@ -141,6 +143,18 @@ public List<TaskResourceInfo> getPhaseResourceUsage() {
public SearchRequest getRequest() {
return searchRequest;
}

void setSuccessfulSearchShardIndices(Set<String> successfulSearchShardIndices) {
this.successfulSearchShardIndices = successfulSearchShardIndices;
}

/**
* @return A {@link List} of {@link String} representing the names of the indices that were
* successfully queried at the shard level.
*/
public Set<String> getSuccessfulSearchShardIndices() {
return successfulSearchShardIndices;

Check warning on line 156 in server/src/main/java/org/opensearch/action/search/SearchRequestContext.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L156 was not covered by tests
}
}

enum ShardStatsFieldNames {
Expand Down

0 comments on commit a37fc20

Please sign in to comment.