diff --git a/src/main/java/org/opensearch/plugin/insights/core/service/grouper/MinMaxHeapQueryGrouper.java b/src/main/java/org/opensearch/plugin/insights/core/service/grouper/MinMaxHeapQueryGrouper.java index 36559447..be2f60ff 100644 --- a/src/main/java/org/opensearch/plugin/insights/core/service/grouper/MinMaxHeapQueryGrouper.java +++ b/src/main/java/org/opensearch/plugin/insights/core/service/grouper/MinMaxHeapQueryGrouper.java @@ -251,7 +251,7 @@ private void addToMaxPQPromoteToMinPQ(SearchQueryRecord aggregateSearchQueryReco } private boolean checkMaxGroupsLimitReached(String groupId) { - if (maxGroups <= maxHeapQueryStore.size()) { + if (maxGroups <= maxHeapQueryStore.size() && minHeapTopQueriesStore.size() >= topNSize) { log.warn( "Exceeded [{}] setting threshold which is set at {}. Discarding new group with id {}.", TOP_N_QUERIES_MAX_GROUPS_EXCLUDING_N.getKey(),