Fixes for a few randomized agg tests that fail hasValue() checks
Closes #37743 Closes #37873
This commit is contained in:
parent
68149b6058
commit
afd4618851
|
@ -63,7 +63,6 @@ public class FilterAggregatorTests extends AggregatorTestCase {
|
|||
directory.close();
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/37743")
|
||||
public void testRandom() throws Exception {
|
||||
Directory directory = newDirectory();
|
||||
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
|
||||
|
@ -86,26 +85,31 @@ public class FilterAggregatorTests extends AggregatorTestCase {
|
|||
|
||||
IndexReader indexReader = DirectoryReader.open(directory);
|
||||
IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
|
||||
int value = randomInt(maxTerm - 1);
|
||||
QueryBuilder filter = QueryBuilders.termQuery("field", Integer.toString(value));
|
||||
FilterAggregationBuilder builder = new FilterAggregationBuilder("test", filter);
|
||||
try {
|
||||
|
||||
for (boolean doReduce : new boolean[] {true, false}) {
|
||||
final InternalFilter response;
|
||||
if (doReduce) {
|
||||
response = searchAndReduce(indexSearcher, new MatchAllDocsQuery(), builder,
|
||||
int value = randomInt(maxTerm - 1);
|
||||
QueryBuilder filter = QueryBuilders.termQuery("field", Integer.toString(value));
|
||||
FilterAggregationBuilder builder = new FilterAggregationBuilder("test", filter);
|
||||
|
||||
for (boolean doReduce : new boolean[]{true, false}) {
|
||||
final InternalFilter response;
|
||||
if (doReduce) {
|
||||
response = searchAndReduce(indexSearcher, new MatchAllDocsQuery(), builder,
|
||||
fieldType);
|
||||
} else {
|
||||
response = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
|
||||
}
|
||||
assertEquals(response.getDocCount(), (long) expectedBucketCount[value]);
|
||||
if (expectedBucketCount[expectedBucketCount[value]] > 0) {
|
||||
assertTrue(AggregationInspectionHelper.hasValue(response));
|
||||
} else {
|
||||
assertFalse(AggregationInspectionHelper.hasValue(response));
|
||||
} else {
|
||||
response = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
|
||||
}
|
||||
assertEquals(response.getDocCount(), (long) expectedBucketCount[value]);
|
||||
if (expectedBucketCount[value] > 0) {
|
||||
assertTrue(AggregationInspectionHelper.hasValue(response));
|
||||
} else {
|
||||
assertFalse(AggregationInspectionHelper.hasValue(response));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
indexReader.close();
|
||||
directory.close();
|
||||
}
|
||||
indexReader.close();
|
||||
directory.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -160,52 +160,50 @@ public class FiltersAggregatorTests extends AggregatorTestCase {
|
|||
|
||||
IndexReader indexReader = DirectoryReader.open(directory);
|
||||
IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
|
||||
int numFilters = randomIntBetween(1, 10);
|
||||
QueryBuilder[] filters = new QueryBuilder[numFilters];
|
||||
int[] filterTerms = new int[numFilters];
|
||||
int expectedOtherCount = numDocs;
|
||||
Set<Integer> filterSet = new HashSet<>();
|
||||
for (int i = 0; i < filters.length; i++) {
|
||||
int value = randomInt(maxTerm-1);
|
||||
filters[i] = QueryBuilders.termQuery("field", Integer.toString(value));
|
||||
filterTerms[i] = value;
|
||||
if (filterSet.contains(value) == false) {
|
||||
expectedOtherCount -= expectedBucketCount[value];
|
||||
filterSet.add(value);
|
||||
}
|
||||
}
|
||||
FiltersAggregationBuilder builder = new FiltersAggregationBuilder("test", filters);
|
||||
builder.otherBucket(true);
|
||||
builder.otherBucketKey("other");
|
||||
|
||||
for (boolean doReduce : new boolean[] {true, false}) {
|
||||
final InternalFilters response;
|
||||
if (doReduce) {
|
||||
response = searchAndReduce(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
|
||||
} else {
|
||||
response = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
|
||||
}
|
||||
List<InternalFilters.InternalBucket> buckets = response.getBuckets();
|
||||
assertEquals(buckets.size(), filters.length+1);
|
||||
|
||||
int sum = 0;
|
||||
for (InternalFilters.InternalBucket bucket : buckets) {
|
||||
if ("other".equals(bucket.getKey())) {
|
||||
assertEquals(bucket.getDocCount(), expectedOtherCount);
|
||||
} else {
|
||||
int index = Integer.parseInt(bucket.getKey());
|
||||
assertEquals(bucket.getDocCount(), (long) expectedBucketCount[filterTerms[index]]);
|
||||
sum += expectedBucketCount[filterTerms[index]];
|
||||
try {
|
||||
int numFilters = randomIntBetween(1, 10);
|
||||
QueryBuilder[] filters = new QueryBuilder[numFilters];
|
||||
int[] filterTerms = new int[numFilters];
|
||||
int expectedOtherCount = numDocs;
|
||||
Set<Integer> filterSet = new HashSet<>();
|
||||
for (int i = 0; i < filters.length; i++) {
|
||||
int value = randomInt(maxTerm - 1);
|
||||
filters[i] = QueryBuilders.termQuery("field", Integer.toString(value));
|
||||
filterTerms[i] = value;
|
||||
if (filterSet.contains(value) == false) {
|
||||
expectedOtherCount -= expectedBucketCount[value];
|
||||
filterSet.add(value);
|
||||
}
|
||||
}
|
||||
if (sum > 0) {
|
||||
assertTrue(AggregationInspectionHelper.hasValue(response));
|
||||
} else {
|
||||
assertFalse(AggregationInspectionHelper.hasValue(response));
|
||||
}
|
||||
FiltersAggregationBuilder builder = new FiltersAggregationBuilder("test", filters);
|
||||
builder.otherBucket(true);
|
||||
builder.otherBucketKey("other");
|
||||
|
||||
for (boolean doReduce : new boolean[]{true, false}) {
|
||||
final InternalFilters response;
|
||||
if (doReduce) {
|
||||
response = searchAndReduce(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
|
||||
} else {
|
||||
response = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
|
||||
}
|
||||
List<InternalFilters.InternalBucket> buckets = response.getBuckets();
|
||||
assertEquals(buckets.size(), filters.length + 1);
|
||||
|
||||
for (InternalFilters.InternalBucket bucket : buckets) {
|
||||
if ("other".equals(bucket.getKey())) {
|
||||
assertEquals(bucket.getDocCount(), expectedOtherCount);
|
||||
} else {
|
||||
int index = Integer.parseInt(bucket.getKey());
|
||||
assertEquals(bucket.getDocCount(), (long) expectedBucketCount[filterTerms[index]]);
|
||||
}
|
||||
}
|
||||
|
||||
// Always true because we include 'other' in the agg
|
||||
assertTrue(AggregationInspectionHelper.hasValue(response));
|
||||
}
|
||||
} finally {
|
||||
indexReader.close();
|
||||
directory.close();
|
||||
}
|
||||
indexReader.close();
|
||||
directory.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,7 +174,11 @@ public class NestedAggregatorTests extends AggregatorTestCase {
|
|||
assertEquals(MAX_AGG_NAME, max.getName());
|
||||
assertEquals(expectedMaxValue, max.getValue(), Double.MIN_VALUE);
|
||||
|
||||
assertTrue(AggregationInspectionHelper.hasValue(nested));
|
||||
if (expectedNestedDocs > 0) {
|
||||
assertTrue(AggregationInspectionHelper.hasValue(nested));
|
||||
} else {
|
||||
assertFalse(AggregationInspectionHelper.hasValue(nested));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,7 +228,11 @@ public class NestedAggregatorTests extends AggregatorTestCase {
|
|||
assertEquals(MAX_AGG_NAME, max.getName());
|
||||
assertEquals(expectedMaxValue, max.getValue(), Double.MIN_VALUE);
|
||||
|
||||
assertTrue(AggregationInspectionHelper.hasValue(nested));
|
||||
if (expectedNestedDocs > 0) {
|
||||
assertTrue(AggregationInspectionHelper.hasValue(nested));
|
||||
} else {
|
||||
assertFalse(AggregationInspectionHelper.hasValue(nested));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue