use of org.elasticsearch.search.aggregations.bucket.terms.Terms.Order in project elasticsearch by elastic.
the class InternalOrder method validate.
public static Terms.Order validate(Terms.Order order, Aggregator termsAggregator) {
if (order instanceof CompoundOrder) {
for (Terms.Order innerOrder : ((CompoundOrder) order).orderElements) {
validate(innerOrder, termsAggregator);
}
return order;
} else if (!(order instanceof Aggregation)) {
return order;
}
AggregationPath path = ((Aggregation) order).path();
path.validate(termsAggregator);
return order;
}
use of org.elasticsearch.search.aggregations.bucket.terms.Terms.Order in project vertigo by KleeGroup.
the class ESSearchRequestBuilder method termFacetToAggregationBuilder.
private static AggregationBuilder termFacetToAggregationBuilder(final FacetDefinition facetDefinition, final DtField dtField) {
// facette par field
final Order facetOrder;
switch(facetDefinition.getOrder()) {
case alpha:
facetOrder = Terms.Order.term(true);
break;
case count:
facetOrder = Terms.Order.count(false);
break;
case definition:
// ES accept null for no sorting
facetOrder = null;
break;
default:
throw new IllegalArgumentException("Unknown facetOrder :" + facetDefinition.getOrder());
}
// Warning term aggregations are inaccurate : see http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html
final IndexType indexType = IndexType.readIndexType(dtField.getDomain());
String fieldName = dtField.getName();
if (!indexType.isIndexFieldData() && indexType.isIndexSubKeyword()) {
// si le champs n'est pas facetable mais qu'il y a un sub keyword on le prend
fieldName = fieldName + ".keyword";
}
return AggregationBuilders.terms(facetDefinition.getName()).size(TERM_AGGREGATION_SIZE).field(fieldName).order(facetOrder);
}
use of org.elasticsearch.search.aggregations.bucket.terms.Terms.Order in project elasticsearch by elastic.
the class TermsAggregationBuilder method parseOrderParam.
private static Terms.Order parseOrderParam(XContentParser parser, QueryParseContext context) throws IOException {
XContentParser.Token token;
Terms.Order orderParam = null;
String orderKey = null;
boolean orderAsc = false;
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
orderKey = parser.currentName();
} else if (token == XContentParser.Token.VALUE_STRING) {
String dir = parser.text();
if ("asc".equalsIgnoreCase(dir)) {
orderAsc = true;
} else if ("desc".equalsIgnoreCase(dir)) {
orderAsc = false;
} else {
throw new ParsingException(parser.getTokenLocation(), "Unknown terms order direction [" + dir + "]");
}
} else {
throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " for [order]");
}
}
if (orderKey == null) {
throw new ParsingException(parser.getTokenLocation(), "Must specify at least one field for [order]");
} else {
orderParam = resolveOrder(orderKey, orderAsc);
}
return orderParam;
}
Aggregations