Skip to content

Commit d0fdc17

Browse files
Skip approcimation when track total hits sets to true
Signed-off-by: Prudhvi Godithi <[email protected]>
1 parent a3dba00 commit d0fdc17

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

server/src/main/java/org/opensearch/search/approximate/ApproximateMatchAllQuery.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ protected boolean canApproximate(SearchContext context) {
3636
if (context.aggregations() != null) {
3737
return false;
3838
}
39+
// When "track_total_hits": true,
40+
if (context.trackTotalHitsUpTo() == SearchContext.TRACK_TOTAL_HITS_ACCURATE) {
41+
return false;
42+
}
3943

4044
if (context.request() != null && context.request().source() != null && context.innerHits().getInnerHits().isEmpty()) {
4145
FieldSortBuilder primarySortField = FieldSortBuilder.getPrimaryFieldSortOrNull(context.request().source());

server/src/main/java/org/opensearch/search/approximate/ApproximatePointRangeQuery.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ public boolean canApproximate(SearchContext context) {
440440
if (context.aggregations() != null) {
441441
return false;
442442
}
443+
// When "track_total_hits": true,
444+
if (context.trackTotalHitsUpTo() == SearchContext.TRACK_TOTAL_HITS_ACCURATE) {
445+
return false;
446+
}
447+
443448
// size 0 could be set for caching
444449
if (context.from() + context.size() == 0) {
445450
this.setSize(SearchContext.DEFAULT_TRACK_TOTAL_HITS_UP_TO);

0 commit comments

Comments
 (0)