org.elasticsearch.search.aggregations.AggregatorFactory Java Examples

The following examples show how to use org.elasticsearch.search.aggregations.AggregatorFactory. 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: ReverseNestedParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    String path = null;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("path".equals(currentFieldName)) {
                path = parser.text();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    return new ReverseNestedAggregator.Factory(aggregationName, path);
}
 
Example #2
Source File: DateHierarchyAggregatorFactory.java    From elasticsearch-aggregation-pathhierarchy with MIT License 6 votes vote down vote up
DateHierarchyAggregatorFactory(String name,
                               ValuesSourceConfig<ValuesSource.Numeric> config,
                               BucketOrder order,
                               List<DateHierarchyAggregationBuilder.RoundingInfo> roundingsInfo,
                               long minDocCount,
                               DateHierarchyAggregator.BucketCountThresholds bucketCountThresholds,
                               QueryShardContext context,
                               AggregatorFactory parent,
                               AggregatorFactories.Builder subFactoriesBuilder,
                               Map<String, Object> metaData
) throws IOException {
    super(name, config, context, parent, subFactoriesBuilder, metaData);
    this.order = order;
    this.roundingsInfo = roundingsInfo;
    this.minDocCount = minDocCount;
    this.bucketCountThresholds = bucketCountThresholds;
}
 
Example #3
Source File: GeoShapeAggregatorFactory.java    From elasticsearch-plugin-geoshape with MIT License 6 votes vote down vote up
GeoShapeAggregatorFactory(String name,
                               ValuesSourceConfig<ValuesSource> config,
                               InternalGeoShape.OutputFormat output_format,
                               boolean must_simplify,
                               int zoom,
                               GeoShape.Algorithm algorithm,
                               GeoShapeAggregator.BucketCountThresholds bucketCountThresholds,
                               QueryShardContext context,
                               AggregatorFactory parent,
                               AggregatorFactories.Builder subFactoriesBuilder,
                               Map<String, Object> metaData
) throws IOException {
    super(name, config, context, parent, subFactoriesBuilder, metaData);
    this.output_format = output_format;
    this.must_simplify = must_simplify;
    this.zoom = zoom;
    this.algorithm = algorithm;
    this.bucketCountThresholds = bucketCountThresholds;
}
 
Example #4
Source File: NumericValuesSourceMetricsAggregatorParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser<ValuesSource.Numeric> vsParser = ValuesSourceParser.numeric(aggregationName, aggType, context).formattable(true)
            .build();

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (!vsParser.token(currentFieldName, token, parser)) {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    return createFactory(aggregationName, vsParser.config());
}
 
Example #5
Source File: PathHierarchyAggregatorFactory.java    From elasticsearch-aggregation-pathhierarchy with MIT License 6 votes vote down vote up
PathHierarchyAggregatorFactory(String name,
                               ValuesSourceConfig<ValuesSource> config,
                               String separator,
                               int minDepth,
                               int maxDepth,
                               boolean keepBlankPath,
                               BucketOrder order,
                               long minDocCount,
                               PathHierarchyAggregator.BucketCountThresholds bucketCountThresholds,
                               QueryShardContext context,
                               AggregatorFactory parent,
                               AggregatorFactories.Builder subFactoriesBuilder,
                               Map<String, Object> metaData
) throws IOException {
    super(name, config, context, parent, subFactoriesBuilder, metaData);
    this.separator = new BytesRef(separator);
    this.minDepth = minDepth;
    this.maxDepth = maxDepth;
    this.keepBlankPath = keepBlankPath;
    this.order = order;
    this.minDocCount = minDocCount;
    this.bucketCountThresholds = bucketCountThresholds;
}
 
