Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure non-collecting aggs include sub-aggs (backport of #64214) #64244

Merged
merged 5 commits into from
Oct 29, 2020
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 @@ -60,7 +60,7 @@ public ChildrenAggregatorFactory(String name,

@Override
protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map<String, Object> metadata) throws IOException {
return new NonCollectingAggregator(name, searchContext, parent, metadata) {
return new NonCollectingAggregator(name, searchContext, parent, factories, metadata) {
@Override
public InternalAggregation buildEmptyAggregation() {
return new InternalChildren(name, 0, buildEmptySubAggregations(), metadata());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public ParentAggregatorFactory(String name,

@Override
protected Aggregator createUnmapped(SearchContext searchContext, Aggregator parent, Map<String, Object> metadata) throws IOException {
return new NonCollectingAggregator(name, searchContext, parent, metadata) {
return new NonCollectingAggregator(name, searchContext, parent, factories, metadata) {
@Override
public InternalAggregation buildEmptyAggregation() {
return new InternalParent(name, 0, buildEmptySubAggregations(), metadata());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,43 @@ setup:
- match: { aggregations.age_groups.buckets.2.key: "Generation Y" }

- match: { aggregations.age_groups.buckets.2.doc_count: 2 }


---
"Date range unmapped with children":
- skip:
version: " - 7.9.99"
reason: Fixed in 7.10.0

- do:
indices.create:
index: test_a_unmapped
body:
settings:
number_of_shards: 1
number_of_replicas: 0
- do:
search:
index: test_a_unmapped
body:
size: 0
query:
terms:
animal: []
aggs:
date_range:
date_range:
field: date
ranges:
- from: 2020-01-01T00:00:00Z
aggs:
sounds:
cardinality:
field: sound.keyword

- match: { hits.total.value: 0 }
- length: { aggregations.date_range.buckets: 1 }
- match: { aggregations.date_range.buckets.0.doc_count: 0 }
- match: { aggregations.date_range.buckets.0.key: "2020-01-01T00:00:00.000Z-*" }
- is_false: aggregations.date_range.buckets.0.to
- match: { aggregations.date_range.buckets.0.sounds.value: 0 }
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ protected NonCollectingAggregator(String name, SearchContext context, Aggregator
super(name, subFactories, context, parent, CardinalityUpperBound.NONE, metadata);
}

/**
* Build a {@linkplain NonCollectingAggregator} for an aggregator without sub-aggregators.
*/
protected NonCollectingAggregator(String name, SearchContext context, Aggregator parent,
Map<String, Object> metadata) throws IOException {
this(name, context, parent, AggregatorFactories.EMPTY, metadata);
}

@Override
public final LeafBucketCollector getLeafCollector(LeafReaderContext reader, LeafBucketCollector sub) {
// the framework will automatically eliminate it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected Aggregator createUnmapped(SearchContext searchContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
final InternalAggregation aggregation = new InternalGeoHashGrid(name, requiredSize, emptyList(), metadata);
return new NonCollectingAggregator(name, searchContext, parent, metadata) {
return new NonCollectingAggregator(name, searchContext, parent, factories, metadata) {
@Override
public InternalAggregation buildEmptyAggregation() {
return aggregation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected Aggregator createUnmapped(SearchContext searchContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
final InternalAggregation aggregation = new InternalGeoTileGrid(name, requiredSize, Collections.emptyList(), metadata);
return new NonCollectingAggregator(name, searchContext, parent, metadata) {
return new NonCollectingAggregator(name, searchContext, parent, factories, metadata) {
@Override
public InternalAggregation buildEmptyAggregation() {
return aggregation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Aggregator createInternal(SearchContext searchContext,
CardinalityUpperBound cardinality,
Map<String, Object> metadata) throws IOException {
if (childObjectMapper == null) {
return new Unmapped(name, searchContext, parent, metadata);
return new Unmapped(name, searchContext, parent, factories, metadata);
}
return new NestedAggregator(name, factories, parentObjectMapper, childObjectMapper, searchContext, parent,
cardinality, metadata);
Expand All @@ -62,8 +62,9 @@ private static final class Unmapped extends NonCollectingAggregator {
Unmapped(String name,
SearchContext context,
Aggregator parent,
AggregatorFactories factories,
Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
super(name, context, parent, factories, metadata);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public Aggregator createInternal(SearchContext searchContext,
CardinalityUpperBound cardinality,
Map<String, Object> metadata) throws IOException {
if (unmapped) {
return new Unmapped(name, searchContext, parent, metadata);
return new Unmapped(name, searchContext, parent, factories, metadata);
} else {
return new ReverseNestedAggregator(name, factories, parentObjectMapper,
searchContext, parent, cardinality, metadata);
Expand All @@ -64,8 +64,9 @@ private static final class Unmapped extends NonCollectingAggregator {
Unmapped(String name,
SearchContext context,
Aggregator parent,
AggregatorFactories factories,
Map<String, Object> metadata) throws IOException {
super(name, context, parent, metadata);
super(name, context, parent, factories, metadata);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public AbstractRangeAggregatorFactory(String name,
protected Aggregator createUnmapped(SearchContext searchContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new Unmapped<>(name, ranges, keyed, config.format(), searchContext, parent, rangeFactory, metadata);
return new Unmapped<>(name, factories, ranges, keyed, config.format(), searchContext, parent, rangeFactory, metadata);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public GeoDistanceRangeAggregatorFactory(String name, ValuesSourceConfig config,
protected Aggregator createUnmapped(SearchContext searchContext,
Aggregator parent,
Map<String, Object> metadata) throws IOException {
return new RangeAggregator.Unmapped<>(name, ranges, keyed, config.format(), searchContext, parent,
return new RangeAggregator.Unmapped<>(name, factories, ranges, keyed, config.format(), searchContext, parent,
rangeFactory, metadata);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,19 @@ public static class Unmapped<R extends RangeAggregator.Range> extends NonCollect
private final InternalRange.Factory factory;
private final DocValueFormat format;

public Unmapped(String name, R[] ranges, boolean keyed, DocValueFormat format, SearchContext context, Aggregator parent,
InternalRange.Factory factory, Map<String, Object> metadata)
throws IOException {

super(name, context, parent, metadata);
public Unmapped(
String name,
AggregatorFactories factories,
R[] ranges,
boolean keyed,
DocValueFormat format,
SearchContext context,
Aggregator parent,
InternalRange.Factory factory,
Map<String, Object> metadata
) throws IOException {

super(name, context, parent, factories, metadata);
this.ranges = ranges;
this.keyed = keyed;
this.format = format;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ protected Aggregator createUnmapped(SearchContext searchContext,
Map<String, Object> metadata) throws IOException {
final InternalAggregation aggregation = new UnmappedSignificantTerms(name, bucketCountThresholds.getRequiredSize(),
bucketCountThresholds.getMinDocCount(), metadata);
return new NonCollectingAggregator(name, searchContext, parent, metadata) {
return new NonCollectingAggregator(name, searchContext, parent, factories, metadata) {
@Override
public InternalAggregation buildEmptyAggregation() {
return aggregation;
Expand Down