mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
parent
cd982ade99
commit
7d94cc99a7
@ -75,7 +75,7 @@ public class GeoDistanceAggregatorBuilder extends ValuesSourceAggregatorBuilder<
|
|||||||
int size = in.readVInt();
|
int size = in.readVInt();
|
||||||
ranges = new ArrayList<>(size);
|
ranges = new ArrayList<>(size);
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
ranges.add(Range.PROTOTYPE.readFrom(in));
|
ranges.add(new Range(in));
|
||||||
}
|
}
|
||||||
keyed = in.readBoolean();
|
keyed = in.readBoolean();
|
||||||
distanceType = GeoDistance.readFromStream(in);
|
distanceType = GeoDistance.readFromStream(in);
|
||||||
|
@ -54,13 +54,24 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Range extends RangeAggregator.Range {
|
public static class Range extends RangeAggregator.Range {
|
||||||
|
|
||||||
static final Range PROTOTYPE = new Range(null, null, null);
|
|
||||||
|
|
||||||
public Range(String key, Double from, Double to) {
|
public Range(String key, Double from, Double to) {
|
||||||
super(key(key, from, to), from == null ? 0 : from, to);
|
super(key(key, from, to), from == null ? 0 : from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read from a stream.
|
||||||
|
*/
|
||||||
|
public Range(StreamInput in) throws IOException {
|
||||||
|
super(in.readOptionalString(), in.readDouble(), in.readDouble());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
out.writeOptionalString(key);
|
||||||
|
out.writeDouble(from);
|
||||||
|
out.writeDouble(to);
|
||||||
|
}
|
||||||
|
|
||||||
private static String key(String key, Double from, Double to) {
|
private static String key(String key, Double from, Double to) {
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
return key;
|
return key;
|
||||||
@ -71,22 +82,6 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser {
|
|||||||
sb.append((to == null || Double.isInfinite(to)) ? "*" : to);
|
sb.append((to == null || Double.isInfinite(to)) ? "*" : to);
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Range readFrom(StreamInput in) throws IOException {
|
|
||||||
String key = in.readOptionalString();
|
|
||||||
double from = in.readDouble();
|
|
||||||
double to = in.readDouble();
|
|
||||||
return new Range(key, from, to);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
|
||||||
out.writeOptionalString(key);
|
|
||||||
out.writeDouble(from);
|
|
||||||
out.writeDouble(to);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,14 +71,10 @@ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBui
|
|||||||
*/
|
*/
|
||||||
public SignificantTermsAggregatorBuilder(StreamInput in) throws IOException {
|
public SignificantTermsAggregatorBuilder(StreamInput in) throws IOException {
|
||||||
super(in, SignificantStringTerms.TYPE, ValuesSourceType.ANY);
|
super(in, SignificantStringTerms.TYPE, ValuesSourceType.ANY);
|
||||||
bucketCountThresholds = BucketCountThresholds.readFromStream(in);
|
bucketCountThresholds = new BucketCountThresholds(in);
|
||||||
executionHint = in.readOptionalString();
|
executionHint = in.readOptionalString();
|
||||||
if (in.readBoolean()) {
|
filterBuilder = in.readOptionalNamedWriteable(QueryBuilder.class);
|
||||||
filterBuilder = in.readNamedWriteable(QueryBuilder.class);
|
includeExclude = in.readOptionalWriteable(IncludeExclude::new);
|
||||||
}
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
includeExclude = IncludeExclude.readFromStream(in);
|
|
||||||
}
|
|
||||||
significanceHeuristic = in.readNamedWriteable(SignificanceHeuristic.class);
|
significanceHeuristic = in.readNamedWriteable(SignificanceHeuristic.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,16 +82,8 @@ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBui
|
|||||||
protected void innerWriteTo(StreamOutput out) throws IOException {
|
protected void innerWriteTo(StreamOutput out) throws IOException {
|
||||||
bucketCountThresholds.writeTo(out);
|
bucketCountThresholds.writeTo(out);
|
||||||
out.writeOptionalString(executionHint);
|
out.writeOptionalString(executionHint);
|
||||||
boolean hasfilterBuilder = filterBuilder != null;
|
out.writeOptionalNamedWriteable(filterBuilder);
|
||||||
out.writeBoolean(hasfilterBuilder);
|
out.writeOptionalWriteable(includeExclude);
|
||||||
if (hasfilterBuilder) {
|
|
||||||
out.writeNamedWriteable(filterBuilder);
|
|
||||||
}
|
|
||||||
boolean hasIncExc = includeExclude != null;
|
|
||||||
out.writeBoolean(hasIncExc);
|
|
||||||
if (hasIncExc) {
|
|
||||||
includeExclude.writeTo(out);
|
|
||||||
}
|
|
||||||
out.writeNamedWriteable(significanceHeuristic);
|
out.writeNamedWriteable(significanceHeuristic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,18 +46,11 @@ import java.util.Set;
|
|||||||
public abstract class TermsAggregator extends BucketsAggregator {
|
public abstract class TermsAggregator extends BucketsAggregator {
|
||||||
|
|
||||||
public static class BucketCountThresholds implements Writeable<BucketCountThresholds>, ToXContent {
|
public static class BucketCountThresholds implements Writeable<BucketCountThresholds>, ToXContent {
|
||||||
|
|
||||||
private static final BucketCountThresholds PROTOTYPE = new BucketCountThresholds(-1, -1, -1, -1);
|
|
||||||
|
|
||||||
private long minDocCount;
|
private long minDocCount;
|
||||||
private long shardMinDocCount;
|
private long shardMinDocCount;
|
||||||
private int requiredSize;
|
private int requiredSize;
|
||||||
private int shardSize;
|
private int shardSize;
|
||||||
|
|
||||||
public static BucketCountThresholds readFromStream(StreamInput in) throws IOException {
|
|
||||||
return PROTOTYPE.readFrom(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BucketCountThresholds(long minDocCount, long shardMinDocCount, int requiredSize, int shardSize) {
|
public BucketCountThresholds(long minDocCount, long shardMinDocCount, int requiredSize, int shardSize) {
|
||||||
this.minDocCount = minDocCount;
|
this.minDocCount = minDocCount;
|
||||||
this.shardMinDocCount = shardMinDocCount;
|
this.shardMinDocCount = shardMinDocCount;
|
||||||
@ -65,6 +58,24 @@ public abstract class TermsAggregator extends BucketsAggregator {
|
|||||||
this.shardSize = shardSize;
|
this.shardSize = shardSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read from a stream.
|
||||||
|
*/
|
||||||
|
public BucketCountThresholds(StreamInput in) throws IOException {
|
||||||
|
requiredSize = in.readInt();
|
||||||
|
shardSize = in.readInt();
|
||||||
|
minDocCount = in.readLong();
|
||||||
|
shardMinDocCount = in.readLong();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
out.writeInt(requiredSize);
|
||||||
|
out.writeInt(shardSize);
|
||||||
|
out.writeLong(minDocCount);
|
||||||
|
out.writeLong(shardMinDocCount);
|
||||||
|
}
|
||||||
|
|
||||||
public BucketCountThresholds(BucketCountThresholds bucketCountThresholds) {
|
public BucketCountThresholds(BucketCountThresholds bucketCountThresholds) {
|
||||||
this(bucketCountThresholds.minDocCount, bucketCountThresholds.shardMinDocCount, bucketCountThresholds.requiredSize,
|
this(bucketCountThresholds.minDocCount, bucketCountThresholds.shardMinDocCount, bucketCountThresholds.requiredSize,
|
||||||
bucketCountThresholds.shardSize);
|
bucketCountThresholds.shardSize);
|
||||||
@ -135,23 +146,6 @@ public abstract class TermsAggregator extends BucketsAggregator {
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public BucketCountThresholds readFrom(StreamInput in) throws IOException {
|
|
||||||
int requiredSize = in.readInt();
|
|
||||||
int shardSize = in.readInt();
|
|
||||||
long minDocCount = in.readLong();
|
|
||||||
long shardMinDocCount = in.readLong();
|
|
||||||
return new BucketCountThresholds(minDocCount, shardMinDocCount, requiredSize, shardSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
|
||||||
out.writeInt(requiredSize);
|
|
||||||
out.writeInt(shardSize);
|
|
||||||
out.writeLong(minDocCount);
|
|
||||||
out.writeLong(shardMinDocCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(requiredSize, shardSize, minDocCount, shardMinDocCount);
|
return Objects.hash(requiredSize, shardSize, minDocCount, shardMinDocCount);
|
||||||
|
@ -70,12 +70,10 @@ public class TermsAggregatorBuilder extends ValuesSourceAggregatorBuilder<Values
|
|||||||
*/
|
*/
|
||||||
public TermsAggregatorBuilder(StreamInput in) throws IOException {
|
public TermsAggregatorBuilder(StreamInput in) throws IOException {
|
||||||
super(in, StringTerms.TYPE, ValuesSourceType.ANY);
|
super(in, StringTerms.TYPE, ValuesSourceType.ANY);
|
||||||
bucketCountThresholds = BucketCountThresholds.readFromStream(in);
|
bucketCountThresholds = new BucketCountThresholds(in);
|
||||||
collectMode = SubAggCollectionMode.BREADTH_FIRST.readFrom(in);
|
collectMode = SubAggCollectionMode.BREADTH_FIRST.readFrom(in);
|
||||||
executionHint = in.readOptionalString();
|
executionHint = in.readOptionalString();
|
||||||
if (in.readBoolean()) {
|
includeExclude = in.readOptionalWriteable(IncludeExclude::new);
|
||||||
includeExclude = IncludeExclude.readFromStream(in);
|
|
||||||
}
|
|
||||||
order = InternalOrder.Streams.readOrder(in);
|
order = InternalOrder.Streams.readOrder(in);
|
||||||
showTermDocCountError = in.readBoolean();
|
showTermDocCountError = in.readBoolean();
|
||||||
}
|
}
|
||||||
@ -90,11 +88,7 @@ public class TermsAggregatorBuilder extends ValuesSourceAggregatorBuilder<Values
|
|||||||
bucketCountThresholds.writeTo(out);
|
bucketCountThresholds.writeTo(out);
|
||||||
collectMode.writeTo(out);
|
collectMode.writeTo(out);
|
||||||
out.writeOptionalString(executionHint);
|
out.writeOptionalString(executionHint);
|
||||||
boolean hasIncExc = includeExclude != null;
|
out.writeOptionalWriteable(includeExclude);
|
||||||
out.writeBoolean(hasIncExc);
|
|
||||||
if (hasIncExc) {
|
|
||||||
includeExclude.writeTo(out);
|
|
||||||
}
|
|
||||||
InternalOrder.Streams.writeOrder(order, out);
|
InternalOrder.Streams.writeOrder(order, out);
|
||||||
out.writeBoolean(showTermDocCountError);
|
out.writeBoolean(showTermDocCountError);
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,6 @@ import org.elasticsearch.search.aggregations.support.ValuesSource;
|
|||||||
import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals;
|
import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -60,16 +59,10 @@ import java.util.TreeSet;
|
|||||||
* exclusion has precedence, where the {@code include} is evaluated first and then the {@code exclude}.
|
* exclusion has precedence, where the {@code include} is evaluated first and then the {@code exclude}.
|
||||||
*/
|
*/
|
||||||
public class IncludeExclude implements Writeable<IncludeExclude>, ToXContent {
|
public class IncludeExclude implements Writeable<IncludeExclude>, ToXContent {
|
||||||
|
|
||||||
private static final IncludeExclude PROTOTYPE = new IncludeExclude(Collections.emptySortedSet(), Collections.emptySortedSet());
|
|
||||||
private static final ParseField INCLUDE_FIELD = new ParseField("include");
|
private static final ParseField INCLUDE_FIELD = new ParseField("include");
|
||||||
private static final ParseField EXCLUDE_FIELD = new ParseField("exclude");
|
private static final ParseField EXCLUDE_FIELD = new ParseField("exclude");
|
||||||
private static final ParseField PATTERN_FIELD = new ParseField("pattern");
|
private static final ParseField PATTERN_FIELD = new ParseField("pattern");
|
||||||
|
|
||||||
public static IncludeExclude readFromStream(StreamInput in) throws IOException {
|
|
||||||
return PROTOTYPE.readFrom(in);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The includeValue and excludeValue ByteRefs which are the result of the parsing
|
// The includeValue and excludeValue ByteRefs which are the result of the parsing
|
||||||
// process are converted into a LongFilter when used on numeric fields
|
// process are converted into a LongFilter when used on numeric fields
|
||||||
// in the index.
|
// in the index.
|
||||||
@ -257,6 +250,68 @@ public class IncludeExclude implements Writeable<IncludeExclude>, ToXContent {
|
|||||||
this(convertToBytesRefSet(includeValues), convertToBytesRefSet(excludeValues));
|
this(convertToBytesRefSet(includeValues), convertToBytesRefSet(excludeValues));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read from a stream.
|
||||||
|
*/
|
||||||
|
public IncludeExclude(StreamInput in) throws IOException {
|
||||||
|
if (in.readBoolean()) {
|
||||||
|
includeValues = null;
|
||||||
|
excludeValues = null;
|
||||||
|
String includeString = in.readOptionalString();
|
||||||
|
include = includeString == null ? null : new RegExp(includeString);
|
||||||
|
String excludeString = in.readOptionalString();
|
||||||
|
exclude = excludeString == null ? null : new RegExp(excludeString);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
include = null;
|
||||||
|
exclude = null;
|
||||||
|
if (in.readBoolean()) {
|
||||||
|
int size = in.readVInt();
|
||||||
|
includeValues = new TreeSet<>();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
includeValues.add(in.readBytesRef());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
includeValues = null;
|
||||||
|
}
|
||||||
|
if (in.readBoolean()) {
|
||||||
|
int size = in.readVInt();
|
||||||
|
excludeValues = new TreeSet<>();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
excludeValues.add(in.readBytesRef());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
excludeValues = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(StreamOutput out) throws IOException {
|
||||||
|
boolean regexBased = isRegexBased();
|
||||||
|
out.writeBoolean(regexBased);
|
||||||
|
if (regexBased) {
|
||||||
|
out.writeOptionalString(include == null ? null : include.getOriginalString());
|
||||||
|
out.writeOptionalString(exclude == null ? null : exclude.getOriginalString());
|
||||||
|
} else {
|
||||||
|
boolean hasIncludes = includeValues != null;
|
||||||
|
out.writeBoolean(hasIncludes);
|
||||||
|
if (hasIncludes) {
|
||||||
|
out.writeVInt(includeValues.size());
|
||||||
|
for (BytesRef value : includeValues) {
|
||||||
|
out.writeBytesRef(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean hasExcludes = excludeValues != null;
|
||||||
|
out.writeBoolean(hasExcludes);
|
||||||
|
if (hasExcludes) {
|
||||||
|
out.writeVInt(excludeValues.size());
|
||||||
|
for (BytesRef value : excludeValues) {
|
||||||
|
out.writeBytesRef(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static SortedSet<BytesRef> convertToBytesRefSet(String[] values) {
|
private static SortedSet<BytesRef> convertToBytesRefSet(String[] values) {
|
||||||
SortedSet<BytesRef> returnSet = null;
|
SortedSet<BytesRef> returnSet = null;
|
||||||
if (values != null) {
|
if (values != null) {
|
||||||
@ -555,68 +610,6 @@ public class IncludeExclude implements Writeable<IncludeExclude>, ToXContent {
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IncludeExclude readFrom(StreamInput in) throws IOException {
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
String includeString = in.readOptionalString();
|
|
||||||
RegExp include = null;
|
|
||||||
if (includeString != null) {
|
|
||||||
include = new RegExp(includeString);
|
|
||||||
}
|
|
||||||
String excludeString = in.readOptionalString();
|
|
||||||
RegExp exclude = null;
|
|
||||||
if (excludeString != null) {
|
|
||||||
exclude = new RegExp(excludeString);
|
|
||||||
}
|
|
||||||
return new IncludeExclude(include, exclude);
|
|
||||||
} else {
|
|
||||||
SortedSet<BytesRef> includes = null;
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
int size = in.readVInt();
|
|
||||||
includes = new TreeSet<>();
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
includes.add(in.readBytesRef());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SortedSet<BytesRef> excludes = null;
|
|
||||||
if (in.readBoolean()) {
|
|
||||||
int size = in.readVInt();
|
|
||||||
excludes = new TreeSet<>();
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
excludes.add(in.readBytesRef());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new IncludeExclude(includes, excludes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void writeTo(StreamOutput out) throws IOException {
|
|
||||||
boolean regexBased = isRegexBased();
|
|
||||||
out.writeBoolean(regexBased);
|
|
||||||
if (regexBased) {
|
|
||||||
out.writeOptionalString(include == null ? null : include.getOriginalString());
|
|
||||||
out.writeOptionalString(exclude == null ? null : exclude.getOriginalString());
|
|
||||||
} else {
|
|
||||||
boolean hasIncludes = includeValues != null;
|
|
||||||
out.writeBoolean(hasIncludes);
|
|
||||||
if (hasIncludes) {
|
|
||||||
out.writeVInt(includeValues.size());
|
|
||||||
for (BytesRef value : includeValues) {
|
|
||||||
out.writeBytesRef(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
boolean hasExcludes = excludeValues != null;
|
|
||||||
out.writeBoolean(hasExcludes);
|
|
||||||
if (hasExcludes) {
|
|
||||||
out.writeVInt(excludeValues.size());
|
|
||||||
for (BytesRef value : excludeValues) {
|
|
||||||
out.writeBytesRef(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(include == null ? null : include.getOriginalString(), exclude == null ? null : exclude.getOriginalString(),
|
return Objects.hash(include == null ? null : include.getOriginalString(), exclude == null ? null : exclude.getOriginalString(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user