@Override public final XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (fields != null) { for (Map.Entry<String, MultiValuesSourceFieldConfig> fieldEntry : fields.entrySet()) { builder.field(fieldEntry.getKey(), fieldEntry.getValue()); } } if (format != null) { builder.field(CommonFields.FORMAT.getPreferredName(), format); } if (valueType != null) { builder.field(CommonFields.VALUE_TYPE.getPreferredName(), valueType.getPreferredName()); } doXContentBody(builder, params); builder.endObject(); return builder; }
public boolean isNotA(ValueType valueType) { return !isA(valueType); }
@Override public boolean isFloatingPoint() { return scriptValueType != null ? scriptValueType.isFloatingPoint() : true; }
public static <VS extends ValuesSource, T> void declareCommon( AbstractObjectParser<? extends MultiValuesSourceAggregationBuilder<VS, ?>, T> objectParser, boolean formattable, ValueType targetValueType) { objectParser.declareField(MultiValuesSourceAggregationBuilder::valueType, p -> { ValueType valueType = ValueType.resolveForScript(p.text()); if (targetValueType != null && valueType.isNotA(targetValueType)) { throw new ParsingException(p.getTokenLocation(), "Aggregation [" + objectParser.getName() + "] was configured with an incompatible value type [" + valueType + "]. It can only work on value of type [" + targetValueType + "]"); } return valueType; }, ValueType.VALUE_TYPE, ObjectParser.ValueType.STRING); if (formattable) { objectParser.declareField(MultiValuesSourceAggregationBuilder::format, XContentParser::text, ParseField.CommonFields.FORMAT, ObjectParser.ValueType.STRING); } }
return config; ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : ValuesSourceType.ANY; if (valuesSourceType == ValuesSourceType.ANY) { ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : ValuesSourceType.ANY; ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType); config.missing(missing); config = new ValuesSourceConfig<>(valueType.getValuesSourceType());
/** * Read from a stream. */ private void read(StreamInput in) throws IOException { field = in.readOptionalString(); if (in.readBoolean()) { script = new Script(in); } if (in.readBoolean()) { valueType = ValueType.readFromStream(in); } format = in.readOptionalString(); missing = in.readGenericValue(); if (in.readBoolean()) { timeZone = DateTimeZone.forID(in.readString()); } }
@Override protected final void doWriteTo(StreamOutput out) throws IOException { if (serializeTargetValueType()) { out.writeOptionalWriteable(targetValueType); } out.writeOptionalString(field); boolean hasScript = script != null; out.writeBoolean(hasScript); if (hasScript) { script.writeTo(out); } boolean hasValueType = valueType != null; out.writeBoolean(hasValueType); if (hasValueType) { valueType.writeTo(out); } out.writeOptionalString(format); out.writeGenericValue(missing); boolean hasTimeZone = timeZone != null; out.writeBoolean(hasTimeZone); if (hasTimeZone) { out.writeString(timeZone.getID()); } innerWriteTo(out); }
@Override public boolean isNumeric() { return super.isNumeric(); } };
public static ValueType readFromStream(StreamInput in) throws IOException { byte id = in.readByte(); for (ValueType valueType : values()) { if (id == valueType.id) { return valueType; } } throw new IOException("No valueType found for id [" + id + "]"); }
ValueType valueType = ValueType.resolveForScript(p.text()); if (targetValueType != null && valueType.isNotA(targetValueType)) { throw new ParsingException(p.getTokenLocation(), "Aggregation [" + objectParser.getName() + "] was configured with an incompatible value type ["
return config.format(resolveFormat(null, valueType)); ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType; if (valuesSourceType == null || valuesSourceType == ValuesSourceType.ANY) { ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType; ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType); config.missing(missingMap.get(field));
CompositeValuesSourceBuilder(StreamInput in) throws IOException { this.name = in.readString(); this.field = in.readOptionalString(); if (in.readBoolean()) { this.script = new Script(in); } if (in.readBoolean()) { this.valueType = ValueType.readFromStream(in); } if (in.getVersion().onOrAfter(Version.V_6_4_0)) { this.missingBucket = in.readBoolean(); } else { this.missingBucket = false; } this.missing = in.readGenericValue(); this.order = SortOrder.readFromStream(in); if (in.getVersion().onOrAfter(Version.V_6_3_0)) { this.format = in.readOptionalString(); } else { this.format = null; } }
@Override public final void writeTo(StreamOutput out) throws IOException { out.writeString(name); out.writeOptionalString(field); boolean hasScript = script != null; out.writeBoolean(hasScript); if (hasScript) { script.writeTo(out); } boolean hasValueType = valueType != null; out.writeBoolean(hasValueType); if (hasValueType) { valueType.writeTo(out); } if (out.getVersion().onOrAfter(Version.V_6_4_0)) { out.writeBoolean(missingBucket); } out.writeGenericValue(missing); order.writeTo(out); if (out.getVersion().onOrAfter(Version.V_6_3_0)) { out.writeOptionalString(format); } innerWriteTo(out); }
@Override public boolean isNumeric() { return super.isNumeric(); } };
public static ValueType readFromStream(StreamInput in) throws IOException { byte id = in.readByte(); for (ValueType valueType : values()) { if (id == valueType.id) { return valueType; } } throw new IOException("No valueType found for id [" + id + "]"); }
static <VB extends CompositeValuesSourceBuilder<VB>, T> void declareValuesSourceFields(AbstractObjectParser<VB, T> objectParser, ValueType targetValueType) { objectParser.declareField(VB::field, XContentParser::text, new ParseField("field"), ObjectParser.ValueType.STRING); objectParser.declareField(VB::missing, XContentParser::objectText, new ParseField("missing"), ObjectParser.ValueType.VALUE); objectParser.declareBoolean(VB::missingBucket, new ParseField("missing_bucket")); objectParser.declareField(VB::valueType, p -> { ValueType valueType = ValueType.resolveForScript(p.text()); if (targetValueType != null && valueType.isNotA(targetValueType)) { throw new ParsingException(p.getTokenLocation(), "Aggregation [" + objectParser.getName() + "] was configured with an incompatible value type [" + valueType + "]. It can only work on value of type [" + targetValueType + "]"); } return valueType; }, new ParseField("value_type"), ObjectParser.ValueType.STRING); objectParser.declareField(VB::script, (parser, context) -> Script.parse(parser), Script.SCRIPT_PARSE_FIELD, ObjectParser.ValueType.OBJECT_OR_STRING); objectParser.declareField(VB::order, XContentParser::text, new ParseField("order"), ObjectParser.ValueType.STRING); }
@Override public final XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (field != null) { builder.field("field", field); } if (script != null) { builder.field("script", script); } if (missing != null) { builder.field("missing", missing); } if (format != null) { builder.field("format", format); } if (timeZone != null) { builder.field("time_zone", timeZone.toString()); } if (valueType != null) { builder.field("value_type", valueType.getPreferredName()); } doXContentBody(builder, params); builder.endObject(); return builder; }
return config.format(resolveFormat(null, valueType)); ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType; if (valuesSourceType == null || valuesSourceType == ValuesSourceType.ANY) { ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType; ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType); config.missing(missingMap.get(field));
@Override public boolean isFloatingPoint() { return scriptValueType != null ? scriptValueType.isFloatingPoint() : true; }
public boolean isNotA(ValueType valueType) { return !isA(valueType); }