当前位置:网站首页>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();
}边栏推荐
- [HCAI] learning summary OSI model
- Use of file class
- 《指環王:力量之戒》新劇照 力量之戒鑄造者亮相
- docket
- 4EVERLAND:IPFS 上的 Web3 开发者中心,部署了超过 30,000 个 Dapp!
- SharePoint modification usage analysis report is more than 30 days
- 7.2刷题两个
- 【开发笔记】基于机智云4G转接板GC211的设备上云APP控制
- [solved] sqlexception: invalid value for getint() - 'Tian Peng‘
- GStreamer ffmpeg avdec decoded data flow analysis
猜你喜欢

Basic knowledge about SQL database
![[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)](/img/d8/b4f39d9637c9886a8c81ca125d6944.jpg)
[set theory] Stirling subset number (Stirling subset number concept | ball model | Stirling subset number recurrence formula | binary relationship refinement relationship of division)

HCIA notes

Reconnaissance et détection d'images - Notes

Circuit, packet and message exchange

7.2 brush two questions

New stills of Lord of the rings: the ring of strength: the caster of the ring of strength appears

Introduction of transformation flow

Deep learning parameter initialization (I) Xavier initialization with code

Docker builds MySQL: the specified path of version 5.7 cannot be mounted.
随机推荐
The babbage industrial policy forum
JS monitors empty objects and empty references
【最詳細】最新最全Redis面試大全(50道)
Qtip2 solves the problem of too many texts
C代码生产YUV420 planar格式文件
gstreamer ffmpeg avdec解码数据流向分析
[solved] sqlexception: invalid value for getint() - 'Tian Peng‘
Some basic operations of reflection
IPv4 address
HISAT2 - StringTie - DESeq2 pipeline 进行bulk RNA-seq
专题 | 同步 异步
Introduction of buffer flow
High concurrency memory pool
Le Seigneur des anneaux: l'anneau du pouvoir
File operation serialization recursive copy
Raspberry pie update tool chain
Logging log configuration of vertx
带你全流程,全方位的了解属于测试的软件事故
SQL create temporary table
Final, override, polymorphism, abstraction, interface