Example #6
Source File: GeoCentroidParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    ValuesSourceParser<ValuesSource.GeoPoint> vsParser = ValuesSourceParser.geoPoint(aggregationName, InternalGeoCentroid.TYPE, context)
            .targetValueType(ValueType.GEOPOINT)
            .formattable(true)
            .build();
    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else {
            throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                    + currentFieldName + "].", parser.getTokenLocation());
        }
    }
    return new GeoCentroidAggregator.Factory(aggregationName, vsParser.config());
}
 
Example #7
Source File: ValueCountParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser vsParser = ValuesSourceParser.any(aggregationName, InternalValueCount.TYPE, context)
            .build();

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (!vsParser.token(currentFieldName, token, parser)) {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    return new ValueCountAggregator.Factory(aggregationName, vsParser.config());
}
 
Example #8
Source File: PathHierarchyAggregationBuilder.java    From elasticsearch-aggregation-pathhierarchy with MIT License 6 votes vote down vote up
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> innerBuild(
        QueryShardContext context,
        ValuesSourceConfig<ValuesSource> config,
        AggregatorFactory parent,
        AggregatorFactories.Builder subFactoriesBuilder) throws IOException {

    if (minDepth > maxDepth)
        throw new IllegalArgumentException("[minDepth] (" + minDepth + ") must not be greater than [maxDepth] (" +
                maxDepth + ")");

    if (depth >= 0) {
        if (minDepth > depth)
            throw new IllegalArgumentException("[minDepth] (" + minDepth + ") must not be greater than [depth] (" +
                    depth + ")");
        minDepth = depth;
        maxDepth = depth;
    }

    return new PathHierarchyAggregatorFactory(
            name, config, separator, minDepth, maxDepth, keepBlankPath, order, minDocCount, bucketCountThresholds,
            context, parent, subFactoriesBuilder, metaData);
}
 
Example #9
Source File: MovAvgPipelineAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories,
        List<PipelineAggregatorFactory> pipelineAggregatoractories) {
    if (bucketsPaths.length != 1) {
        throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName()
                + " must contain a single entry for aggregation [" + name + "]");
    }
    if (!(parent instanceof HistogramAggregator.Factory)) {
        throw new IllegalStateException("moving average aggregation [" + name
                + "] must have a histogram or date_histogram as parent");
    } else {
        HistogramAggregator.Factory histoParent = (HistogramAggregator.Factory) parent;
        if (histoParent.minDocCount() != 0) {
            throw new IllegalStateException("parent histogram of moving average aggregation [" + name
                    + "] must have min_doc_count of 0");
        }
    }
}
 
Example #10
Source File: CumulativeSumPipelineAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, List<PipelineAggregatorFactory> pipelineAggregatorFactories) {
    if (bucketsPaths.length != 1) {
        throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName()
                + " must contain a single entry for aggregation [" + name + "]");
    }
    if (!(parent instanceof HistogramAggregator.Factory)) {
        throw new IllegalStateException("cumulative sum aggregation [" + name
                + "] must have a histogram or date_histogram as parent");
    } else {
        HistogramAggregator.Factory histoParent = (HistogramAggregator.Factory) parent;
        if (histoParent.minDocCount() != 0) {
            throw new IllegalStateException("parent histogram of cumulative sum aggregation [" + name
                    + "] must have min_doc_count of 0");
        }
    }
}
 
Example #11
Source File: DerivativePipelineAggregator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories, List<PipelineAggregatorFactory> pipelineAggregatorFactories) {
    if (bucketsPaths.length != 1) {
        throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName()
                + " must contain a single entry for aggregation [" + name + "]");
    }
    if (!(parent instanceof HistogramAggregator.Factory)) {
        throw new IllegalStateException("derivative aggregation [" + name
                + "] must have a histogram or date_histogram as parent");
    } else {
        HistogramAggregator.Factory histoParent = (HistogramAggregator.Factory) parent;
        if (histoParent.minDocCount() != 0) {
            throw new IllegalStateException("parent histogram of derivative aggregation [" + name
                    + "] must have min_doc_count of 0");
        }
    }
}
 
