org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder Java Examples
The following examples show how to use
org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AggregationQueryAction.java From elasticsearch-sql with Apache License 2.0 | 6 votes |
private AggregationBuilder createNestedAggregation(Field field) { AggregationBuilder nestedBuilder; String nestedPath = field.getNestedPath(); if (field.isReverseNested()) { if (nestedPath == null || !nestedPath.startsWith("~")) { ReverseNestedAggregationBuilder reverseNestedAggregationBuilder = AggregationBuilders.reverseNested(getNestedAggName(field)); if(nestedPath!=null){ reverseNestedAggregationBuilder.path(nestedPath); } return reverseNestedAggregationBuilder; } nestedPath = nestedPath.substring(1); } nestedBuilder = AggregationBuilders.nested(getNestedAggName(field),nestedPath); return nestedBuilder; }
Example #2
Source File: AggMaker.java From elasticsearch-sql with Apache License 2.0 | 4 votes |
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()); }