private ValuesSource bytesField() throws IOException { final IndexFieldData<?> indexFieldData = fieldContext().indexFieldData(); ValuesSource dataSource; if (indexFieldData instanceof IndexOrdinalsFieldData) { dataSource = new ValuesSource.Bytes.WithOrdinals.FieldData((IndexOrdinalsFieldData) indexFieldData); } else { dataSource = new ValuesSource.Bytes.FieldData(indexFieldData); } if (script() != null) { dataSource = new ValuesSource.WithScript(dataSource, script()); } return dataSource; }
@Override public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOException { SortedBinaryDocValues values = valuesSource.bytesValues(context); return replaceMissing(values, missing); } };
@Override public MultiGeoPointValues geoPointValues(LeafReaderContext context) { final MultiGeoPointValues values = valuesSource.geoPointValues(context); return replaceMissing(values, missing); } };
private ValuesSource.Numeric numericField() throws IOException { if (!(fieldContext().indexFieldData() instanceof IndexNumericFieldData)) { throw new IllegalArgumentException("Expected numeric type on field [" + fieldContext().field() + "], but got [" + fieldContext().fieldType().typeName() + "]"); } ValuesSource.Numeric dataSource = new ValuesSource.Numeric.FieldData((IndexNumericFieldData)fieldContext().indexFieldData()); if (script() != null) { dataSource = new ValuesSource.Numeric.WithScript(dataSource, script()); } return dataSource; }
private ValuesSource.GeoPoint geoPointField() throws IOException { if (!(fieldContext().indexFieldData() instanceof IndexGeoPointFieldData)) { throw new IllegalArgumentException("Expected geo_point type on field [" + fieldContext().field() + "], but got [" + fieldContext().fieldType().typeName() + "]"); } return new ValuesSource.GeoPoint.Fielddata((IndexGeoPointFieldData) fieldContext().indexFieldData()); } }
@Override public LongUnaryOperator globalOrdinalsMapping(LeafReaderContext context) throws IOException { return getGlobalMapping(valuesSource.ordinalsValues(context), valuesSource.globalOrdinalsValues(context), valuesSource.globalOrdinalsMapping(context), missing); } };
@Override public SortedSetDocValues globalOrdinalsValues(LeafReaderContext context) throws IOException { SortedSetDocValues values = valuesSource.globalOrdinalsValues(context); return replaceMissing(values, missing); }
private ValuesSource.Numeric numericScript() throws IOException { return new ValuesSource.Numeric.Script(script(), scriptValueType()); }
@Override public SortedSetDocValues ordinalsValues(LeafReaderContext context) throws IOException { SortedSetDocValues values = valuesSource.ordinalsValues(context); return replaceMissing(values, missing); }
@Override public SortedBinaryDocValues bytesValues(LeafReaderContext context) throws IOException { SortedBinaryDocValues values = valuesSource.bytesValues(context); return replaceMissing(values, missing); }
private ValuesSource.Bytes bytesScript() throws IOException { return new ValuesSource.Bytes.Script(script()); }
/** * Get the maximum global ordinal value for the provided {@link ValuesSource} or -1 * if the values source is not an instance of {@link ValuesSource.Bytes.WithOrdinals}. */ static long getMaxOrd(ValuesSource source, IndexSearcher searcher) throws IOException { if (source instanceof ValuesSource.Bytes.WithOrdinals) { ValuesSource.Bytes.WithOrdinals valueSourceWithOrdinals = (ValuesSource.Bytes.WithOrdinals) source; return valueSourceWithOrdinals.globalMaxOrd(searcher); } else { return -1; } }
/** * Read an aggregation from a stream that does not serialize its targetValueType. This should be used by most subclasses. */ protected ValuesSourceAggregationBuilder(StreamInput in, ValuesSourceType valuesSourceType, ValueType targetValueType) throws IOException { super(in); assert false == serializeTargetValueType() : "Wrong read constructor called for subclass that provides its targetValueType"; this.valuesSourceType = valuesSourceType; this.targetValueType = targetValueType; read(in); }
@Override protected final void doWriteTo(StreamOutput out) throws IOException { if (serializeTargetValueType()) { out.writeOptionalWriteable(targetValueType); } out.writeMap(fields, StreamOutput::writeString, (o, value) -> value.writeTo(o)); out.writeOptionalWriteable(valueType); out.writeOptionalString(format); innerWriteTo(out); }
protected MultiValuesSourceAggregationBuilder(StreamInput in, ValueType targetValueType) throws IOException { super(in); assert false == serializeTargetValueType() : "Wrong read constructor called for subclass that provides its targetValueType"; this.targetValueType = targetValueType; read(in); }
if (kvValue.key != null && kvValue.key.equals("script")) { if (kvValue.value instanceof MethodField) { return builder.script(new Script(((MethodField) kvValue.value).getParams().get(1).toString())); } else { return builder.script(new Script(kvValue.value.toString())); return builder.script(new Script(kvValue.value.toString())); } else if (kvValue.key != null && (kvValue.key.equals("nested") || kvValue.key.equals("reverse_nested"))) { NestedType nestedType = (NestedType) kvValue.value; builder.field(nestedType.field); ChildrenType childrenType = (ChildrenType) kvValue.value; builder.field(childrenType.field); return builder.field(kvValue.toString());
public static <T> void declareAnyFields( AbstractObjectParser<? extends ValuesSourceAggregationBuilder<ValuesSource, ?>, T> objectParser, boolean scriptable, boolean formattable) { declareFields(objectParser, scriptable, formattable, false, null); }
@Override public boolean isNumeric() { return super.isNumeric(); } };
@Override public Aggregator createInternal(Aggregator parent, boolean collectsFromSingleBucket, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException { return doCreateInternal(configs, format, parent, collectsFromSingleBucket, pipelineAggregators, metaData); }
public static <T> void declareNumericFields( AbstractObjectParser<? extends ValuesSourceAggregationBuilder<ValuesSource.Numeric, ?>, T> objectParser, boolean scriptable, boolean formattable, boolean timezoneAware) { declareFields(objectParser, scriptable, formattable, timezoneAware, ValueType.NUMERIC); }