Example #12
Source File: ValuesSourceAggregatorFactory.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private void resolveValuesSourceConfigFromAncestors(String aggName, AggregatorFactory parent, Class<VS> requiredValuesSourceType) {
    ValuesSourceConfig config;
    while (parent != null) {
        if (parent instanceof ValuesSourceAggregatorFactory) {
            config = ((ValuesSourceAggregatorFactory) parent).config;
            if (config != null && config.valid()) {
                if (requiredValuesSourceType == null || requiredValuesSourceType.isAssignableFrom(config.valueSourceType)) {
                    ValueFormat format = config.format;
                    this.config = config;
                    // if the user explicitly defined a format pattern, we'll do our best to keep it even when we inherit the
                    // value source form one of the ancestor aggregations
                    if (this.config.formatPattern != null && format != null && format instanceof ValueFormat.Patternable) {
                        this.config.format = ((ValueFormat.Patternable) format).create(this.config.formatPattern);
                    }
                    return;
                }
            }
        }
        parent = parent.parent();
    }
    throw new AggregationExecutionException("could not find the appropriate value context to perform aggregation [" + aggName + "]");
}
 
Example #13
Source File: PredictionAggregationBuilder.java    From elasticsearch-linear-regression with Apache License 2.0 6 votes vote down vote up
@Override
protected MultiValuesSourceAggregatorFactory<Numeric, ?> innerInnerBuild(
    final SearchContext context,
    final List<NamedValuesSourceConfigSpec<Numeric>> configs, final MultiValueMode multiValueMode,
    final AggregatorFactory<?> parent, final Builder subFactoriesBuilder) throws IOException {
  if (this.inputs == null || this.inputs.length != configs.size() - 1) {
    throw new IllegalArgumentException(
        "[inputs] must have [" + (configs.size() - 1)
            + "] values as much as the number of feature fields: ["
            + this.name
            + "]");
  }
  return new PredictionAggregatorFactory(this.name, configs, multiValueMode, this.inputs,
      context,
      parent,
      subFactoriesBuilder, this.metaData);
}
 
Example #14
Source File: MissingParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser vsParser = ValuesSourceParser.any(aggregationName, InternalMissing.TYPE, context)
            .scriptable(false)
            .build();

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    return new MissingAggregator.Factory(aggregationName, vsParser.config());
}
 
Example #15
Source File: PercentilesParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected AggregatorFactory buildFactory(SearchContext context, String aggregationName, ValuesSourceConfig<Numeric> valuesSourceConfig,
        double[] keys, PercentilesMethod method, Double compression, Integer numberOfSignificantValueDigits, boolean keyed) {
    if (keys == null) {
        keys = DEFAULT_PERCENTS;
    }
    if (method == PercentilesMethod.TDIGEST) {
        return new TDigestPercentilesAggregator.Factory(aggregationName, valuesSourceConfig, keys, compression, keyed);
    } else if (method == PercentilesMethod.HDR) {
        return new HDRPercentilesAggregator.Factory(aggregationName, valuesSourceConfig, keys, numberOfSignificantValueDigits, keyed);
    } else {
        throw new AssertionError();
    }
}
 
Example #16
Source File: GeoShapeBuilder.java    From elasticsearch-plugin-geoshape with MIT License 5 votes vote down vote up
@Override
protected ValuesSourceAggregatorFactory<ValuesSource> innerBuild(
        QueryShardContext queryShardContext,
        ValuesSourceConfig<ValuesSource> config,
        AggregatorFactory parent,
        AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
    return new GeoShapeAggregatorFactory(
            name, config, output_format, must_simplify, simplify_zoom, simplify_algorithm,
            bucketCountThresholds, queryShardContext, parent, subFactoriesBuilder, metaData);
}
 
