|
@@ -17,6 +17,7 @@ import org.elasticsearch.index.query.AbstractQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
import org.elasticsearch.search.aggregations.AggregationBuilder;
|
|
|
+import org.elasticsearch.search.aggregations.bucket.terms.IncludeExclude;
|
|
|
import org.elasticsearch.xcontent.ObjectParser;
|
|
|
import org.elasticsearch.xcontent.ParseField;
|
|
|
import org.elasticsearch.xcontent.ToXContentObject;
|
|
@@ -38,6 +39,7 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
private final QueryBuilder filter;
|
|
|
// supported only if heterogeneous == true
|
|
|
private final ValueType userValueTypeHint;
|
|
|
+ private final IncludeExclude includeExclude;
|
|
|
private final String format;
|
|
|
|
|
|
private static final String NAME = "field_config";
|
|
@@ -50,6 +52,7 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
* @param timezoneAware - allows specifying timezone
|
|
|
* @param filtered - allows specifying filters on the values
|
|
|
* @param heterogeneous - allows specifying value-source specific format and user value type hint
|
|
|
+ * @param supportsIncludesExcludes - allows specifying includes and excludes
|
|
|
* @param <C> - parser context
|
|
|
* @return configured parser
|
|
|
*/
|
|
@@ -57,7 +60,8 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
boolean scriptable,
|
|
|
boolean timezoneAware,
|
|
|
boolean filtered,
|
|
|
- boolean heterogeneous
|
|
|
+ boolean heterogeneous,
|
|
|
+ boolean supportsIncludesExcludes
|
|
|
) {
|
|
|
|
|
|
ObjectParser<MultiValuesSourceFieldConfig.Builder, C> parser = new ObjectParser<>(
|
|
@@ -116,6 +120,23 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
ObjectParser.ValueType.STRING
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ if (supportsIncludesExcludes) {
|
|
|
+ parser.declareField(
|
|
|
+ (b, v) -> b.setIncludeExclude(IncludeExclude.merge(v, b.getIncludeExclude())),
|
|
|
+ IncludeExclude::parseInclude,
|
|
|
+ IncludeExclude.INCLUDE_FIELD,
|
|
|
+ ObjectParser.ValueType.OBJECT_ARRAY_OR_STRING
|
|
|
+ );
|
|
|
+
|
|
|
+ parser.declareField(
|
|
|
+ (b, v) -> b.setIncludeExclude(IncludeExclude.merge(b.getIncludeExclude(), v)),
|
|
|
+ IncludeExclude::parseExclude,
|
|
|
+ IncludeExclude.EXCLUDE_FIELD,
|
|
|
+ ObjectParser.ValueType.STRING_ARRAY
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
return parser;
|
|
|
};
|
|
|
|
|
@@ -126,7 +147,8 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
ZoneId timeZone,
|
|
|
QueryBuilder filter,
|
|
|
ValueType userValueTypeHint,
|
|
|
- String format
|
|
|
+ String format,
|
|
|
+ IncludeExclude includeExclude
|
|
|
) {
|
|
|
this.fieldName = fieldName;
|
|
|
this.missing = missing;
|
|
@@ -135,6 +157,7 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
this.filter = filter;
|
|
|
this.userValueTypeHint = userValueTypeHint;
|
|
|
this.format = format;
|
|
|
+ this.includeExclude = includeExclude;
|
|
|
}
|
|
|
|
|
|
public MultiValuesSourceFieldConfig(StreamInput in) throws IOException {
|
|
@@ -158,6 +181,11 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
this.userValueTypeHint = null;
|
|
|
this.format = null;
|
|
|
}
|
|
|
+ if (in.getVersion().onOrAfter(Version.V_8_7_0)) {
|
|
|
+ this.includeExclude = in.readOptionalWriteable(IncludeExclude::new);
|
|
|
+ } else {
|
|
|
+ this.includeExclude = null;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public Object getMissing() {
|
|
@@ -188,6 +216,10 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
return format;
|
|
|
}
|
|
|
|
|
|
+ public IncludeExclude getIncludeExclude() {
|
|
|
+ return includeExclude;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void writeTo(StreamOutput out) throws IOException {
|
|
|
if (out.getVersion().onOrAfter(Version.V_7_6_0)) {
|
|
@@ -205,6 +237,9 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
out.writeOptionalWriteable(userValueTypeHint);
|
|
|
out.writeOptionalString(format);
|
|
|
}
|
|
|
+ if (out.getVersion().onOrAfter(Version.V_8_7_0)) {
|
|
|
+ out.writeOptionalWriteable(includeExclude);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -232,6 +267,10 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
if (format != null) {
|
|
|
builder.field(AggregationBuilder.CommonFields.FORMAT.getPreferredName(), format);
|
|
|
}
|
|
|
+ if (includeExclude != null) {
|
|
|
+ includeExclude.toXContent(builder, params);
|
|
|
+ }
|
|
|
+
|
|
|
builder.endObject();
|
|
|
return builder;
|
|
|
}
|
|
@@ -247,12 +286,13 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
&& Objects.equals(timeZone, that.timeZone)
|
|
|
&& Objects.equals(filter, that.filter)
|
|
|
&& Objects.equals(userValueTypeHint, that.userValueTypeHint)
|
|
|
- && Objects.equals(format, that.format);
|
|
|
+ && Objects.equals(format, that.format)
|
|
|
+ && Objects.equals(includeExclude, that.includeExclude);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hash(fieldName, missing, script, timeZone, filter, userValueTypeHint, format);
|
|
|
+ return Objects.hash(fieldName, missing, script, timeZone, filter, userValueTypeHint, format, includeExclude);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -268,6 +308,7 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
private QueryBuilder filter = null;
|
|
|
private ValueType userValueTypeHint = null;
|
|
|
private String format = null;
|
|
|
+ private IncludeExclude includeExclude = null;
|
|
|
|
|
|
public String getFieldName() {
|
|
|
return fieldName;
|
|
@@ -328,6 +369,15 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
return format;
|
|
|
}
|
|
|
|
|
|
+ public Builder setIncludeExclude(IncludeExclude includeExclude) {
|
|
|
+ this.includeExclude = includeExclude;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public IncludeExclude getIncludeExclude() {
|
|
|
+ return includeExclude;
|
|
|
+ }
|
|
|
+
|
|
|
public MultiValuesSourceFieldConfig build() {
|
|
|
if (Strings.isNullOrEmpty(fieldName) && script == null) {
|
|
|
throw new IllegalArgumentException(
|
|
@@ -351,7 +401,16 @@ public class MultiValuesSourceFieldConfig implements Writeable, ToXContentObject
|
|
|
);
|
|
|
}
|
|
|
|
|
|
- return new MultiValuesSourceFieldConfig(fieldName, missing, script, timeZone, filter, userValueTypeHint, format);
|
|
|
+ return new MultiValuesSourceFieldConfig(
|
|
|
+ fieldName,
|
|
|
+ missing,
|
|
|
+ script,
|
|
|
+ timeZone,
|
|
|
+ filter,
|
|
|
+ userValueTypeHint,
|
|
|
+ format,
|
|
|
+ includeExclude
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
}
|