Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.apache.lucene.document.StringField;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.util.NumericUtils;
Expand Down Expand Up @@ -41,7 +40,7 @@ public void testNoData() throws Exception {
MatrixStatsAggregationBuilder aggBuilder = new MatrixStatsAggregationBuilder("my_agg").fields(
Collections.singletonList("field")
);
InternalMatrixStats stats = searchAndReduce(searcher, new MatchAllDocsQuery(), aggBuilder, ft);
InternalMatrixStats stats = searchAndReduce(new AggTestConfig(searcher, aggBuilder, ft));
assertNull(stats.getStats());
assertEquals(0L, stats.getDocCount());
}
Expand All @@ -60,7 +59,7 @@ public void testUnmapped() throws Exception {
MatrixStatsAggregationBuilder aggBuilder = new MatrixStatsAggregationBuilder("my_agg").fields(
Collections.singletonList("bogus")
);
InternalMatrixStats stats = searchAndReduce(searcher, new MatchAllDocsQuery(), aggBuilder, ft);
InternalMatrixStats stats = searchAndReduce(new AggTestConfig(searcher, aggBuilder, ft));
assertNull(stats.getStats());
assertEquals(0L, stats.getDocCount());
}
Expand Down Expand Up @@ -95,7 +94,7 @@ public void testTwoFields() throws Exception {
MatrixStatsAggregationBuilder aggBuilder = new MatrixStatsAggregationBuilder("my_agg").fields(
Arrays.asList(fieldA, fieldB)
);
InternalMatrixStats stats = searchAndReduce(searcher, new MatchAllDocsQuery(), aggBuilder, ftA, ftB);
InternalMatrixStats stats = searchAndReduce(new AggTestConfig(searcher, aggBuilder, ftA, ftB));
multiPassStats.assertNearlyEqual(stats);
assertTrue(MatrixAggregationInspectionHelper.hasValue(stats));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private void testCase(Query query, IndexSearcher indexSearcher, Consumer<Interna
aggregationBuilder.subAggregation(new MinAggregationBuilder("in_parent").field("number"));

MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
InternalParent result = searchAndReduce(indexSearcher, query, aggregationBuilder, withJoinFields(fieldType));
InternalParent result = searchAndReduce(new AggTestConfig(indexSearcher, query, aggregationBuilder, withJoinFields(fieldType)));
verify.accept(result);
}

Expand All @@ -278,7 +278,7 @@ private void testCaseTerms(Query query, IndexSearcher indexSearcher, Consumer<In
aggregationBuilder.subAggregation(new TermsAggregationBuilder("value_terms").field("number"));

MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
InternalParent result = searchAndReduce(indexSearcher, query, aggregationBuilder, withJoinFields(fieldType));
InternalParent result = searchAndReduce(new AggTestConfig(indexSearcher, query, aggregationBuilder, withJoinFields(fieldType)));
verify.accept(result);
}

Expand All @@ -293,7 +293,9 @@ private void testCaseTermsParentTerms(Query query, IndexSearcher indexSearcher,

MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
MappedFieldType subFieldType = new NumberFieldMapper.NumberFieldType("subNumber", NumberFieldMapper.NumberType.LONG);
LongTerms result = searchAndReduce(indexSearcher, query, aggregationBuilder, withJoinFields(fieldType, subFieldType));
LongTerms result = searchAndReduce(
new AggTestConfig(indexSearcher, query, aggregationBuilder, withJoinFields(fieldType, subFieldType))
);
verify.accept(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ public void testParentChildAsSubAgg() throws IOException {
expectedOddMin = Math.min(expectedOddMin, e.getValue().v2());
}
}
StringTerms result = searchAndReduce(
indexSearcher,
new MatchAllDocsQuery(),
request,
withJoinFields(longField("number"), kwd)
);
StringTerms result = searchAndReduce(new AggTestConfig(indexSearcher, request, withJoinFields(longField("number"), kwd)));

StringTerms.Bucket evenBucket = result.getBucketByKey("even");
InternalChildren evenChildren = evenBucket.getAggregations().get("children");
Expand Down Expand Up @@ -209,10 +204,12 @@ public void testBestDeferringCollectorWithSubAggOfChildrenAggNeedingScores() thr
var e = expectThrows(
RuntimeException.class,
() -> searchAndReduce(
indexSearcher,
new TermQuery(new Term("join_field", "parent_type")),
aggregationBuilder,
withJoinFields(fieldType, fieldType2)
new AggTestConfig(
indexSearcher,
new TermQuery(new Term("join_field", "parent_type")),
aggregationBuilder,
withJoinFields(fieldType, fieldType2)
)
)
);
assertThat(
Expand All @@ -239,10 +236,12 @@ public void testBestDeferringCollectorWithSubAggOfChildrenAggNeedingScores() thr
var fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
var fieldType2 = new KeywordFieldMapper.KeywordFieldType("string_field", false, true, Map.of());
InternalChildren result = searchAndReduce(
indexSearcher,
new TermQuery(new Term("join_field", "parent_type")),
aggregationBuilder,
withJoinFields(fieldType, fieldType2)
new AggTestConfig(
indexSearcher,
new TermQuery(new Term("join_field", "parent_type")),
aggregationBuilder,
withJoinFields(fieldType, fieldType2)
)
);

Terms terms = result.getAggregations().get("_name2");
Expand Down Expand Up @@ -312,7 +311,7 @@ private void testCase(Query query, IndexSearcher indexSearcher, Consumer<Interna
aggregationBuilder.subAggregation(new MinAggregationBuilder("in_child").field("number"));

MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
InternalChildren result = searchAndReduce(indexSearcher, query, aggregationBuilder, withJoinFields(fieldType));
InternalChildren result = searchAndReduce(new AggTestConfig(indexSearcher, query, aggregationBuilder, withJoinFields(fieldType)));
verify.accept(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
public class CompositeAggregatorTests extends AggregatorTestCase {
private static MappedFieldType[] FIELD_TYPES;
private List<ObjectMapper> objectMappers;
private Sort indexSort;

@Override
@Before
Expand Down Expand Up @@ -3295,8 +3296,7 @@ private <T extends AggregationBuilder, V extends InternalAggregation> void execu
assert create.size() == verify.size() : "create and verify should be the same size";
Map<String, MappedFieldType> types = Arrays.stream(FIELD_TYPES)
.collect(Collectors.toMap(MappedFieldType::name, Function.identity()));
Sort indexSort = useIndexSort ? buildIndexSort(sources, types) : null;
IndexSettings indexSettings = createIndexSettings(indexSort);
indexSort = useIndexSort ? buildIndexSort(sources, types) : null;
try (Directory directory = newDirectory()) {
IndexWriterConfig config = newIndexWriterConfig(random(), new MockAnalyzer(random()));
if (indexSort != null) {
Expand Down Expand Up @@ -3335,17 +3335,18 @@ private <T extends AggregationBuilder, V extends InternalAggregation> void execu
try (IndexReader indexReader = DirectoryReader.open(directory)) {
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
for (int i = 0; i < create.size(); i++) {
verify.get(i).accept(searchAndReduce(indexSettings, indexSearcher, query, create.get(i).get(), FIELD_TYPES));
verify.get(i).accept(searchAndReduce(new AggTestConfig(indexSearcher, query, create.get(i).get(), FIELD_TYPES)));
}
}
}
}

private static IndexSettings createIndexSettings(Sort sort) {
@Override
protected IndexSettings createIndexSettings() {
Settings.Builder builder = Settings.builder();
if (sort != null) {
String[] fields = Arrays.stream(sort.getSort()).map(SortField::getField).toArray(String[]::new);
String[] orders = Arrays.stream(sort.getSort()).map((o) -> o.getReverse() ? "desc" : "asc").toArray(String[]::new);
if (indexSort != null) {
String[] fields = Arrays.stream(indexSort.getSort()).map(SortField::getField).toArray(String[]::new);
String[] orders = Arrays.stream(indexSort.getSort()).map((o) -> o.getReverse() ? "desc" : "asc").toArray(String[]::new);
builder.putList("index.sort.field", fields);
builder.putList("index.sort.order", orders);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.elasticsearch.index.mapper.KeywordFieldMapper;
Expand Down Expand Up @@ -52,7 +51,7 @@ public void testEmpty() throws Exception {
IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
QueryBuilder filter = QueryBuilders.termQuery("field", randomAlphaOfLength(5));
FilterAggregationBuilder builder = new FilterAggregationBuilder("test", filter);
InternalFilter response = searchAndReduce(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
InternalFilter response = searchAndReduce(new AggTestConfig(indexSearcher, builder, fieldType));
assertEquals(response.getDocCount(), 0);
assertFalse(AggregationInspectionHelper.hasValue(response));
indexReader.close();
Expand Down Expand Up @@ -87,7 +86,7 @@ public void testRandom() throws Exception {
QueryBuilder filter = QueryBuilders.termQuery("field", Integer.toString(value));
FilterAggregationBuilder builder = new FilterAggregationBuilder("test", filter);

final InternalFilter response = searchAndReduce(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
final InternalFilter response = searchAndReduce(new AggTestConfig(indexSearcher, builder, fieldType));
assertEquals(response.getDocCount(), (long) expectedBucketCount[value]);
if (expectedBucketCount[value] > 0) {
assertTrue(AggregationInspectionHelper.hasValue(response));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ public void testEmpty() throws Exception {
FiltersAggregationBuilder builder = new FiltersAggregationBuilder("test", filters);
builder.otherBucketKey("other");
InternalFilters response = searchAndReduce(
indexSearcher,
new MatchAllDocsQuery(),
builder,
new KeywordFieldMapper.KeywordFieldType("field")
new AggTestConfig(indexSearcher, new MatchAllDocsQuery(), builder, new KeywordFieldType("field"))
);
assertEquals(response.getBuckets().size(), numFilters);
for (InternalFilters.InternalBucket filter : response.getBuckets()) {
Expand Down Expand Up @@ -221,10 +218,7 @@ public void testKeyedFilter() throws Exception {
builder.otherBucket(true);
builder.otherBucketKey("other");
final InternalFilters filters = searchAndReduce(
indexSearcher,
new MatchAllDocsQuery(),
builder,
new KeywordFieldMapper.KeywordFieldType("field")
new AggTestConfig(indexSearcher, new MatchAllDocsQuery(), builder, new KeywordFieldType("field"))
);
assertEquals(filters.getBuckets().size(), 7);
assertEquals(filters.getBucketByKey("foobar").getDocCount(), 2);
Expand Down Expand Up @@ -281,10 +275,7 @@ public void testRandom() throws Exception {
builder.otherBucketKey("other");

final InternalFilters response = searchAndReduce(
indexSearcher,
new MatchAllDocsQuery(),
builder,
new KeywordFieldMapper.KeywordFieldType("field")
new AggTestConfig(indexSearcher, new MatchAllDocsQuery(), builder, new KeywordFieldType("field"))
);
List<InternalFilters.InternalBucket> buckets = response.getBuckets();
assertEquals(buckets.size(), filters.length + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -942,12 +942,7 @@ private void testSearchCase(
MappedFieldType numericFieldType = new NumberFieldMapper.NumberFieldType(NUMERIC_FIELD, NumberFieldMapper.NumberType.LONG);

final InternalAutoDateHistogram histogram = searchAndReduce(
indexSearcher,
query,
aggregationBuilder,
fieldType,
instantFieldType,
numericFieldType
new AggTestConfig(indexSearcher, query, aggregationBuilder, fieldType, instantFieldType, numericFieldType)
);
verify.accept(histogram);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,9 @@ private void testSearchCase(
configure.accept(aggregationBuilder);
}

InternalDateHistogram histogram = searchAndReduce(indexSearcher, query, aggregationBuilder, maxBucket, fieldType);
InternalDateHistogram histogram = searchAndReduce(
new AggTestConfig(indexSearcher, query, aggregationBuilder, fieldType).withMaxBuckets(maxBucket)
);
verify.accept(histogram);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ private void testCase(
try (IndexReader indexReader = DirectoryReader.open(directory)) {
IndexSearcher indexSearcher = newSearcher(indexReader, true, true);

InternalDateHistogram histogram = searchAndReduce(indexSearcher, query, aggregationBuilder, fieldType);
InternalDateHistogram histogram = searchAndReduce(new AggTestConfig(indexSearcher, query, aggregationBuilder, fieldType));
verify.accept(histogram);
}
}
Expand Down
Loading