diff --git a/server/src/main/java/org/opensearch/action/search/SearchResponse.java b/server/src/main/java/org/opensearch/action/search/SearchResponse.java index 899c71e91e3ab..7131d4611ea79 100644 --- a/server/src/main/java/org/opensearch/action/search/SearchResponse.java +++ b/server/src/main/java/org/opensearch/action/search/SearchResponse.java @@ -705,6 +705,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.startObject(PHASE_TOOK.getPreferredName()); for (SearchPhaseName searchPhaseName : SearchPhaseName.values()) { + if (!searchPhaseName.shouldTrack()) continue; if (phaseTookMap.containsKey(searchPhaseName.getName())) { builder.field(searchPhaseName.getName(), phaseTookMap.get(searchPhaseName.getName())); } else { diff --git a/server/src/test/java/org/opensearch/index/search/stats/SearchStatsTests.java b/server/src/test/java/org/opensearch/index/search/stats/SearchStatsTests.java index 594700ea60b3e..bb8896023fdc7 100644 --- a/server/src/test/java/org/opensearch/index/search/stats/SearchStatsTests.java +++ b/server/src/test/java/org/opensearch/index/search/stats/SearchStatsTests.java @@ -83,6 +83,7 @@ public void testShardLevelSearchGroupStats() throws Exception { SearchRequestStats testRequestStats = new SearchRequestStats(clusterSettings); SearchPhaseContext ctx = mock(SearchPhaseContext.class); for (SearchPhaseName searchPhaseName : SearchPhaseName.values()) { + if (!searchPhaseName.shouldTrack()) continue; SearchPhase mockSearchPhase = mock(SearchPhase.class); when(ctx.getCurrentPhase()).thenReturn(mockSearchPhase); when(mockSearchPhase.getStartTimeInNanos()).thenReturn(System.nanoTime() - TimeUnit.SECONDS.toNanos(paramValue)); @@ -94,6 +95,7 @@ public void testShardLevelSearchGroupStats() throws Exception { } searchStats1.setSearchRequestStats(testRequestStats); for (SearchPhaseName searchPhaseName : SearchPhaseName.values()) { + if (!searchPhaseName.shouldTrack()) continue; assertEquals( 0, searchStats1.getTotal().getRequestStatsLongHolder().getRequestStatsHolder().get(searchPhaseName.getName()).current