当前位置:网站首页>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();
}
边栏推荐
- twenty million two hundred and twenty thousand three hundred and nineteen
- 【已解决】Unknown error 1146
- 【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
- Unified handling and interception of exception exceptions of vertx
- FileInputStream and fileoutputstream
- 你开发数据API最快多长时间?我1分钟就足够了
- Hisat2 - stringtie - deseq2 pipeline for bulk RNA seq
- 2. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
- C代码生产YUV420 planar格式文件
- How long is the fastest time you can develop data API? One minute is enough for me
猜你喜欢
Reconnaissance et détection d'images - Notes
【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
为什么说数据服务化是下一代数据中台的方向?
691. Cube IV
How long is the fastest time you can develop data API? One minute is enough for me
SecureCRT password to cancel session recording
Margin left: -100% understanding in the Grail layout
Introduction of transformation flow
Use of generics
New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
随机推荐
1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
Pgadmin 4 v6.11 release, PostgreSQL open source graphical management tool
TreeMap
带你全流程,全方位的了解属于测试的软件事故
High concurrency memory pool
Vertx's responsive redis client
Vertx restful style web router
SQL create temporary table
【无标题】
Responsive MySQL of vertx
GStreamer ffmpeg avdec decoded data flow analysis
【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
Visit Google homepage to display this page, which cannot be displayed
New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears
"Moss ma not found" solution
Lombok cooperates with @slf4j and logback to realize logging
《指环王:力量之戒》新剧照 力量之戒铸造者亮相
Take you through the whole process and comprehensively understand the software accidents that belong to testing
TCP cumulative acknowledgement and window value update
【已解决】win10找不到本地组策略编辑器解决方法