当前位置:网站首页>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();
}边栏推荐
- Jeecg request URL signature
- Arduino Serial系列函数 有关print read 的总结
- C WinForm framework
- Qtip2 solves the problem of too many texts
- Visit Google homepage to display this page, which cannot be displayed
- FileInputStream and fileoutputstream
- Jeecg data button permission settings
- Realize the reuse of components with different routing parameters and monitor the changes of routing parameters
- Common problems in io streams
- The underlying mechanism of advertising on websites
猜你喜欢

Use of other streams

Summary of abnormal mechanism of interview

7.2刷题两个

TreeMap

Basic knowledge about SQL database

为什么说数据服务化是下一代数据中台的方向?

The embodiment of generics in inheritance and wildcards

Le Seigneur des anneaux: l'anneau du pouvoir
![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

Margin left: -100% understanding in the Grail layout
随机推荐
High concurrency memory pool
不出网上线CS的各种姿势
【CMake】CMake链接SQLite库
Visit Google homepage to display this page, which cannot be displayed
Arduino Serial系列函数 有关print read 的总结
C WinForm framework
《指环王:力量之戒》新剧照 力量之戒铸造者亮相
URL programming
Sent by mqtt client server of vertx
c语言指针的概念
[most detailed] latest and complete redis interview book (50)
4everland: the Web3 Developer Center on IPFs has deployed more than 30000 dapps!
【最详细】最新最全Redis面试大全(50道)
IPv4 address
1. E-commerce tool cefsharp autojs MySQL Alibaba cloud react C RPA automated script, open source log
Vertx's responsive redis client
TreeMap
VMWare网络模式-桥接,Host-Only,NAT网络
Circuit, packet and message exchange
Spa single page application