Skip to content

Commit 52f4c52

Browse files
committed
Updated the algorithm selection logic
Signed-off-by: Vinay Krishna Pudyodu <vinkrish.neo@gmail.com>
1 parent 14738d8 commit 52f4c52

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

server/src/main/java/org/opensearch/search/aggregations/bucket/terms/NumericTermsAggregator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws
263263

264264
// Use priority queue approach when request size is smaller than 10% of total buckets,
265265
// or when key ordering is required
266-
if ((size < 0.1 * bucketsInOrd) || isKeyOrder(order)) {
266+
if ((size < 0.2 * bucketsInOrd) || isKeyOrder(order)) {
267267
PriorityQueue<B> ordered = buildPriorityQueue(size);
268268
while (ordsEnum.next()) {
269269
long docCount = bucketDocCount(ordsEnum.ord());

server/src/test/java/org/opensearch/search/aggregations/bucket/terms/NumericTermsAggregatorTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,16 @@ private void testSearchCase(
196196
}
197197
}
198198

199-
public void testHeapSortForSmallResultSets() throws IOException {
200-
List<Long> highCardinalityDataset = new ArrayList<>();
199+
public void testBuildAggregationsForHeapSort() throws IOException {
200+
List<Long> dataSet = new ArrayList<>();
201201
for (long i = 0; i < 150; i++) {
202-
highCardinalityDataset.add(i);
202+
dataSet.add(i);
203203
}
204204

205205
testSearchCase(
206206
new MatchAllDocsQuery(),
207-
highCardinalityDataset,
208-
aggregation -> aggregation.field(LONG_FIELD).size(2), // Small result set
207+
dataSet,
208+
aggregation -> aggregation.field(LONG_FIELD).size(2),
209209
agg -> {
210210
assertEquals(2, agg.getBuckets().size());
211211
for (int i = 0; i < 2; i++) {
@@ -218,13 +218,13 @@ public void testHeapSortForSmallResultSets() throws IOException {
218218
);
219219
}
220220

221-
public void testQuickSelectForLargeResultSets() throws IOException {
222-
List<Long> highCardinalityDataset = new ArrayList<>();
221+
public void testBuildAggregationsForQuickSelect() throws IOException {
222+
List<Long> dataSet = new ArrayList<>();
223223
for (long i = 0; i < 150; i++) {
224-
highCardinalityDataset.add(i);
224+
dataSet.add(i);
225225
}
226226

227-
testSearchCase(new MatchAllDocsQuery(), highCardinalityDataset, aggregation -> aggregation.field(LONG_FIELD).size(50), agg -> {
227+
testSearchCase(new MatchAllDocsQuery(), dataSet, aggregation -> aggregation.field(LONG_FIELD).size(50), agg -> {
228228
assertEquals(50, agg.getBuckets().size());
229229
for (int i = 0; i < agg.getBuckets().size(); i++) {
230230
LongTerms.Bucket bucket = (LongTerms.Bucket) agg.getBuckets().get(i);

0 commit comments

Comments
 (0)