当前位置: 首页>>代码示例>>Java>>正文


Java AggregationBuilder.subAggregation方法代码示例

本文整理汇总了Java中org.elasticsearch.search.aggregations.AggregationBuilder.subAggregation方法的典型用法代码示例。如果您正苦于以下问题:Java AggregationBuilder.subAggregation方法的具体用法?Java AggregationBuilder.subAggregation怎么用?Java AggregationBuilder.subAggregation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.search.aggregations.AggregationBuilder的用法示例。


在下文中一共展示了AggregationBuilder.subAggregation方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addMetrics

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
/**
 * Adds a set of 'leaf aggregations' to the provided parent metric (i.e. count, sum, max etc)
 * @param parentAgg
 * @param metrics
 * @param addCount
 */
@SuppressWarnings("rawtypes")
private void addMetrics(AggregationBuilder parentAgg, Heading heading, boolean addCount){
	for(Column metric : heading.columns()){
		if(metric.getOp() == Operation.AVG) 
			parentAgg.subAggregation(AggregationBuilders.avg(metric.getAggName()).field(metric.getColumn()));
		else if(addCount && metric.getOp() == Operation.COUNT)
			parentAgg.subAggregation(AggregationBuilders.count(metric.getAggName()));
		else if(metric.getOp() == Operation.MAX) 
			parentAgg.subAggregation(AggregationBuilders.max(metric.getAggName()).field(metric.getColumn()));
		else if(metric.getOp() == Operation.MIN) 
			parentAgg.subAggregation(AggregationBuilders.min(metric.getAggName()).field(metric.getColumn()));
		else if(metric.getOp() == Operation.SUM) 
			parentAgg.subAggregation(AggregationBuilders.sum(metric.getAggName()).field(metric.getColumn()));
	}
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:22,代码来源:GroupParser.java

示例2: explanFields

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
private void explanFields(SearchRequestBuilder request, List<Field> fields, AggregationBuilder groupByAgg) throws SqlParseException {
    for (Field field : fields) {
        if (field instanceof MethodField) {

            if (field.getName().equals("script")) {
                request.addStoredField(field.getAlias());
                DefaultQueryAction defaultQueryAction = new DefaultQueryAction(client, select);
                defaultQueryAction.intialize(request);
                List<Field> tempFields = Lists.newArrayList(field);
                defaultQueryAction.setFields(tempFields);
                continue;
            }

            AggregationBuilder makeAgg = aggMaker.makeFieldAgg((MethodField) field, groupByAgg);
            if (groupByAgg != null) {
                groupByAgg.subAggregation(makeAgg);
            } else {
                request.addAggregation(makeAgg);
            }
        } else if (field instanceof Field) {
            request.addStoredField(field.getName());
        } else {
            throw new SqlParseException("it did not support this field method " + field);
        }
    }
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:27,代码来源:AggregationQueryAction.java

示例3: explanFields

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
private void explanFields(SearchRequestBuilder request, List<Field> fields, AggregationBuilder<?> groupByAgg) throws SqlParseException {
	for (Field field : fields) {
		if (field instanceof MethodField) {
			AbstractAggregationBuilder makeAgg = aggMaker.makeFieldAgg((MethodField) field, groupByAgg);
			if (groupByAgg != null) {
				groupByAgg.subAggregation(makeAgg);
			}
			 else {
				request.addAggregation(makeAgg);
			}
		} else if (field instanceof Field) {
			request.addField(field.getName());
		} else {
			throw new SqlParseException("it did not support this field method " + field);
		}
	}
}
 
开发者ID:lane-cn,项目名称:elasticsql,代码行数:18,代码来源:AggregationQueryAction.java

示例4: addSubAggs

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
void addSubAggs(QueryConverter queryConverter, Aggregation agg, AggregationBuilder builder) {
    Map<String, Aggregation> aggs = agg.getAggs();
    for (String key : aggs.keySet()) {
        Aggregation subAgg = aggs.get(key);
        AbstractAggregationBuilder subBuilder = queryConverter.converterAggregation(subAgg);
        if (subBuilder != null) {
            builder.subAggregation(subBuilder);
        }
    }
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:11,代码来源:AbstractCombinedConverter.java

示例5: insertFilterIfExistsAfter

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
private boolean insertFilterIfExistsAfter(AggregationBuilder agg, List<Field> groupBy, AggregationBuilder builder, int nextPosition) throws SqlParseException {
    if (groupBy.size() <= nextPosition) return false;
    Field filterFieldCandidate = groupBy.get(nextPosition);
    if (!(filterFieldCandidate instanceof MethodField)) return false;
    MethodField methodField = (MethodField) filterFieldCandidate;
    if (!methodField.getName().toLowerCase().equals("filter")) return false;
    builder.subAggregation(aggMaker.makeGroupAgg(filterFieldCandidate).subAggregation(agg));
    return true;
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:10,代码来源:AggregationQueryAction.java

示例6: addSubAggs

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
protected void addSubAggs(QueryConverter queryConverter, Aggregation agg, AggregationBuilder builder) {
    Map<String, Aggregation> aggs = agg.getAggs();
    for (String key : aggs.keySet()) {
        Aggregation subAgg = aggs.get(key);
        AbstractAggregationBuilder subBuilder = queryConverter.converterAggregation(subAgg);
        if (subBuilder != null) {
            builder.subAggregation(subBuilder);
        }
    }
}
 
开发者ID:scaleset,项目名称:scaleset-search,代码行数:11,代码来源:AbstractCombinedConverter.java

示例7: addFieldToAgg

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
private AggregationBuilder addFieldToAgg(MethodField field, ValuesSourceAggregationBuilder builder) {
    KVValue kvValue = field.getParams().get(0);
    if (kvValue.key != null && kvValue.key.equals("script")) {
        if (kvValue.value instanceof MethodField) {
            return builder.script(new Script(((MethodField) kvValue.value).getParams().get(1).toString()));
        } else {
            return builder.script(new Script(kvValue.value.toString()));
        }

    } else if (kvValue.key != null && kvValue.value.toString().trim().startsWith("def")) {
        return builder.script(new Script(kvValue.value.toString()));
    } else if (kvValue.key != null && (kvValue.key.equals("nested") || kvValue.key.equals("reverse_nested"))) {
        NestedType nestedType = (NestedType) kvValue.value;

        builder.field(nestedType.field);

        AggregationBuilder nestedBuilder;

        String nestedAggName = nestedType.field + "@NESTED";

        if (nestedType.isReverse()) {
            if (nestedType.path != null && nestedType.path.startsWith("~")) {
                String realPath = nestedType.path.substring(1);
                nestedBuilder = AggregationBuilders.nested(nestedAggName,realPath);
                nestedBuilder = nestedBuilder.subAggregation(builder);
                return AggregationBuilders.reverseNested(nestedAggName + "_REVERSED").subAggregation(nestedBuilder);
            } else {
                ReverseNestedAggregationBuilder reverseNestedAggregationBuilder = AggregationBuilders.reverseNested(nestedAggName);
                if (nestedType.path!=null){
                    reverseNestedAggregationBuilder.path(nestedType.path);
                }
                nestedBuilder = reverseNestedAggregationBuilder;
            }
        } else {
            nestedBuilder = AggregationBuilders.nested(nestedAggName,nestedType.path);
        }

        return nestedBuilder.subAggregation(builder);
    } else if (kvValue.key != null && (kvValue.key.equals("children"))) {
        ChildrenType childrenType = (ChildrenType) kvValue.value;

        builder.field(childrenType.field);

        AggregationBuilder childrenBuilder;

        String childrenAggName = childrenType.field + "@CHILDREN";

        childrenBuilder = AggregationBuilders.children(childrenAggName,childrenType.childType);

        return childrenBuilder;
    }

    return builder.field(kvValue.toString());
}
 
开发者ID:mazhou,项目名称:es-sql,代码行数:55,代码来源:AggMaker.java

示例8: explain

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
@Override
public SqlElasticSearchRequestBuilder explain() throws SqlParseException {
	this.request = client.prepareSearch();

	setIndicesAndTypes();

	setWhere(select.getWhere());
	AggregationBuilder<?> lastAgg = null;

	for (List<Field> groupBy : select.getGroupBys()) {
		if (!groupBy.isEmpty()) {
			Field field = groupBy.get(0);
			lastAgg = aggMaker.makeGroupAgg(field);

			if (lastAgg != null && lastAgg instanceof TermsBuilder) {
				((TermsBuilder) lastAgg).size(select.getRowCount());
			}

			request.addAggregation(lastAgg);

			for (int i = 1; i < groupBy.size(); i++) {
				field = groupBy.get(i);
				AggregationBuilder<?> subAgg = aggMaker.makeGroupAgg(field);
				if (subAgg instanceof TermsBuilder) {
					((TermsBuilder) subAgg).size(0);
				}

				lastAgg.subAggregation(subAgg);
				lastAgg = subAgg;
			}
		}
	}

	Map<String, KVValue> groupMap = aggMaker.getGroupMap();
	// add field
	if (select.getFields().size() > 0) {
		setFields(select.getFields());
		explanFields(request, select.getFields(), lastAgg);
	}

	// add order
	if (lastAgg != null && select.getOrderBys().size() > 0) {
		for (Order order : select.getOrderBys()) {
			KVValue temp = groupMap.get(order.getName());
			if (temp != null) {
				TermsBuilder termsBuilder = (TermsBuilder) temp.value;
				switch (temp.key) {
				case "COUNT":
					termsBuilder.order(Terms.Order.count(isASC(order)));
					break;
				case "KEY":
					termsBuilder.order(Terms.Order.term(isASC(order)));
					// add the sort to the request also so the results get sorted as well
					request.addSort(order.getName(), SortOrder.valueOf(order.getType()));
					break;
				case "FIELD":
					termsBuilder.order(Terms.Order.aggregation(order.getName(), isASC(order)));
					break;
				default:
					throw new SqlParseException(order.getName() + " can not to order");
				}
			} else {
				request.addSort(order.getName(), SortOrder.valueOf(order.getType()));
			}
		}
	}
	setLimit(select.getOffset(), select.getRowCount());

	request.setSearchType(SearchType.DEFAULT);
       SqlElasticSearchRequestBuilder sqlElasticRequestBuilder = new SqlElasticSearchRequestBuilder(request);
       return sqlElasticRequestBuilder;
}
 
开发者ID:selvakumarEsra,项目名称:es4sql,代码行数:73,代码来源:AggregationQueryAction.java

示例9: addFieldToAgg

import org.elasticsearch.search.aggregations.AggregationBuilder; //导入方法依赖的package包/类
private AggregationBuilder addFieldToAgg(MethodField field, ValuesSourceAggregationBuilder builder) {
    KVValue kvValue = field.getParams().get(0);
    if (kvValue.key != null && kvValue.key.equals("script")) {
        if (kvValue.value instanceof MethodField) {
            return builder.script(new Script(((MethodField) kvValue.value).getParams().get(1).toString()));
        } else {
            return builder.script(new Script(kvValue.value.toString()));
        }

    } else if (kvValue.key != null && kvValue.value.toString().trim().startsWith("def")) {
        return builder.script(new Script(kvValue.value.toString()));
    } else if (kvValue.key != null && (kvValue.key.equals("nested") || kvValue.key.equals("reverse_nested"))) {
        NestedType nestedType = (NestedType) kvValue.value;

        builder.field(nestedType.field);

        AggregationBuilder nestedBuilder;

        String nestedAggName = nestedType.field + "@NESTED";

        if (nestedType.isReverse()) {
            if (nestedType.path != null && nestedType.path.startsWith("~")) {
                String realPath = nestedType.path.substring(1);
                nestedBuilder = AggregationBuilders.nested(nestedAggName,realPath);
                nestedBuilder = nestedBuilder.subAggregation(builder);
                return AggregationBuilders.reverseNested(nestedAggName + "_REVERSED").subAggregation(nestedBuilder);
            } else {
                ReverseNestedAggregationBuilder reverseNestedAggregationBuilder = AggregationBuilders.reverseNested(nestedAggName);
                if (nestedType.path!=null){
                    reverseNestedAggregationBuilder.path(nestedType.path);
                }
                nestedBuilder = reverseNestedAggregationBuilder;
            }
        } else {
            nestedBuilder = AggregationBuilders.nested(nestedAggName,nestedType.path);
        }

        return nestedBuilder.subAggregation(builder);
    } else if (kvValue.key != null && (kvValue.key.equals("children"))) {
        ChildrenType childrenType = (ChildrenType) kvValue.value;

        builder.field(childrenType.field);

        AggregationBuilder childrenBuilder;

        String childrenAggName = childrenType.field + "@CHILDREN";

        childrenBuilder = JoinAggregationBuilders.children(childrenAggName,childrenType.childType);

        return childrenBuilder;
    }

    return builder.field(kvValue.toString());
}
 
开发者ID:NLPchina,项目名称:elasticsearch-sql,代码行数:55,代码来源:AggMaker.java


注:本文中的org.elasticsearch.search.aggregations.AggregationBuilder.subAggregation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。