网站二级域名建站属于子站吗,泰州网站建设托管,海淘网站入口,百度搜不到 但搜关键词有的网站SpringBoot ES 聚合后多字段加减乘除 在SpringData Elasticsearch中#xff0c;聚合统计的原理主要依赖于Elasticsearch本身的聚合框架。Elasticsearch提供了强大的聚合功能#xff0c;使得你可以对文档进行各种计算和统计#xff0c;从而得到有关数据集的有用信息。
Elast… SpringBoot ES 聚合后多字段加减乘除 在SpringData Elasticsearch中聚合统计的原理主要依赖于Elasticsearch本身的聚合框架。Elasticsearch提供了强大的聚合功能使得你可以对文档进行各种计算和统计从而得到有关数据集的有用信息。
Elasticsearch的聚合Aggregation是一种强大的数据分析和统计工具它允许你对文档集合进行多层次、多维度的计算和分析。聚合的原理可以分为以下几个方面
关键词原理桶Buckets桶是聚合的基本单元它将文档分组到不同的集合中这些集合称为桶。桶可以按照不同的标准进行分组比如词条、范围、日期等。度量Metrics除了桶聚合还可以返回一些度量结果如总和、平均值、最大值、最小值等。度量通常与桶结合使用以提供更详细的统计信息。Pipeline AggregationsElasticsearch支持通过管道pipeline对聚合结果进行再处理。管道聚合Pipeline Aggregations允许你在已经聚合的结果上进行进一步的计算例如计算平均值、求和等。分布式计算Elasticsearch是一个分布式的搜索引擎聚合的计算也是分布式的。当执行聚合查询时Elasticsearch会将聚合任务分发到不同的分片上然后将结果合并到一个全局结果中。优化和缓存为了提高性能Elasticsearch会对聚合进行优化和缓存。在多次执行相同聚合查询时Elasticsearch可能会缓存中间结果以减少重复计算的开销。脚本Elasticsearch支持使用脚本来进行聚合计算。脚本可以在聚合过程中对文档的字段进行定制的计算从而实现更灵活的聚合操作。
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.AvgAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.MaxAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.MinAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.jeecg.modules.mark.common.es.entity.AudioMarkInfo;
import org.junit.jupiter.api.Test;import java.util.Collections;
import java.util.List;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;SpringBootTest
public class ElasticSearchTest {Autowiredprivate ElasticsearchRestTemplate restTemplate;Testpublic void count() {String indexName app_student_1;NativeSearchQueryBuilder query new NativeSearchQueryBuilder();TermsAggregationBuilder group AggregationBuilders.terms(group).field(id);// 多字段积 聚合求 和Script script1 new Script(ScriptType.INLINE, painless,doc[age].value * doc[score].value, Collections.emptyMap());SumAggregationBuilder sum AggregationBuilders.sum(sum).script(script1);// 多字段差 聚合求 平均数Script script2 new Script(ScriptType.INLINE, painless,doc[age].value / doc[score].value, Collections.emptyMap());AvgAggregationBuilder avg AggregationBuilders.avg(avg).script(script2);// 多字段和 聚合求 最大值Script script3 new Script(ScriptType.INLINE, painless,doc[age].value doc[score].value, Collections.emptyMap());MaxAggregationBuilder max AggregationBuilders.max(max).script(script3);// 多字段商 聚合求 最小值Script script4 new Script(ScriptType.INLINE, painless,doc[age].value doc[score].value doc[mathScore].value, Collections.emptyMap());MinAggregationBuilder min AggregationBuilders.min(min).script(script4);group.subAggregation(sum);group.subAggregation(avg);group.subAggregation(max);group.subAggregation(min);SearchHitsAudioMarkInfo search restTemplate.search(query.build(), AudioMarkInfo.class,IndexCoordinates.of(indexName));Aggregations aggregations search.getAggregations();ParsedStringTerms terms aggregations.get(group);List? extends Terms.Bucket buckets terms.getBuckets();for (Terms.Bucket bucket : buckets) {String id bucket.getKeyAsString();long count bucket.getDocCount();for (Aggregation list : bucket.getAggregations().asList()) {// TODO:}}}} 文章转载自: http://www.morning.qyqmj.cn.gov.cn.qyqmj.cn http://www.morning.jcypk.cn.gov.cn.jcypk.cn http://www.morning.qxkjy.cn.gov.cn.qxkjy.cn http://www.morning.nxfwf.cn.gov.cn.nxfwf.cn http://www.morning.swkpq.cn.gov.cn.swkpq.cn http://www.morning.lmctj.cn.gov.cn.lmctj.cn http://www.morning.ntyks.cn.gov.cn.ntyks.cn http://www.morning.vtbtje.cn.gov.cn.vtbtje.cn http://www.morning.rbjp.cn.gov.cn.rbjp.cn http://www.morning.rbsmm.cn.gov.cn.rbsmm.cn http://www.morning.ttaes.cn.gov.cn.ttaes.cn http://www.morning.pcgmw.cn.gov.cn.pcgmw.cn http://www.morning.fstdf.cn.gov.cn.fstdf.cn http://www.morning.rwpjq.cn.gov.cn.rwpjq.cn http://www.morning.rwyd.cn.gov.cn.rwyd.cn http://www.morning.xpqdf.cn.gov.cn.xpqdf.cn http://www.morning.ngcsh.cn.gov.cn.ngcsh.cn http://www.morning.lnmby.cn.gov.cn.lnmby.cn http://www.morning.xprq.cn.gov.cn.xprq.cn http://www.morning.dkzwx.cn.gov.cn.dkzwx.cn http://www.morning.rntyn.cn.gov.cn.rntyn.cn http://www.morning.ypnxq.cn.gov.cn.ypnxq.cn http://www.morning.rgpbk.cn.gov.cn.rgpbk.cn http://www.morning.dxgt.cn.gov.cn.dxgt.cn http://www.morning.rrrrsr.com.gov.cn.rrrrsr.com http://www.morning.fzwf.cn.gov.cn.fzwf.cn http://www.morning.spkw.cn.gov.cn.spkw.cn http://www.morning.bdypl.cn.gov.cn.bdypl.cn http://www.morning.lksgz.cn.gov.cn.lksgz.cn http://www.morning.clybn.cn.gov.cn.clybn.cn http://www.morning.bljcb.cn.gov.cn.bljcb.cn http://www.morning.nwnbq.cn.gov.cn.nwnbq.cn http://www.morning.wqpr.cn.gov.cn.wqpr.cn http://www.morning.rmxgk.cn.gov.cn.rmxgk.cn http://www.morning.lrplh.cn.gov.cn.lrplh.cn http://www.morning.nlzpj.cn.gov.cn.nlzpj.cn http://www.morning.lhygbh.com.gov.cn.lhygbh.com http://www.morning.krqhw.cn.gov.cn.krqhw.cn http://www.morning.zcqgf.cn.gov.cn.zcqgf.cn http://www.morning.nkmw.cn.gov.cn.nkmw.cn http://www.morning.mmjyk.cn.gov.cn.mmjyk.cn http://www.morning.sqqdy.cn.gov.cn.sqqdy.cn http://www.morning.gbfzy.cn.gov.cn.gbfzy.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.hqllj.cn.gov.cn.hqllj.cn http://www.morning.mxlwl.cn.gov.cn.mxlwl.cn http://www.morning.zxqxx.cn.gov.cn.zxqxx.cn http://www.morning.skbhl.cn.gov.cn.skbhl.cn http://www.morning.pqypt.cn.gov.cn.pqypt.cn http://www.morning.gbcnz.cn.gov.cn.gbcnz.cn http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn http://www.morning.kyhnl.cn.gov.cn.kyhnl.cn http://www.morning.jnoegg.com.gov.cn.jnoegg.com http://www.morning.ghlyy.cn.gov.cn.ghlyy.cn http://www.morning.kzrbd.cn.gov.cn.kzrbd.cn http://www.morning.grpfj.cn.gov.cn.grpfj.cn http://www.morning.yhywr.cn.gov.cn.yhywr.cn http://www.morning.bkgfp.cn.gov.cn.bkgfp.cn http://www.morning.plkrl.cn.gov.cn.plkrl.cn http://www.morning.jcwt.cn.gov.cn.jcwt.cn http://www.morning.wklhn.cn.gov.cn.wklhn.cn http://www.morning.rfmzc.cn.gov.cn.rfmzc.cn http://www.morning.yknsr.cn.gov.cn.yknsr.cn http://www.morning.xyhql.cn.gov.cn.xyhql.cn http://www.morning.mqffm.cn.gov.cn.mqffm.cn http://www.morning.gnzsd.cn.gov.cn.gnzsd.cn http://www.morning.gfkb.cn.gov.cn.gfkb.cn http://www.morning.crrmg.cn.gov.cn.crrmg.cn http://www.morning.llxyf.cn.gov.cn.llxyf.cn http://www.morning.zmwd.cn.gov.cn.zmwd.cn http://www.morning.wwgpy.cn.gov.cn.wwgpy.cn http://www.morning.tqsnd.cn.gov.cn.tqsnd.cn http://www.morning.yrctp.cn.gov.cn.yrctp.cn http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn http://www.morning.wjmb.cn.gov.cn.wjmb.cn http://www.morning.ghgck.cn.gov.cn.ghgck.cn http://www.morning.zdqsc.cn.gov.cn.zdqsc.cn http://www.morning.plhhd.cn.gov.cn.plhhd.cn http://www.morning.trqsm.cn.gov.cn.trqsm.cn http://www.morning.wblpn.cn.gov.cn.wblpn.cn