org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder Java Examples

The following examples show how to use org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder. 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: AggregationHelper.java    From fast-elasticsearch-query-builder with Apache License 2.0 5 votes vote down vote up
private static void setCardinalityAggregation(SearchSourceBuilder searchSource, CardinalityAggregation aggregation,
        Boolean value) {
    if (!value) {
        return;
    }
    CardinalityAggregationBuilder cardinalityAggregation = AggregationBuilders.cardinality(aggregation.name()).field(aggregation.field());
    long precisionThreshold = aggregation.precisionThreshold();
    if (precisionThreshold > 0) {
        cardinalityAggregation.precisionThreshold(precisionThreshold);
    }
    searchSource.aggregation(cardinalityAggregation);
}
 
Example #2
Source File: ElasticsearchSearchQueryBase.java    From vertexium with Apache License 2.0 5 votes vote down vote up
protected List<AggregationBuilder> getElasticsearchCardinalityAggregations(CardinalityAggregation agg) {
    List<AggregationBuilder> cardinalityAggs = new ArrayList<>();
    String fieldName = agg.getPropertyName();
    if (Element.ID_PROPERTY_NAME.equals(fieldName)
        || Edge.LABEL_PROPERTY_NAME.equals(fieldName)
        || Edge.OUT_VERTEX_ID_PROPERTY_NAME.equals(fieldName)
        || Edge.IN_VERTEX_ID_PROPERTY_NAME.equals(fieldName)
        || ExtendedDataRow.TABLE_NAME.equals(fieldName)
        || ExtendedDataRow.ROW_ID.equals(fieldName)
        || ExtendedDataRow.ELEMENT_ID.equals(fieldName)
        || ExtendedDataRow.ELEMENT_TYPE.equals(fieldName)) {
        Map<String, Object> metadata = new HashMap<>();
        metadata.put(AGGREGATION_METADATA_FIELD_NAME_KEY, fieldName);

        if (Element.ID_PROPERTY_NAME.equals(fieldName) || ExtendedDataRow.ELEMENT_ID.equals(fieldName)) {
            fieldName = ELEMENT_ID_FIELD_NAME;
        } else if (ExtendedDataRow.ELEMENT_TYPE.equals(fieldName)) {
            fieldName = ELEMENT_TYPE_FIELD_NAME;
        }
        String aggregationName = createAggregationName(agg.getAggregationName(), "0");
        CardinalityAggregationBuilder cardinalityAgg = AggregationBuilders.cardinality(aggregationName);
        cardinalityAgg.setMetaData(metadata);
        cardinalityAgg.field(fieldName);
        cardinalityAggs.add(cardinalityAgg);
    } else {
        throw new VertexiumException("Cannot use cardinality aggregation on properties with visibility: " + fieldName);
    }
    return cardinalityAggs;
}
 
Example #3
Source File: Utils.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
public static CardinalityAggregationBuilder buildCardinalityAggregation(String field, int precisionThreshold) {
    if (0 == precisionThreshold) {
        precisionThreshold = PRECISION_THRESHOLD;
    }
    return AggregationBuilders.cardinality(Utils.sanitizeFieldForAggregation(field))
            .precisionThreshold(precisionThreshold)
            .field(storedFieldName(field));

}