当前位置:网站首页>Restclient multi conditional aggregation
Restclient multi conditional aggregation
2022-07-19 06:34:00 【Its natural happy clothes】

In the corresponding service Write in layer :


HotelService The code in is as follows :
@Override
public Map<String, List<String>> filters() {
try {
//1. Get ready Request
SearchRequest request = new SearchRequest("hotel");
//2. Get ready DSL
//2.1 Set up size
request.source().size(0);
//2.2 polymerization
buildAggretgaion(request);
//3. Request
SearchResponse response = client.search(request,RequestOptions.DEFAULT);
//4. Analysis results
Map<String,List<String>> result = new HashMap<String, List<String>>();
Aggregations aggregations = response.getAggregations();
//4.1 According to brand ( Aggregate name ) Name gets the result of the brand
List<String> brandList = getAddByName(aggregations,"brandAgg");
result.put(" brand ",brandList); // Put in map
//4.2 According to the city ( Aggregate name ) Name gets the result of the brand
List<String> cityList = getAddByName(aggregations,"cityList");
result.put(" City ",cityList); // Put in map
//4.3 According to stars ( Aggregate name ) Name gets the result of the brand
List<String> starList = getAddByName(aggregations,"starList");
result.put(" The star ",starList); // Put in map
return result;
} catch (IOException e) {
throw new RuntimeException();
}
}
//( Extracted from ) Get the results of the brand according to the name
private List<String> getAddByName(Aggregations aggregations, String aggName) {
//4.1 Get the aggregation result according to the aggregation name
Terms brandTerms = aggregations.get(aggName);
//4.2 obtain buckets
List<? extends Terms.Bucket> buckets = brandTerms.getBuckets();
//4.3 Traverse
List<String> brandList = new ArrayList<String>();
for(Terms.Bucket bucket : buckets){
//4.4 obtain key
String key = bucket.getKeyAsString();
brandList.add(key);
System.out.println(key);
}
return brandList;
}
// Extracted from polymerization
private void buildAggretgaion(SearchRequest request) {
request.source().aggregation(AggregationBuilders
.terms("brandAgg")
.field("brand")
.size(10)
);
request.source().aggregation(AggregationBuilders
.terms("cityAgg")
.field("city")
.size(10)
);
request.source().aggregation(AggregationBuilders
.terms("starAgg")
.field("starName.keyword")
.size(10)
);
}边栏推荐
- 感知智能手機上用戶的關注狀態
- EOG-based eye movement detection and gaze estimation for an asynchronous virtual keyboard基于EOG的异步虚
- Busybox specified date modification temporarily does not require clock -w to write to hardware
- Eye tracking in virtual reality
- 大龄程序员都去哪了?
- Learning non posture gaze deviation with head movement
- Learning non posture gaze deviation with head movement
- Perceive the attention status of users on smart phones
- 机器人缝合手势识别和分类
- LeetCode字符串
猜你喜欢

Eye tracking in virtual reality

Manjaro 系统日常使用入门导引

颜色直方图 灰度图&彩色图

Unity2d learning Fox game production process 1: basic game character control, animation effects, lens control, item collection, bug optimization

數學基礎課2_歐拉函數,線性篩,擴歐

Cours de mathématiques de base 2 Fonction Euler, écran linéaire, élargissement de l'Europe

Perception de l’état d’attention des utilisateurs sur les smartphones

EOG-based eye movement detection and gaze estimation for an asynchronous virtual keyboard基于EOG的异步虚

斑点检测 记录

Unity2D学习 Fox Game制作 过程1:基本的游戏角色控制,动画效果,镜头控制,物品收集,bug优化
随机推荐
斑点检测 记录
[force buckle] symmetric binary tree
从零开始的 Rust 语言 blas 库之预备篇(2)—— blas 矩阵格式详解
【牛客】二叉树遍历
LeetCode树
工作中遇到的一些问题
2022/07/12 学习笔记 (day05)循环
Knapsack with dependency, narrow sense (binary enumeration), broad sense (tree DP)
Busybox date date increases by one day, and decreases by one day on the Internet tomorrow
实习笔试解答
Read pictures and convert them to show different color spaces
2022/07/09 group 5 Ding Shuai's study notes day02
[force buckle] ring list II
实验三 继承性和派生类
颜色直方图 灰度图&彩色图
Manjaro 系统日常使用入门导引
QT creator flashback solution
2022/07/14 learning notes (day07) array
数据库的查询(二)
[Li Kou] a subtree of another tree