Skip to content

Commit 374cee8

Browse files
committed
set track_total_hits to true in aggregation queries
1 parent d8dfd26 commit 374cee8

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

connector/query.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,17 @@ func prepareElasticsearchQuery(ctx context.Context, request *schema.QueryRequest
190190
}
191191
if len(aggs) != 0 {
192192
query["aggs"] = aggs
193-
194-
// set query size to 0 if aggregation is present
195-
// this is because, by default, an aggregation query returns both the aggregation result and the hit documents
196-
// we only want the aggregation result
197-
// more reading: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html#return-only-agg-results
198-
query["size"] = 0
199193
}
194+
195+
// set query size to 0 if aggregation is present
196+
// this is because, by default, an aggregation query returns both the aggregation result and the hit documents
197+
// we only want the aggregation result
198+
// more reading: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html#return-only-agg-results
199+
query["size"] = 0
200+
201+
// set track_total_hits to true if aggregation is present
202+
// this is because, by default, a count query will only return 10,000 hits
203+
query["track_total_hits"] = true
200204
}
201205

202206
span.AddEvent("prepare_filter_query")

0 commit comments

Comments
 (0)