|
@ -1,5 +1,6 @@
|
|
|
package com.yihu.quota.util;
|
|
|
|
|
|
import com.yihu.quota.vo.ViewDataModel;
|
|
|
import org.elasticsearch.action.search.SearchRequestBuilder;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.client.transport.TransportClient;
|
|
@ -116,10 +117,13 @@ public class AggregationBuildHandler {
|
|
|
parsingAggregation(resultList,aggregation);
|
|
|
}
|
|
|
client.close();
|
|
|
return resultList;
|
|
|
LinkedList<String> rowDimensionList = new LinkedList<>();
|
|
|
rowDimensionList.add("区县_terms");
|
|
|
LinkedList<String> columnDimensionList = new LinkedList<>();
|
|
|
columnDimensionList.add("性别_terms");
|
|
|
return convertList(resultList,rowDimensionList,columnDimensionList);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 递归解析 json
|
|
|
* @param resultList
|
|
@ -129,10 +133,10 @@ public class AggregationBuildHandler {
|
|
|
System.out.println("aggKey=" + aggKey);
|
|
|
while (gradeBucket.hasNext()) {
|
|
|
Terms.Bucket b = gradeBucket.next();
|
|
|
String subVal = StringUtils.isEmpty(aggKey) ? b.getKey().toString() : (aggKey + "-" + b.getKey());
|
|
|
String subVal = StringUtils.isEmpty(aggKey) ? b.getKey().toString() : (aggKey + ":" + b.getKey());
|
|
|
for(Aggregation aggregation : b.getAggregations().asList()){
|
|
|
// System.out.println("bucketNmae = " + b.getKey().toString() + "; aggName=" + aggregation.getName());
|
|
|
subVal += ":"+ aggregation.getName();
|
|
|
System.out.println("bucketNmae = " + b.getKey().toString() + "; aggName=" + aggregation.getName());
|
|
|
subVal += ";"+ aggregation.getName();
|
|
|
if (aggregation instanceof InternalValueCount) {
|
|
|
Map<String, Object> countMap = new HashMap<>();
|
|
|
InternalValueCount valueCount = (InternalValueCount) aggregation;
|
|
@ -198,8 +202,54 @@ public class AggregationBuildHandler {
|
|
|
Terms terms = (Terms)aggregation;
|
|
|
String termName = terms.getName();
|
|
|
System.out.println("termName:" + termName);
|
|
|
expainAggregationResult(resultList, terms.getBuckets().iterator(), "");
|
|
|
expainAggregationResult(resultList, terms.getBuckets().iterator(), termName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 行列数据转换
|
|
|
* @param dataList
|
|
|
* @param rowDimensionList
|
|
|
* @param columnDimensionList
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String, Object>> convertList(List<Map<String, Object>> dataList,LinkedList<String> rowDimensionList ,LinkedList<String> columnDimensionList){
|
|
|
List<Map<String,Object>> dataMapList = new ArrayList<>();
|
|
|
List<String> rowList = new ArrayList<>();
|
|
|
for(String rowDimen : rowDimensionList){
|
|
|
for(Map<String, Object> map : dataList) {
|
|
|
for (String key : map.keySet()) {
|
|
|
List<String> result = Arrays.asList(key.split(";"));//区县_terms:信州区 ;性别_terms ; 合计_count_result
|
|
|
for(String str : result){
|
|
|
if(str.contains(rowDimen)){
|
|
|
if(!rowList.contains(str)){
|
|
|
rowList.add(str);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Map<String,Object> dataMap = new HashMap<>();
|
|
|
for(String row : rowList){
|
|
|
dataMap.put(row,row);
|
|
|
for(String columnDimen : columnDimensionList){
|
|
|
|
|
|
for(Map<String, Object> map : dataList) {
|
|
|
for (String key : map.keySet()) {
|
|
|
if(key.contains(row) && key.contains(columnDimen)){
|
|
|
List<String> result = Arrays.asList(key.split(";"));
|
|
|
for(String str : result){
|
|
|
dataMap.put(columnDimen,columnDimen);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
dataMapList.add(dataMap);
|
|
|
}
|
|
|
//未调试完成
|
|
|
return dataMapList;
|
|
|
}
|
|
|
|
|
|
|