org.elasticsearch.search.aggregations.bucket.terms.InternalMappedRareTerms Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of elasticsearch Show documentation
Show all versions of elasticsearch Show documentation
Elasticsearch subproject :server
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.elasticsearch.search.aggregations.bucket.terms;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.CollectionUtil;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.util.SetBackedScalingCuckooFilter;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.aggregations.AggregationExecutionException;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
public abstract class InternalMappedRareTerms, B extends InternalRareTerms.Bucket>
extends InternalRareTerms {
protected DocValueFormat format;
protected List buckets;
protected Map bucketMap;
final SetBackedScalingCuckooFilter filter;
protected final Logger logger = LogManager.getLogger(getClass());
InternalMappedRareTerms(String name, BucketOrder order, List pipelineAggregators,
Map metaData, DocValueFormat format,
List buckets, long maxDocCount, SetBackedScalingCuckooFilter filter) {
super(name, order, maxDocCount, pipelineAggregators, metaData);
this.format = format;
this.buckets = buckets;
this.filter = filter;
}
public long getMaxDocCount() {
return maxDocCount;
}
SetBackedScalingCuckooFilter getFilter() {
return filter;
}
/**
* Read from a stream.
*/
InternalMappedRareTerms(StreamInput in, Bucket.Reader bucketReader) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
buckets = in.readList(stream -> bucketReader.read(stream, format));
filter = new SetBackedScalingCuckooFilter(in, Randomness.get());
}
@Override
protected void writeTermTypeInfoTo(StreamOutput out) throws IOException {
out.writeNamedWriteable(format);
out.writeList(buckets);
filter.writeTo(out);
}
@Override
public InternalAggregation reduce(List aggregations, ReduceContext reduceContext) {
Map