Class Field<T>

java.lang.Object
org.elasticsearch.script.Field<T>
Direct Known Subclasses:
EmptyField, Field.BigIntegerField, Field.BooleanField, Field.BytesRefField, Field.DateMillisField, Field.DateNanosField, Field.DoubleField, Field.GeoPointField, Field.IpField, Field.LongField, Field.StringField, Field.VersionField

public abstract class Field<T> extends Object
A field in a document accessible via scripting. In search contexts, the Field may be backed by doc values, source or both. In ingestion, the field may be in the source document or being added to the document. Field's methods must not throw exceptions nor return null. A Field object representing a empty or unmapped field will have * isEmpty() == true * getValues().equals(Collections.emptyList()) * getValue(defaultValue) == defaultValue
  • Field Details

  • Constructor Details

  • Method Details

    • getName

      public String getName()
    • isEmpty

      public boolean isEmpty()
      Does the field have any values? An unmapped field may have values from source
    • getValues

      public List<T> getValues()
      Get all values of a multivalued field. If isEmpty() this returns an empty list
    • as

      public final <CT,​ CF extends Field<CT>> Field<CT> as(Converter<CT,​CF> converter)
      Convert this Field into another Field type using a Converter of the target type. As this is called from user scripts, as may be called to convert a field into its same type, if so this is cast via converters Converter.getFieldClass().
    • convert

      protected <CT,​ CF extends Field<CT>> Field<CT> convert(Converter<CT,​CF> converter)
      Extensions outside the core package should override this method to implement their own conversions, calling the superclass of this method as a fallback.
    • getFieldValues

      public FieldValues<T> getFieldValues()
      Provide Converters access to the underlying FieldValues, should not be exposed to scripts
    • getValue

      public T getValue(T defaultValue)
      Get the first value of a field, if isEmpty() return defaultValue instead
    • getDouble

      public double getDouble(double defaultValue)
      Get the underlying value as a double unless isEmpty(), in which case return defaultValue. May throw InvalidConversion if the underlying value is not representable as a double.
    • getLong

      public long getLong(long defaultValue)
      Get the underlying value as a long unless isEmpty(), in which case return defaultValue. May throw InvalidConversion if the underlying value is not representable as a long.