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 @@ -4,6 +4,7 @@ setup:
index: test
body:
settings:
number_of_shards: 1
number_of_replicas: 0
mappings:
properties:
Expand Down Expand Up @@ -75,3 +76,25 @@ setup:
- match: { aggregations.histo.buckets.1.doc_count: 2 }
- match: { aggregations.histo.buckets.1.v.value: 7 }
- match: { aggregations.histo_avg_v.value: 5 }

---
"profile at top level":
- skip:
version: " - 7.99.99"
reason: Debug information added in 8.0.0 (to be backported to 7.9.0)

- do:
search:
body:
profile: true
size: 0
aggs:
histo:
auto_date_histogram:
field: date
buckets: 2

- match: { hits.total.value: 4 }
- length: { aggregations.histo.buckets: 2 }
- match: { profile.shards.0.aggregations.0.type: AutoDateHistogramAggregator.FromSingle }
- match: { profile.shards.0.aggregations.0.debug.surviving_buckets: 4 }
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.InternalAggregations;
import org.elasticsearch.search.aggregations.LeafBucketCollector;
import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator;
import org.elasticsearch.search.aggregations.bucket.terms.LongKeyedBucketOrds;
import org.elasticsearch.search.aggregations.support.AggregationPath;
import org.elasticsearch.search.internal.SearchContext;
Expand Down Expand Up @@ -329,7 +330,7 @@ protected final <B> InternalAggregation[] buildAggregationsForVariableBuckets(lo
* @param bucketOrds hash of values to the bucket ordinal
*/
protected final <B> InternalAggregation[] buildAggregationsForVariableBuckets(long[] owningBucketOrds, LongKeyedBucketOrds bucketOrds,
BucketBuilderForVariable<B> bucketBuilder, Function<List<B>, InternalAggregation> resultBuilder) throws IOException {
BucketBuilderForVariable<B> bucketBuilder, ResultBuilderForVariable<B> resultBuilder) throws IOException {
long totalOrdsToCollect = 0;
for (int ordIdx = 0; ordIdx < owningBucketOrds.length; ordIdx++) {
totalOrdsToCollect += bucketOrds.bucketsInOrd(owningBucketOrds[ordIdx]);
Expand Down Expand Up @@ -360,14 +361,18 @@ protected final <B> InternalAggregation[] buildAggregationsForVariableBuckets(lo
}
buckets.add(bucketBuilder.build(ordsEnum.value(), bucketDocCount(ordsEnum.ord()), subAggregationResults[b++]));
}
results[ordIdx] = resultBuilder.apply(buckets);
results[ordIdx] = resultBuilder.build(owningBucketOrds[ordIdx], buckets);
}
return results;
}
@FunctionalInterface
protected interface BucketBuilderForVariable<B> {
B build(long bucketValue, int docCount, InternalAggregations subAggregationResults);
}
@FunctionalInterface
protected interface ResultBuilderForVariable<B> {
InternalAggregation build(long owninigBucketOrd, List<B> buckets);
}

/**
* Utility method to build empty aggregations of the sub aggregators.
Expand Down Expand Up @@ -407,4 +412,15 @@ public BucketComparator bucketComparator(String key, SortOrder order) {
"Either drop the key (a la \"" + name() + "\") or change it to \"doc_count\" (a la \"" + name() +
".doc_count\") or \"key\".");
}

public static boolean descendsFromGlobalAggregator(Aggregator parent) {
while (parent != null) {
if (parent.getClass() == GlobalAggregator.class) {
return true;
}
parent = parent.parent();
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.aggregations.BucketCollector;
import org.elasticsearch.search.aggregations.MultiBucketCollector;
import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregator;
import org.elasticsearch.search.internal.SearchContext;

import java.io.IOException;
Expand Down Expand Up @@ -70,16 +69,6 @@ protected void doPreCollection() throws IOException {
collectableSubAggregators = MultiBucketCollector.wrap(collectors);
}

public static boolean descendsFromGlobalAggregator(Aggregator parent) {
while (parent != null) {
if (parent.getClass() == GlobalAggregator.class) {
return true;
}
parent = parent.parent();
}
return false;
}

public DeferringBucketCollector getDeferringCollector() {
// Default impl is a collector that selects the best buckets
// but an alternative defer policy may be based on best docs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public InternalAggregation[] buildAggregations(long[] owningBucketOrds) throws I
double roundKey = Double.longBitsToDouble(bucketValue);
double key = roundKey * interval + offset;
return new InternalHistogram.Bucket(key, docCount, keyed, formatter, subAggregationResults);
}, buckets -> {
}, (owningBucketOrd, buckets) -> {
// the contract of the histogram aggregation is that shards must return buckets ordered by key in ascending order
CollectionUtil.introSort(buckets, BucketOrder.key(true).comparator());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ public long getRoughEstimateDurationMillis() {
return roughEstimateDurationMillis;
}

public long getMaximumRoughEstimateDurationMillis() {
return getRoughEstimateDurationMillis() * getMaximumInnerInterval();
}

@Override
public int hashCode() {
return Objects.hash(rounding, Arrays.hashCode(innerIntervals), dateTimeUnit);
Expand Down
Loading