Java Code Examples for org.elasticsearch.search.aggregations.AggregatorFactories#Builder

The following examples show how to use org.elasticsearch.search.aggregations.AggregatorFactories#Builder . 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: 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 2
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 3
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 4
Source File: ParseUtils.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
public static String generateInternalFeatureQueryTemplate(AnomalyDetector detector, NamedXContentRegistry xContentRegistry)
    throws IOException {
    RangeQueryBuilder rangeQuery = new RangeQueryBuilder(detector.getTimeField())
        .from("{{" + QUERY_PARAM_PERIOD_START + "}}")
        .to("{{" + QUERY_PARAM_PERIOD_END + "}}");

    BoolQueryBuilder internalFilterQuery = QueryBuilders.boolQuery().must(rangeQuery).must(detector.getFilterQuery());

    SearchSourceBuilder internalSearchSourceBuilder = new SearchSourceBuilder().query(internalFilterQuery);
    if (detector.getFeatureAttributes() != null) {
        for (Feature feature : detector.getFeatureAttributes()) {
            AggregatorFactories.Builder internalAgg = parseAggregators(
                feature.getAggregation().toString(),
                xContentRegistry,
                feature.getId()
            );
            internalSearchSourceBuilder.aggregation(internalAgg.getAggregatorFactories().iterator().next());
        }
    }

    return internalSearchSourceBuilder.toString();
}
 
Example 5
Source File: ParseUtils.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
public static SearchSourceBuilder generatePreviewQuery(
    AnomalyDetector detector,
    List<Entry<Long, Long>> ranges,
    NamedXContentRegistry xContentRegistry
) throws IOException {

    DateRangeAggregationBuilder dateRangeBuilder = dateRange("date_range").field(detector.getTimeField()).format("epoch_millis");
    for (Entry<Long, Long> range : ranges) {
        dateRangeBuilder.addRange(range.getKey(), range.getValue());
    }

    if (detector.getFeatureAttributes() != null) {
        for (Feature feature : detector.getFeatureAttributes()) {
            AggregatorFactories.Builder internalAgg = parseAggregators(
                feature.getAggregation().toString(),
                xContentRegistry,
                feature.getId()
            );
            dateRangeBuilder.subAggregation(internalAgg.getAggregatorFactories().iterator().next());
        }
    }

    return new SearchSourceBuilder().query(detector.getFilterQuery()).size(0).aggregation(dateRangeBuilder);
}
 
Example 6
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 7
Source File: ParseUtils.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
public static SearchSourceBuilder generateInternalFeatureQuery(
    AnomalyDetector detector,
    long startTime,
    long endTime,
    NamedXContentRegistry xContentRegistry
) throws IOException {
    RangeQueryBuilder rangeQuery = new RangeQueryBuilder(detector.getTimeField())
        .from(startTime)
        .to(endTime)
        .format("epoch_millis")
        .includeLower(true)
        .includeUpper(false);

    BoolQueryBuilder internalFilterQuery = QueryBuilders.boolQuery().must(rangeQuery).must(detector.getFilterQuery());

    SearchSourceBuilder internalSearchSourceBuilder = new SearchSourceBuilder().query(internalFilterQuery);
    if (detector.getFeatureAttributes() != null) {
        for (Feature feature : detector.getFeatureAttributes()) {
            AggregatorFactories.Builder internalAgg = parseAggregators(
                feature.getAggregation().toString(),
                xContentRegistry,
                feature.getId()
            );
            internalSearchSourceBuilder.aggregation(internalAgg.getAggregatorFactories().iterator().next());
        }
    }

    return internalSearchSourceBuilder;
}
 
Example 8
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 9
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 10
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 11
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 12
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 13
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 14
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 15
Source File: ParseUtilsTests.java    From anomaly-detection with Apache License 2.0 4 votes vote down vote up
public void testParseAggregatorsWithAggregationQueryString() throws IOException {
    AggregatorFactories.Builder agg = ParseUtils
        .parseAggregators("{\"aa\":{\"value_count\":{\"field\":\"ok\"}}}", TestHelpers.xContentRegistry(), "test");
    assertEquals("test", agg.getAggregatorFactories().iterator().next().getName());
}
 
Example 16
Source File: ParseUtilsTests.java    From anomaly-detection with Apache License 2.0 4 votes vote down vote up
public void testParseAggregatorsWithAggregationQueryStringAndNullAggName() throws IOException {
    AggregatorFactories.Builder agg = ParseUtils
        .parseAggregators("{\"aa\":{\"value_count\":{\"field\":\"ok\"}}}", TestHelpers.xContentRegistry(), null);
    assertEquals("aa", agg.getAggregatorFactories().iterator().next().getName());
}
 
Example 17
Source File: TestHelpers.java    From anomaly-detection with Apache License 2.0 4 votes vote down vote up
public static AggregationBuilder randomAggregation(String aggregationName) throws IOException {
    XContentParser parser = parser("{\"" + aggregationName + "\":{\"value_count\":{\"field\":\"ok\"}}}");

    AggregatorFactories.Builder parsed = AggregatorFactories.parseAggregators(parser);
    return parsed.getAggregatorFactories().iterator().next();
}
 
Example 18
Source File: BaseAggregationBuilder.java    From elasticsearch-linear-regression with Apache License 2.0 4 votes vote down vote up
protected abstract MultiValuesSourceAggregatorFactory<ValuesSource.Numeric, ?> innerInnerBuild(
SearchContext context,
List<NamedValuesSourceConfigSpec<Numeric>> configs, MultiValueMode multiValueMode,
AggregatorFactory<?> parent, AggregatorFactories.Builder subFactoriesBuilder)
throws IOException;
 
Example 19
Source File: PathHierarchyAggregationBuilder.java    From elasticsearch-aggregation-pathhierarchy with MIT License 4 votes vote down vote up
@Override
protected AggregationBuilder shallowCopy(AggregatorFactories.Builder factoriesBuilder, Map<String, Object> metaData) {
    return new PathHierarchyAggregationBuilder(this, factoriesBuilder, metaData);
}
 
Example 20
Source File: GeoShapeBuilder.java    From elasticsearch-plugin-geoshape with MIT License 4 votes vote down vote up
@Override
protected AggregationBuilder shallowCopy(AggregatorFactories.Builder factoriesBuilder, Map<String, Object> metaData) {
    return new GeoShapeBuilder(this, factoriesBuilder, metaData);
}