Example #17
Source File: MultiValuesSourceAggregatorFactory.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
public MultiValuesSourceAggregatorFactory(String name,
    List<NamedValuesSourceConfigSpec<VS>> configs,
    SearchContext context, AggregatorFactory<?> parent,
    AggregatorFactories.Builder subFactoriesBuilder,
    Map<String, Object> metaData) throws IOException {
  super(name, context, parent, subFactoriesBuilder, metaData);
  this.configs = configs;
}
 
Example #18
Source File: CardinalityParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatorFactory parse(String name, XContentParser parser, SearchContext context) throws IOException {

    ValuesSourceParser<?> vsParser = ValuesSourceParser.any(name, InternalCardinality.TYPE, context).formattable(false).build();

    long precisionThreshold = -1;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (vsParser.token(currentFieldName, token, parser)) {
            continue;
        } else if (token.isValue()) {
            if (context.parseFieldMatcher().match(currentFieldName, REHASH)) {
                // ignore
            } else if (context.parseFieldMatcher().match(currentFieldName, PRECISION_THRESHOLD)) {
                precisionThreshold = parser.longValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + name + "]: [" + currentFieldName
                        + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + name + "].", parser.getTokenLocation());
        }
    }

    return new CardinalityAggregatorFactory(name, vsParser.config(), precisionThreshold);

}
 
Example #19
Source File: NestedParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    String path = null;

    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token == XContentParser.Token.VALUE_STRING) {
            if ("path".equals(currentFieldName)) {
                path = parser.text();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unexpected token " + token + " in [" + aggregationName + "].",
                    parser.getTokenLocation());
        }
    }

    if (path == null) {
        // "field" doesn't exist, so we fall back to the context of the ancestors
        throw new SearchParseException(context, "Missing [path] field for nested aggregation [" + aggregationName + "]",
                parser.getTokenLocation());
    }

    return new NestedAggregator.Factory(aggregationName, path);
}
 
Example #20
Source File: SignificantTermsParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    SignificantTermsParametersParser aggParser = new SignificantTermsParametersParser(significanceHeuristicParserMapper);
    ValuesSourceParser vsParser = ValuesSourceParser.any(aggregationName, SignificantStringTerms.TYPE, context)
            .scriptable(false)
            .formattable(true)
            .build();
    IncludeExclude.Parser incExcParser = new IncludeExclude.Parser();
    aggParser.parse(aggregationName, parser, context, vsParser, incExcParser);

    TermsAggregator.BucketCountThresholds bucketCountThresholds = aggParser.getBucketCountThresholds();
    if (bucketCountThresholds.getShardSize() == aggParser.getDefaultBucketCountThresholds().getShardSize()) {
        //The user has not made a shardSize selection .
        //Use default heuristic to avoid any wrong-ranking caused by distributed counting
        //but request double the usual amount.
        //We typically need more than the number of "top" terms requested by other aggregations
        //as the significance algorithm is in less of a position to down-select at shard-level -
        //some of the things we want to find have only one occurrence on each shard and as
        // such are impossible to differentiate from non-significant terms at that early stage.
        bucketCountThresholds.setShardSize(2 * BucketUtils.suggestShardSideQueueSize(bucketCountThresholds.getRequiredSize(), context.numberOfShards()));
    }

    bucketCountThresholds.ensureValidity();
    SignificanceHeuristic significanceHeuristic = aggParser.getSignificanceHeuristic();
    if (significanceHeuristic == null) {
        significanceHeuristic = JLHScore.INSTANCE;
    }
    return new SignificantTermsAggregatorFactory(aggregationName, vsParser.config(), bucketCountThresholds, aggParser.getIncludeExclude(), aggParser.getExecutionHint(), aggParser.getFilter(), significanceHeuristic);
}
 
