|
@ -131,6 +131,7 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
|
|
View view = this.getViewRule(viewCode);
|
|
View view = this.getViewRule(viewCode);
|
|
String[] esIndices = view.getEsIndex().split(",");
|
|
String[] esIndices = view.getEsIndex().split(",");
|
|
String[] esTypes = view.getEsType().split(",");
|
|
String[] esTypes = view.getEsType().split(",");
|
|
|
|
int indexCount = esIndices.length;
|
|
|
|
|
|
TransportClient transportClient = elasticSearchPool.getClient();
|
|
TransportClient transportClient = elasticSearchPool.getClient();
|
|
SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch(esIndices).setTypes(esTypes).setSize(0);
|
|
SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch(esIndices).setTypes(esTypes).setSize(0);
|
|
@ -169,13 +170,8 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
int indexCount = esIndices.length;
|
|
|
|
// 遍历顶层行维度
|
|
// 遍历顶层行维度
|
|
for (ViewDimension topRowDimension : groupTopRowDimensionList) {
|
|
for (ViewDimension topRowDimension : groupTopRowDimensionList) {
|
|
String topRowDimensionCode = topRowDimension.getDimensionCode();
|
|
|
|
String topOrderType = topRowDimension.getMemberOrderType();
|
|
|
|
boolean isTopAsc = "asc".equals(topRowDimension.getMemberOrderStrategy()) ? true : false;
|
|
|
|
|
|
|
|
// 有多个多维度数据集时,设定顶层行维度聚合的数据来自哪个多维数据集。
|
|
// 有多个多维度数据集时,设定顶层行维度聚合的数据来自哪个多维数据集。
|
|
FilterAggregationBuilder topFilterAgg = null;
|
|
FilterAggregationBuilder topFilterAgg = null;
|
|
if (indexCount > 1) {
|
|
if (indexCount > 1) {
|
|
@ -316,33 +312,33 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
|
|
String dimensionCode = viewDimension.getDimensionCode();
|
|
String dimensionCode = viewDimension.getDimensionCode();
|
|
String orderType = viewDimension.getMemberOrderType();
|
|
String orderType = viewDimension.getMemberOrderType();
|
|
String orderStrategy = viewDimension.getMemberOrderStrategy();
|
|
String orderStrategy = viewDimension.getMemberOrderStrategy();
|
|
boolean isTopAsc = StringUtils.isEmpty(orderStrategy) || "asc".equals(orderStrategy) ? true : false;
|
|
|
|
|
|
boolean isAsc = StringUtils.isEmpty(orderStrategy) || "asc".equals(orderStrategy) ? true : false;
|
|
|
|
String memberOrderQuotaId = viewDimension.getMemberOrderQuotaId();
|
|
|
|
Integer memberCount = viewDimension.getMemberCount();
|
|
|
|
|
|
String fieldType = cubeService.findDimensionDataType(viewDimension.getCubeCode(), viewDimension.getDimensionCode());
|
|
|
|
|
|
String fieldType = cubeService.findDimensionDataType(viewDimension.getCubeCode(), dimensionCode);
|
|
if (!"date".equals(fieldType)) {
|
|
if (!"date".equals(fieldType)) {
|
|
String aggName = dimensionCode + "-terms";
|
|
String aggName = dimensionCode + "-terms";
|
|
dimensionAgg = AggregationBuilders.terms(aggName).field(dimensionCode);
|
|
dimensionAgg = AggregationBuilders.terms(aggName).field(dimensionCode);
|
|
|
|
|
|
// 设置排序
|
|
// 设置排序
|
|
if (StringUtils.isEmpty(orderType) || "name".equals(orderType)) {
|
|
if (StringUtils.isEmpty(orderType) || "name".equals(orderType)) {
|
|
((TermsBuilder) dimensionAgg).order(Terms.Order.term(isTopAsc));
|
|
|
|
|
|
((TermsBuilder) dimensionAgg).order(Terms.Order.term(isAsc));
|
|
} else {
|
|
} else {
|
|
// 按子聚合结果排序,拼接子聚合路径
|
|
// 按子聚合结果排序,拼接子聚合路径
|
|
String memberOrderQuotaId = viewDimension.getMemberOrderQuotaId();
|
|
|
|
if (StringUtils.isNotEmpty(memberOrderQuotaId)) {
|
|
if (StringUtils.isNotEmpty(memberOrderQuotaId)) {
|
|
ViewQuota viewQuota = viewQuotaDao.findOne(memberOrderQuotaId);
|
|
ViewQuota viewQuota = viewQuotaDao.findOne(memberOrderQuotaId);
|
|
if ("basic".equals(viewQuota.getFormulaMode())) {
|
|
if ("basic".equals(viewQuota.getFormulaMode())) {
|
|
String subAggPath = viewQuota.getBasicFormulaType() + "-result";
|
|
String subAggPath = viewQuota.getBasicFormulaType() + "-result";
|
|
((TermsBuilder) dimensionAgg).order(Terms.Order.aggregation(subAggPath, isTopAsc));
|
|
|
|
|
|
((TermsBuilder) dimensionAgg).order(Terms.Order.aggregation(subAggPath, isAsc));
|
|
} else {
|
|
} else {
|
|
((TermsBuilder) dimensionAgg).order(Terms.Order.term(isTopAsc));
|
|
|
|
|
|
((TermsBuilder) dimensionAgg).order(Terms.Order.term(isAsc));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 设置分组个数
|
|
// 设置分组个数
|
|
int memberCount = viewDimension.getMemberCount();
|
|
|
|
if (memberCount > 0) {
|
|
|
|
|
|
if (memberCount!= null && memberCount > 0) {
|
|
((TermsBuilder) dimensionAgg).size(memberCount);
|
|
((TermsBuilder) dimensionAgg).size(memberCount);
|
|
} else {
|
|
} else {
|
|
// TODO 需动态获取全部的分组个数进行设置
|
|
// TODO 需动态获取全部的分组个数进行设置
|
|
@ -355,17 +351,16 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
|
|
((DateHistogramBuilder) dimensionAgg).format(viewDimension.getMemberDateFormat());
|
|
((DateHistogramBuilder) dimensionAgg).format(viewDimension.getMemberDateFormat());
|
|
((DateHistogramBuilder) dimensionAgg).interval(new DateHistogramInterval(viewDimension.getMemberDateInterval()));
|
|
((DateHistogramBuilder) dimensionAgg).interval(new DateHistogramInterval(viewDimension.getMemberDateInterval()));
|
|
// 设置排序
|
|
// 设置排序
|
|
Histogram.Order order = isTopAsc ? Histogram.Order.KEY_ASC : Histogram.Order.KEY_DESC;
|
|
|
|
|
|
Histogram.Order order = isAsc ? Histogram.Order.KEY_ASC : Histogram.Order.KEY_DESC;
|
|
if (StringUtils.isEmpty(orderType) || "name".equals(orderType)) {
|
|
if (StringUtils.isEmpty(orderType) || "name".equals(orderType)) {
|
|
((DateHistogramBuilder) dimensionAgg).order(order);
|
|
((DateHistogramBuilder) dimensionAgg).order(order);
|
|
} else {
|
|
} else {
|
|
// 按子聚合结果排序,拼接子聚合路径
|
|
// 按子聚合结果排序,拼接子聚合路径
|
|
String memberOrderQuotaId = viewDimension.getMemberOrderQuotaId();
|
|
|
|
if (StringUtils.isNotEmpty(memberOrderQuotaId)) {
|
|
if (StringUtils.isNotEmpty(memberOrderQuotaId)) {
|
|
ViewQuota viewQuota = viewQuotaDao.findOne(memberOrderQuotaId);
|
|
ViewQuota viewQuota = viewQuotaDao.findOne(memberOrderQuotaId);
|
|
if ("basic".equals(viewQuota.getFormulaMode())) {
|
|
if ("basic".equals(viewQuota.getFormulaMode())) {
|
|
String subAggPath = viewQuota.getBasicFormulaType() + "-result";
|
|
String subAggPath = viewQuota.getBasicFormulaType() + "-result";
|
|
((DateHistogramBuilder) dimensionAgg).order(Histogram.Order.aggregation(subAggPath, isTopAsc));
|
|
|
|
|
|
((DateHistogramBuilder) dimensionAgg).order(Histogram.Order.aggregation(subAggPath, isAsc));
|
|
} else {
|
|
} else {
|
|
((DateHistogramBuilder) dimensionAgg).order(order);
|
|
((DateHistogramBuilder) dimensionAgg).order(order);
|
|
}
|
|
}
|