本文整理汇总了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()));
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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());
}
示例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;
}
示例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());
}