Example #21
Source File: MultiValuesSourceAggregationBuilder.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
@Override
protected final MultiValuesSourceAggregatorFactory<VS, ?> doBuild(SearchContext context,
    AggregatorFactory<?> parent,
    AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
  List<NamedValuesSourceConfigSpec<VS>> configs = resolveConfig(context);
  MultiValuesSourceAggregatorFactory<VS, ?> factory = innerBuild(context, configs, parent,
      subFactoriesBuilder);
  return factory;
}
 
Example #22
Source File: GeoPointClusteringAggregatorFactory.java    From elasticsearch-aggregation-geoclustering with Apache License 2.0 5 votes vote down vote up
GeoPointClusteringAggregatorFactory(
        String name, ValuesSourceConfig<GeoPoint> config, int precision, double radius, double ratio,
        int requiredSize, int shardSize, QueryShardContext context,
        AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder, Map<String, Object> metaData
) throws IOException {
    super(name, config, context, parent, subFactoriesBuilder, metaData);
    this.precision = precision;
    this.radius = radius;
    this.ratio = ratio;
    this.requiredSize = requiredSize;
    this.shardSize = shardSize;
}
 
Example #23
Source File: PredictionAggregatorFactory.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
public PredictionAggregatorFactory(final String name,
    final List<NamedValuesSourceConfigSpec<Numeric>> configs, final MultiValueMode multiValueMode,
    final double[] inputs, final SearchContext context, final AggregatorFactory<?> parent,
    final Builder subFactoriesBuilder,
    final Map<String, Object> metaData) throws IOException {
  super(name, configs, context, parent, subFactoriesBuilder, metaData);
  this.multiValueMode = multiValueMode;
  this.inputs = inputs;
}
 
Example #24
Source File: StatsAggregatorFactory.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
public StatsAggregatorFactory(String name,
    List<NamedValuesSourceConfigSpec<Numeric>> configs, MultiValueMode multiValueMode,
    SearchContext context, AggregatorFactory<?> parent,
    AggregatorFactories.Builder subFactoriesBuilder,
    Map<String, Object> metaData) throws IOException {
  super(name, configs, context, parent, subFactoriesBuilder, metaData);
  this.multiValueMode = multiValueMode;
}
 
Example #25
Source File: StatsAggregationBuilder.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
@Override
protected StatsAggregatorFactory innerInnerBuild(final SearchContext context,
    final List<NamedValuesSourceConfigSpec<Numeric>> configs, final MultiValueMode multiValueMode,
    final AggregatorFactory<?> parent, final AggregatorFactories.Builder subFactoriesBuilder)
    throws IOException {
  return new StatsAggregatorFactory(this.name, configs, multiValueMode, context, parent,
      subFactoriesBuilder, this.metaData);
}
 
Example #26
Source File: TermsParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    TermsParametersParser aggParser = new TermsParametersParser();
    ValuesSourceParser vsParser = ValuesSourceParser.any(aggregationName, StringTerms.TYPE, context).scriptable(true).formattable(true).build();
    IncludeExclude.Parser incExcParser = new IncludeExclude.Parser();
    aggParser.parse(aggregationName, parser, context, vsParser, incExcParser);

    List<OrderElement> orderElements = aggParser.getOrderElements();
    List<Terms.Order> orders = new ArrayList<>(orderElements.size());
    for (OrderElement orderElement : orderElements) {
        orders.add(resolveOrder(orderElement.key(), orderElement.asc()));
    }
    Terms.Order order;
    if (orders.size() == 1 && (orders.get(0) == InternalOrder.TERM_ASC || orders.get(0) == InternalOrder.TERM_DESC))
    {
        // If order is only terms order then we don't need compound ordering
        order = orders.get(0);
    }
    else
    {
        // for all other cases we need compound order so term order asc can be added to make the order deterministic
        order = Order.compound(orders);
    }
    TermsAggregator.BucketCountThresholds bucketCountThresholds = aggParser.getBucketCountThresholds();
    if (!(order == InternalOrder.TERM_ASC || order == InternalOrder.TERM_DESC)
            && bucketCountThresholds.getShardSize() == aggParser.getDefaultBucketCountThresholds().getShardSize()) {
        // The user has not made a shardSize selection. Use default heuristic to avoid any wrong-ranking caused by distributed counting
        bucketCountThresholds.setShardSize(BucketUtils.suggestShardSideQueueSize(bucketCountThresholds.getRequiredSize(),
                context.numberOfShards()));
    }
    bucketCountThresholds.ensureValidity();
    return new TermsAggregatorFactory(aggregationName, vsParser.config(), order, bucketCountThresholds, aggParser.getIncludeExclude(), aggParser.getExecutionHint(), aggParser.getCollectionMode(), aggParser.showTermDocCountError());
}
 
