Search in sources :

Example 1 with Order

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;
}
Also used : Order(org.elasticsearch.search.aggregations.bucket.terms.Terms.Order) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) AggregationPath(org.elasticsearch.search.aggregations.support.AggregationPath)

Example 2 with 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);
}
Also used : Order(org.elasticsearch.search.aggregations.bucket.terms.Terms.Order) SortOrder(org.elasticsearch.search.sort.SortOrder)

Example 3 with Order

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;
}
Also used : Order(org.elasticsearch.search.aggregations.bucket.terms.Terms.Order) ParsingException(org.elasticsearch.common.ParsingException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

Order (org.elasticsearch.search.aggregations.bucket.terms.Terms.Order)3 ParsingException (org.elasticsearch.common.ParsingException)1 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)1 AggregationPath (org.elasticsearch.search.aggregations.support.AggregationPath)1 SortOrder (org.elasticsearch.search.sort.SortOrder)1