Package org.elasticsearch.search.aggregations

Examples of org.elasticsearch.search.aggregations.AggregationExecutionException


    }

    @Override
    protected Aggregator create(ValuesSource valuesSource, long expectedBucketsCount, AggregationContext context, Aggregator parent, Map<String, Object> metaData) {
        if (!(valuesSource instanceof ValuesSource.Numeric) && !rehash) {
            throw new AggregationExecutionException("Turning off rehashing for cardinality aggregation [" + name + "] on non-numeric values in not allowed");
        }
        return new CardinalityAggregator(name, parent == null ? 1 : parent.estimatedBucketCount(), valuesSource, rehash, precision(parent), context, parent, metaData);
    }
View Full Code Here


            @Override
            public long parseLong(String value, SearchContext searchContext) {
                try {
                    return format.parse(value).longValue();
                } catch (ParseException nfe) {
                    throw new AggregationExecutionException("Invalid number format [" + ((DecimalFormat) format).toPattern() + "]");
                }
            }
View Full Code Here

            @Override
            public double parseDouble(String value, SearchContext searchContext) {
                try {
                    return format.parse(value).doubleValue();
                } catch (ParseException nfe) {
                    throw new AggregationExecutionException("Invalid number format [" + ((DecimalFormat) format).toPattern() + "]");
                }
            }
View Full Code Here

            }
            assert i == count;
        }

        else {
            throw new AggregationExecutionException("Unsupported script value [" + value + "]");
        }

        sort();
    }
View Full Code Here

            }
            assert i == count;
        }

        else {
            throw new AggregationExecutionException("Unsupported script value [" + value + "]");
        }

        sort();
    }
View Full Code Here

                return (VS) numericScript(config);
            }
            if (ValuesSource.Bytes.class.isAssignableFrom(config.valueSourceType)) {
                return (VS) bytesScript(config);
            }
            throw new AggregationExecutionException("value source of type [" + config.valueSourceType.getSimpleName() + "] is not supported by scripts");
        }

        if (ValuesSource.Numeric.class.isAssignableFrom(config.valueSourceType)) {
            return (VS) numericField(fieldDataSources, config);
        }
View Full Code Here

            String element = elements[i];
            if (i == elements.length - 1) {
                int index = element.lastIndexOf('[');
                if (index >= 0) {
                    if (index == 0 || index > element.length() - 3) {
                        throw new AggregationExecutionException("Invalid path element [" + element + "] in path [" + path + "]");
                    }
                    if (element.charAt(element.length() - 1) != ']') {
                        throw new AggregationExecutionException("Invalid path element [" + element + "] in path [" + path + "]");
                    }
                    tokens[i] = new Token(element, element.substring(0, index), element.substring(index + 1, element.length() - 1));
                    continue;
                }
                index = element.lastIndexOf('.');
                if (index < 0) {
                    tokens[i] = new Token(element, element, null);
                    continue;
                }
                if (index == 0 || index > element.length() - 2) {
                    throw new AggregationExecutionException("Invalid path element [" + element + "] in path [" + path + "]");
                }
                tuple = split(element, index, tuple);
                tokens[i] = new Token(element, tuple[0], tuple[1]);

            } else {
                int index = element.lastIndexOf('[');
                if (index >= 0) {
                    if (index == 0 || index > element.length() - 3) {
                        throw new AggregationExecutionException("Invalid path element [" + element + "] in path [" + path + "]");
                    }
                    if (element.charAt(element.length() - 1) != ']') {
                        throw new AggregationExecutionException("Invalid path element [" + element + "] in path [" + path + "]");
                    }
                    tokens[i] = new Token(element, element.substring(0, index), element.substring(index + 1, element.length() - 1));
                    continue;
                }
                tokens[i] = new Token(element, element, null);
View Full Code Here

    public void validate(Aggregator root) {
        Aggregator aggregator = root;
        for (int i = 0; i < tokens.length; i++) {
            aggregator = aggregator.subAggregator(tokens[i].name);
            if (aggregator == null) {
                throw new AggregationExecutionException("Invalid term-aggregator order path [" + this + "]. Unknown aggregation [" + tokens[i].name + "]");
            }
            if (i < tokens.length - 1) {

                // we're in the middle of the path, so the aggregator can only be a single-bucket aggregator

                if (!(aggregator instanceof SingleBucketAggregator)) {
                    throw new AggregationExecutionException("Invalid terms aggregation order path [" + this +
                            "]. Terms buckets can only be sorted on a sub-aggregator path " +
                            "that is built out of zero or more single-bucket aggregations within the path and a final " +
                            "single-bucket or a metrics aggregation at the path end. Sub-path [" +
                            subPath(0, i + 1) + "] points to non single-bucket aggregation");
                }

                if (tokens[i].key != null) {
                    throw new AggregationExecutionException("Invalid terms aggregation order path [" + this +
                            "]. Terms buckets can only be sorted on a sub-aggregator path " +
                            "that is built out of zero or more single-bucket aggregations within the path and a " +
                            "final single-bucket or a metrics aggregation at the path end. Sub-path [" +
                            subPath(0, i + 1) + "] points to non single-bucket aggregation");
                }
            }
        }
        boolean singleBucket = aggregator instanceof SingleBucketAggregator;
        if (!singleBucket && !(aggregator instanceof NumericMetricsAggregator)) {
            throw new AggregationExecutionException("Invalid terms aggregation order path [" + this +
                    "]. Terms buckets can only be sorted on a sub-aggregator path " +
                    "that is built out of zero or more single-bucket aggregations within the path and a final " +
                    "single-bucket or a metrics aggregation at the path end.");
        }

        OrderPath.Token lastToken = lastToken();

        if (singleBucket) {
            if (lastToken.key != null && !"doc_count".equals(lastToken.key)) {
                throw new AggregationExecutionException("Invalid terms aggregation order path [" + this +
                        "]. Ordering on a single-bucket aggregation can only be done on its doc_count. " +
                        "Either drop the key (a la \"" + lastToken.name + "\") or change it to \"doc_count\" (a la \"" + lastToken.name + ".doc_count\")");
            }
            return;   // perfectly valid to sort on single-bucket aggregation (will be sored on its doc_count)
        }

        if (aggregator instanceof NumericMetricsAggregator.SingleValue) {
            if (lastToken.key != null && !"value".equals(lastToken.key)) {
                throw new AggregationExecutionException("Invalid terms aggregation order path [" + this +
                        "]. Ordering on a single-value metrics aggregation can only be done on its value. " +
                        "Either drop the key (a la \"" + lastToken.name + "\") or change it to \"value\" (a la \"" + lastToken.name + ".value\")");
            }
            return;   // perfectly valid to sort on single metric aggregation (will be sorted on its associated value)
        }

        // the aggregator must be of a multi-value metrics type
        if (lastToken.key == null) {
            throw new AggregationExecutionException("Invalid terms aggregation order path [" + this +
                    "]. When ordering on a multi-value metrics aggregation a metric name must be specified");
        }

        if (!((NumericMetricsAggregator.MultiValue) aggregator).hasMetric(lastToken.key)) {
            throw new AggregationExecutionException("Invalid terms aggregation order path [" + this +
                    "]. Unknown metric name [" + lastToken.key + "] on multi-value metrics aggregation [" + lastToken.name + "]");
        }
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.aggregations.AggregationExecutionException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.