Skip to content

Commit a022ef7

Browse files
committed
Rare terms aggregation false **positive** fix
1 parent 99719f2 commit a022ef7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

server/src/main/java/org/elasticsearch/common/util/SetBackedScalingCuckooFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public void merge(SetBackedScalingCuckooFilter other) {
340340
} else if (isSetMode == false && other.isSetMode) {
341341
// Rather than converting the other to a cuckoo first, we can just
342342
// replay the values directly into our filter.
343-
other.hashes.forEach(this::add);
343+
other.hashes.forEach(this::addHash);
344344
} else {
345345
// Both are in cuckoo mode, merge raw fingerprints
346346

server/src/test/java/org/elasticsearch/common/util/SetBackedScalingCuckooFilterTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,34 @@ public void testConvertTwice() {
131131
);
132132
}
133133

134+
public void testMergeBigSmall(){
135+
int threshold = 1000;
136+
137+
// Setup the first filter
138+
SetBackedScalingCuckooFilter filter = new SetBackedScalingCuckooFilter(threshold, Randomness.get(), 0.01);
139+
int counter = 0;
140+
Set<Long> values = new HashSet<>();
141+
while (counter < threshold + 1) {
142+
long value = randomLong();
143+
filter.add(value);
144+
boolean newValue = values.add(value);
145+
if (newValue) {
146+
counter += 1;
147+
}
148+
}
149+
150+
SetBackedScalingCuckooFilter filter2 = new SetBackedScalingCuckooFilter(threshold, Randomness.get(), 0.01);
151+
long value = randomLong();
152+
while(filter.mightContain(value)){
153+
value = randomLong();
154+
}
155+
156+
filter2.add(value);
157+
158+
filter.merge(filter2);
159+
assertTrue(filter.mightContain(value));
160+
}
161+
134162
public void testMergeSmall() {
135163
int threshold = 1000;
136164

0 commit comments

Comments
 (0)