下面列出了怎么用org.elasticsearch.search.aggregations.AggregatorFactories的API类实例代码及写法,或者点击链接到github查看源代码。
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);
}
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();
}
public RangeAggregator(String name, AggregatorFactories factories, ValuesSource.Numeric valuesSource, ValueFormat format,
InternalRange.Factory rangeFactory, List<Range> ranges, boolean keyed, AggregationContext aggregationContext,
Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
assert valuesSource != null;
this.valuesSource = valuesSource;
this.formatter = format.formatter();
this.keyed = keyed;
this.rangeFactory = rangeFactory;
this.ranges = ranges.toArray(new Range[ranges.size()]);
ValueParser parser = format != null ? format.parser() : ValueParser.RAW;
for (int i = 0; i < this.ranges.length; i++) {
this.ranges[i].process(parser, context.searchContext());
}
sortRanges(this.ranges);
maxTo = new double[this.ranges.length];
maxTo[0] = this.ranges[0].to;
for (int i = 1; i < this.ranges.length; ++i) {
maxTo[i] = Math.max(this.ranges[i].to,maxTo[i-1]);
}
}
public HistogramAggregator(String name, AggregatorFactories factories, Rounding rounding, InternalOrder order, boolean keyed,
long minDocCount, @Nullable ExtendedBounds extendedBounds, @Nullable ValuesSource.Numeric valuesSource,
ValueFormatter formatter, InternalHistogram.Factory<?> histogramFactory, AggregationContext aggregationContext,
Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
this.rounding = rounding;
this.order = order;
this.keyed = keyed;
this.minDocCount = minDocCount;
this.extendedBounds = extendedBounds;
this.valuesSource = valuesSource;
this.formatter = formatter;
this.histogramFactory = histogramFactory;
bucketOrds = new LongHash(1, aggregationContext.bigArrays());
}
public FiltersAggregator(String name, AggregatorFactories factories, String[] keys, Weight[] filters, boolean keyed, String otherBucketKey,
AggregationContext aggregationContext,
Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
throws IOException {
super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
this.keyed = keyed;
this.keys = keys;
this.filters = filters;
this.showOtherBucket = otherBucketKey != null;
this.otherBucketKey = otherBucketKey;
if (showOtherBucket) {
this.totalNumKeys = keys.length + 1;
} else {
this.totalNumKeys = keys.length;
}
}
@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);
}
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;
}
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;
}
public DateHierarchyAggregator(
String name,
AggregatorFactories factories,
SearchContext context,
ValuesSource.Numeric valuesSource,
BucketOrder order,
long minDocCount,
BucketCountThresholds bucketCountThresholds,
List<DateHierarchyAggregationBuilder.RoundingInfo> roundingsInfo,
Aggregator parent,
List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData
) throws IOException {
super(name, factories, context, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.roundingsInfo = roundingsInfo;
this.minDocCount = minDocCount;
bucketOrds = new BytesRefHash(1, context.bigArrays());
this.order = InternalOrder.validate(order, this);
this.bucketCountThresholds = bucketCountThresholds;
}
public PathHierarchyAggregator(
String name,
AggregatorFactories factories,
SearchContext context,
ValuesSource valuesSource,
BucketOrder order,
long minDocCount,
BucketCountThresholds bucketCountThresholds,
BytesRef separator,
int minDepth,
Aggregator parent,
List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData
) throws IOException {
super(name, factories, context, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.separator = separator;
this.minDocCount = minDocCount;
bucketOrds = new BytesRefHash(1, context.bigArrays());
this.order = InternalOrder.validate(order, this);
this.bucketCountThresholds = bucketCountThresholds;
this.minDepth = minDepth;
}
public GeoShapeAggregator(
String name,
AggregatorFactories factories,
SearchContext context,
ValuesSource valuesSource,
InternalGeoShape.OutputFormat output_format,
boolean must_simplify,
int zoom,
GeoShape.Algorithm algorithm,
BucketCountThresholds bucketCountThresholds,
Aggregator parent,
List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData
) throws IOException {
super(name, factories, context, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.output_format = output_format;
this.must_simplify = must_simplify;
this.zoom = zoom;
this.algorithm = algorithm;
bucketOrds = new BytesRefHash(1, context.bigArrays());
this.bucketCountThresholds = bucketCountThresholds;
this.wkbReader = new WKBReader();
this.geometryFactory = new GeometryFactory();
}
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;
}
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;
}
public SignificantStringTermsAggregator(String name, AggregatorFactories factories, ValuesSource valuesSource,
BucketCountThresholds bucketCountThresholds,
IncludeExclude.StringFilter includeExclude, AggregationContext aggregationContext, Aggregator parent,
SignificantTermsAggregatorFactory termsAggFactory, List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData)
throws IOException {
super(name, factories, valuesSource, null, bucketCountThresholds, includeExclude, aggregationContext, parent,
SubAggCollectionMode.DEPTH_FIRST, false, pipelineAggregators, metaData);
this.termsAggFactory = termsAggFactory;
}
public GlobalOrdinalsSignificantTermsAggregator(String name, AggregatorFactories factories,
ValuesSource.Bytes.WithOrdinals.FieldData valuesSource, BucketCountThresholds bucketCountThresholds,
IncludeExclude.OrdinalsFilter includeExclude, AggregationContext aggregationContext, Aggregator parent,
SignificantTermsAggregatorFactory termsAggFactory, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
throws IOException {
super(name, factories, valuesSource, null, bucketCountThresholds, includeExclude, aggregationContext, parent,
SubAggCollectionMode.DEPTH_FIRST, false, pipelineAggregators, metaData);
this.termsAggFactory = termsAggFactory;
}
public WithHash(String name, AggregatorFactories factories, ValuesSource.Bytes.WithOrdinals.FieldData valuesSource,
BucketCountThresholds bucketCountThresholds, IncludeExclude.OrdinalsFilter includeExclude,
AggregationContext aggregationContext, Aggregator parent, SignificantTermsAggregatorFactory termsAggFactory,
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
super(name, factories, valuesSource, bucketCountThresholds, includeExclude, aggregationContext, parent, termsAggFactory,
pipelineAggregators, metaData);
bucketOrds = new LongHash(1, aggregationContext.bigArrays());
}
public SignificantLongTermsAggregator(String name, AggregatorFactories factories, ValuesSource.Numeric valuesSource,
ValueFormat format, BucketCountThresholds bucketCountThresholds, AggregationContext aggregationContext, Aggregator parent,
SignificantTermsAggregatorFactory termsAggFactory, IncludeExclude.LongFilter includeExclude,
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
super(name, factories, valuesSource, format, null, bucketCountThresholds, aggregationContext, parent,
SubAggCollectionMode.DEPTH_FIRST, false, includeExclude, pipelineAggregators, metaData);
this.termsAggFactory = termsAggFactory;
}
public ParentToChildrenAggregator(String name, AggregatorFactories factories, AggregationContext aggregationContext,
Aggregator parent, String parentType, Query childFilter, Query parentFilter,
ValuesSource.Bytes.WithOrdinals.ParentChild valuesSource,
long maxOrd, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
this.parentType = parentType;
// these two filters are cached in the parser
this.childFilter = aggregationContext.searchContext().searcher().createNormalizedWeight(childFilter, false);
this.parentFilter = aggregationContext.searchContext().searcher().createNormalizedWeight(parentFilter, false);
this.parentOrdToBuckets = aggregationContext.bigArrays().newLongArray(maxOrd, false);
this.parentOrdToBuckets.fill(0, maxOrd, -1);
this.parentOrdToOtherBuckets = new LongObjectPagedHashMap<>(aggregationContext.bigArrays());
this.valuesSource = valuesSource;
}
public StringTermsAggregator(String name, AggregatorFactories factories, ValuesSource valuesSource,
Terms.Order order, BucketCountThresholds bucketCountThresholds,
IncludeExclude.StringFilter includeExclude, AggregationContext aggregationContext,
Aggregator parent, SubAggCollectionMode collectionMode, boolean showTermDocCountError, List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException {
super(name, factories, aggregationContext, parent, order, bucketCountThresholds, collectionMode, showTermDocCountError, pipelineAggregators,
metaData);
this.valuesSource = valuesSource;
this.includeExclude = includeExclude;
bucketOrds = new BytesRefHash(1, aggregationContext.bigArrays());
}
public LongTermsAggregator(String name, AggregatorFactories factories, ValuesSource.Numeric valuesSource, ValueFormat format,
Terms.Order order, BucketCountThresholds bucketCountThresholds, AggregationContext aggregationContext, Aggregator parent,
SubAggCollectionMode subAggCollectMode, boolean showTermDocCountError, IncludeExclude.LongFilter longFilter,
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
super(name, factories, aggregationContext, parent, bucketCountThresholds, order, subAggCollectMode, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.showTermDocCountError = showTermDocCountError;
this.formatter = format.formatter();
this.longFilter = longFilter;
bucketOrds = new LongHash(1, aggregationContext.bigArrays());
}
public DoubleTermsAggregator(String name, AggregatorFactories factories, ValuesSource.Numeric valuesSource, ValueFormat format,
Terms.Order order, BucketCountThresholds bucketCountThresholds, AggregationContext aggregationContext, Aggregator parent,
SubAggCollectionMode collectionMode, boolean showTermDocCountError, IncludeExclude.LongFilter longFilter,
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
super(name, factories, valuesSource, format, order, bucketCountThresholds, aggregationContext, parent, collectionMode,
showTermDocCountError, longFilter, pipelineAggregators, metaData);
}
public GlobalOrdinalsStringTermsAggregator(String name, AggregatorFactories factories, ValuesSource.Bytes.WithOrdinals valuesSource,
Terms.Order order, BucketCountThresholds bucketCountThresholds,
IncludeExclude.OrdinalsFilter includeExclude,
AggregationContext aggregationContext, Aggregator parent, SubAggCollectionMode collectionMode, boolean showTermDocCountError,
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
super(name, factories, aggregationContext, parent, order, bucketCountThresholds, collectionMode, showTermDocCountError,
pipelineAggregators,
metaData);
this.valuesSource = valuesSource;
this.includeExclude = includeExclude;
}
public WithHash(String name, AggregatorFactories factories, ValuesSource.Bytes.WithOrdinals valuesSource,
Terms.Order order, BucketCountThresholds bucketCountThresholds, IncludeExclude.OrdinalsFilter includeExclude, AggregationContext aggregationContext,
Aggregator parent, SubAggCollectionMode collectionMode,
boolean showTermDocCountError, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
throws IOException {
super(name, factories, valuesSource, order, bucketCountThresholds, includeExclude, aggregationContext, parent, collectionMode,
showTermDocCountError, pipelineAggregators, metaData);
bucketOrds = new LongHash(1, aggregationContext.bigArrays());
}
public LowCardinality(String name, AggregatorFactories factories, ValuesSource.Bytes.WithOrdinals valuesSource,
Terms.Order order,
BucketCountThresholds bucketCountThresholds, AggregationContext aggregationContext, Aggregator parent,
SubAggCollectionMode collectionMode, boolean showTermDocCountError, List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException {
super(name, factories, valuesSource, order, bucketCountThresholds, null, aggregationContext, parent, collectionMode,
showTermDocCountError, pipelineAggregators, metaData);
assert factories == null || factories.count() == 0;
this.segmentDocCounts = context.bigArrays().newIntArray(1, true);
}
public DiversifiedMapSamplerAggregator(String name, int shardSize, AggregatorFactories factories,
AggregationContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData,
ValuesSource valuesSource, int maxDocsPerValue) throws IOException {
super(name, shardSize, factories, aggregationContext, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.maxDocsPerValue = maxDocsPerValue;
bucketOrds = new BytesRefHash(shardSize, aggregationContext.bigArrays());
}
public DiversifiedBytesHashSamplerAggregator(String name, int shardSize, AggregatorFactories factories,
AggregationContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData,
ValuesSource valuesSource,
int maxDocsPerValue) throws IOException {
super(name, shardSize, factories, aggregationContext, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.maxDocsPerValue = maxDocsPerValue;
}
public DiversifiedOrdinalsSamplerAggregator(String name, int shardSize, AggregatorFactories factories,
AggregationContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData,
ValuesSource.Bytes.WithOrdinals.FieldData valuesSource, int maxDocsPerValue) throws IOException {
super(name, shardSize, factories, aggregationContext, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.maxDocsPerValue = maxDocsPerValue;
}
public DiversifiedNumericSamplerAggregator(String name, int shardSize, AggregatorFactories factories,
AggregationContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData,
ValuesSource.Numeric valuesSource, int maxDocsPerValue) throws IOException {
super(name, shardSize, factories, aggregationContext, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.maxDocsPerValue = maxDocsPerValue;
}
public GeoHashGridAggregator(String name, AggregatorFactories factories, GeoHashGridParser.GeoGridFactory.CellIdSource valuesSource,
int requiredSize, int shardSize, AggregationContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators,
Map<String, Object> metaData) throws IOException {
super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
this.valuesSource = valuesSource;
this.requiredSize = requiredSize;
this.shardSize = shardSize;
bucketOrds = new LongHash(1, aggregationContext.bigArrays());
}
public ReverseNestedAggregator(String name, AggregatorFactories factories, ObjectMapper objectMapper,
AggregationContext aggregationContext, Aggregator parent, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData)
throws IOException {
super(name, factories, aggregationContext, parent, pipelineAggregators, metaData);
if (objectMapper == null) {
parentFilter = Queries.newNonNestedFilter();
} else {
parentFilter = objectMapper.nestedTypeFilter();
}
parentBitsetProducer = context.searchContext().bitsetFilterCache().getBitSetProducer(parentFilter);
}