当前位置:网站首页>Implementation of breadth first in aggregation in ES
Implementation of breadth first in aggregation in ES
2022-07-03 07:30:00 【chuanyangwang】
{
"size": 0,
"aggs": {
"all_speaker": {
"terms": {
"field": "speaker",
"size": 5
},
"aggs": {
"avg_speech": {
"avg": {
"field": "speech_number"
}
}
}
}
}
}First step : First of all, I will use org.elasticsearch.search.aggregations.LeafBucketCollector#collect Methods collect all all_speaker The data in the bucket
return new LeafBucketCollector() {
int lastDoc = 0;
@Override
public void collect(int doc, long bucket) throws IOException {
if (context == null) {
context = ctx;
docDeltasBuilder = PackedLongValues.packedBuilder(PackedInts.DEFAULT);
bucketsBuilder = PackedLongValues.packedBuilder(PackedInts.DEFAULT);
}
docDeltasBuilder.add(doc - lastDoc);
bucketsBuilder.add(bucket);
lastDoc = doc;
maxBucket = Math.max(maxBucket, bucket);
}
};The second step : Replay collected data , Only deal with the barrels that survived the last round selectedBuckets
/**
* Replay the wrapped collector, but only on a selection of buckets.
*/
@Override
public void prepareSelectedBuckets(long... selectedBuckets) throws IOException {
if (finished == false) {
throw new IllegalStateException("Cannot replay yet, collection is not finished: postCollect() has not been called");
}
if (this.selectedBuckets != null) {
throw new IllegalStateException("Already been replayed");
}
final LongHash hash = new LongHash(selectedBuckets.length, BigArrays.NON_RECYCLING_INSTANCE);
for (long bucket : selectedBuckets) {
hash.add(bucket);
}
this.selectedBuckets = hash;
boolean needsScores = scoreMode().needsScores();
Weight weight = null;
if (needsScores) {
Query query = isGlobal ? new MatchAllDocsQuery() : searchContext.query();
weight = searchContext.searcher().createWeight(searchContext.searcher().rewrite(query), ScoreMode.COMPLETE, 1f);
}
for (Entry entry : entries) {
assert entry.docDeltas.size() > 0 : "segment should have at least one document to replay, got 0";
try {
final LeafBucketCollector leafCollector = collector.getLeafCollector(entry.context);
DocIdSetIterator scoreIt = null;
if (needsScores) {
Scorer scorer = weight.scorer(entry.context);
// We don't need to check if the scorer is null
// since we are sure that there are documents to replay (entry.docDeltas it not empty).
scoreIt = scorer.iterator();
leafCollector.setScorer(scorer);
}
final PackedLongValues.Iterator docDeltaIterator = entry.docDeltas.iterator();
final PackedLongValues.Iterator buckets = entry.buckets.iterator();
int doc = 0;
for (long i = 0, end = entry.docDeltas.size(); i < end; ++i) {
doc += docDeltaIterator.next();
final long bucket = buckets.next();
final long rebasedBucket = hash.find(bucket);
if (rebasedBucket != -1) {
if (needsScores) {
if (scoreIt.docID() < doc) {
scoreIt.advance(doc);
}
// aggregations should only be replayed on matching documents
assert scoreIt.docID() == doc;
}
leafCollector.collect(doc, rebasedBucket);
}
}
} catch (CollectionTerminatedException e) {
// collection was terminated prematurely
// continue with the following leaf
}
}
collector.postCollection();
}边栏推荐
- Circuit, packet and message exchange
- 带你全流程,全方位的了解属于测试的软件事故
- Final, override, polymorphism, abstraction, interface
- New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
- Use of generics
- IO stream system and FileReader, filewriter
- Arduino Serial系列函数 有关print read 的总结
- Web router of vertx
- Lombok cooperates with @slf4j and logback to realize logging
- II. D3.js draw a simple figure -- circle
猜你喜欢

Use of other streams

Deep learning parameter initialization (I) Xavier initialization with code

Pat grade a real problem 1166

File operation serialization recursive copy

Take you through the whole process and comprehensively understand the software accidents that belong to testing

C code production YUV420 planar format file

【CoppeliaSim4.3】C#调用 remoteApi控制场景中UR5
![PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef](/img/65/1f28071fc15e76abb37f1b128e1d90.jpg)
PdfWriter. GetInstance throws system Nullreferenceexception [en] pdfwriter GetInstance throws System. NullRef

Summary of abnormal mechanism of interview

Map interface and method
随机推荐
JS monitors empty objects and empty references
Store WordPress media content on 4everland to complete decentralized storage
【CMake】CMake链接SQLite库
Vertx's responsive MySQL template
Responsive MySQL of vertx
IP home online query platform
Web router of vertx
Beginners use Minio
"Moss ma not found" solution
Vertx's responsive redis client
GStreamer ffmpeg avdec decoded data flow analysis
Vertx restful style web router
SQL create temporary table
LeetCode
TCP cumulative acknowledgement and window value update
[Development Notes] cloud app control on device based on smart cloud 4G adapter gc211
Win 2008 R2 crashed at the final installation stage
20220319
An overview of IfM Engage
[most detailed] latest and complete redis interview book (50)