Example #27
Source File: BaseAggregatorFactory.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
public BaseAggregatorFactory(final String name,
    final List<ValuesSourceConfig<Numeric>> featureConfigs,
    final ValuesSourceConfig<Numeric> responseConfig,
    final SearchContext context,
    final AggregatorFactory<?> parent, final AggregatorFactories.Builder subFactoriesBuilder,
    final Map<String, Object> metaData) throws IOException {
  super(name, context, parent, subFactoriesBuilder, metaData);
  this.featureConfigs = featureConfigs;
  this.responseConfig = responseConfig;
}
 
Example #28
Source File: GeoBoundsParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public AggregatorFactory parse(String aggregationName, XContentParser parser, SearchContext context) throws IOException {
    ValuesSourceParser<GeoPoint> vsParser = ValuesSourceParser.geoPoint(aggregationName, InternalGeoBounds.TYPE, context)
            .targetValueType(ValueType.GEOPOINT)
            .formattable(true)
            .build();
    boolean wrapLongitude = true;
    XContentParser.Token token;
    String currentFieldName = null;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (vsParser.token(currentFieldName, token, parser)) {
            continue;
            
        } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
            if ("wrap_longitude".equals(currentFieldName) || "wrapLongitude".equals(currentFieldName)) {
                wrapLongitude = parser.booleanValue();
            } else {
                throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                        + currentFieldName + "].", parser.getTokenLocation());
            }
        } else {
            throw new SearchParseException(context, "Unknown key for a " + token + " in aggregation [" + aggregationName + "]: ["
                    + currentFieldName + "].", parser.getTokenLocation());
        }
    }
    return new GeoBoundsAggregator.Factory(aggregationName, vsParser.config(), wrapLongitude);
}
 
Example #29
Source File: BaseAggregationBuilder.java    From elasticsearch-linear-regression with Apache License 2.0 5 votes vote down vote up
@Override
protected final MultiValuesSourceAggregatorFactory<ValuesSource.Numeric, ?> innerBuild(
    final SearchContext context,
    final List<NamedValuesSourceConfigSpec<Numeric>> configs,
    final AggregatorFactory<?> parent, final AggregatorFactories.Builder subFactoriesBuilder)
    throws IOException {
  return innerInnerBuild(context, configs, this.multiValueMode, parent, subFactoriesBuilder);
}
 
Example #30
Source File: PercentileRanksParser.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected AggregatorFactory buildFactory(SearchContext context, String aggregationName, ValuesSourceConfig<Numeric> valuesSourceConfig,
        double[] keys, PercentilesMethod method, Double compression, Integer numberOfSignificantValueDigits, boolean keyed) {
    if (keys == null) {
        throw new SearchParseException(context, "Missing token values in [" + aggregationName + "].", null);
    }
    if (method == PercentilesMethod.TDIGEST) {
        return new TDigestPercentileRanksAggregator.Factory(aggregationName, valuesSourceConfig, keys, compression, keyed);
    } else if (method == PercentilesMethod.HDR) {
        return new HDRPercentileRanksAggregator.Factory(aggregationName, valuesSourceConfig, keys, numberOfSignificantValueDigits,
                keyed);
    } else {
        throw new AssertionError();
    }
}