当前位置:网站首页>RestAPI实现聚合(黑马教程)
RestAPI实现聚合(黑马教程)
2022-07-17 05:12:00 【其然乐衣】



@Test
void testAggredation() throws IOException {
//1. 准备Request
SearchRequest request = new SearchRequest("hotel");
//2. 准备DSL
//2.1 设置size
request.source().size(0);
//2.2 聚合
request.source().aggregation(AggregationBuilders
.terms("brandAgg")
.field("brand")
.size(10)
);
//3. 发出请求
SearchResponse response = client.search(request,RequestOptions.DEFAULT);
//4. 解析结果
Aggregations aggregations = response.getAggregations();
//4.1 根据聚合名称获取聚合结果
Terms brandTerms = aggregations.get("brandAgg");
//4.2 获取buckets
List<? extends Terms.Bucket> buckets = brandTerms.getBuckets();
//4.3 遍历
for(Terms.Bucket bucket : buckets){
//4.4 获取key
String key = bucket.getKeyAsString();
System.out.println(key);
}
}ps:

边栏推荐
猜你喜欢

FS68001无线充SOC芯片外围简单,5W无线充方案原理图

Impact of static keyword on scope and lifecycle

CV-Model【1】:Mnist

Review of software process and management (10)

FMC子卡:4 路 SFP+万兆光纤网络 FMC 子卡

FMC子卡:4 通道 250MSPS采样率16 位 AD 采集子卡

sd nand与nandflash的区别?

SD NAND与eMMC优劣势对比

golang高并发特性goroutine介绍

Material and application circuit diagram of 0-10V, 4-20mA current voltage to PWM isolation converter
随机推荐
数字信号隔离模块 ADUM1401ARWZ 亚德诺 库存现货
4-channel encoder pulse counter, speed measurement, 8-Channel do, Modbus TCP data acquisition module
Pytorch learning notes [2]: learning mechanism
李宏毅机器学习2022.7.15--梯度下降
2021-11-17 ESP32引脚参考
Digital signal isolation module adum1401arwz yadeno in stock
Pressure strain bridge signal processing photoelectric isolation amplifier
如何用NumPy读取和保存点云数据
minio安装部署及简单使用
比例阀放大板1A、2A、3A、5A比例阀驱动模块0-10V转0-24V
[speech recognition] Kaldi installation experience
李宏毅机器学习--回归2022.07.13
CV-Model【2】:Alexnet
Review of software process and management (VIII)
分享CS品牌贴片式T卡在打猎相机领域的运用案例
String distance problem
0-10V,4-20mA电流电压转PWM隔离转换器 质料以及应用电路图
2021-11-26 pyautogui 配合雷电模拟器实现手机APP签到答题自动化
Conversion, isolation and transmission of international standard signals 0-5v/0-10v/1-5v, 0-10ma/0-20ma/4-20ma, etc
三星系列NAND Flash有什么区别?