Interface Source


public interface Source
The source of a document. Note that, while objects returned from source() and internalSourceRef() are immutable, objects implementing this interface may not be immutable themselves.
  • Method Details

    • sourceContentType

      XContentType sourceContentType()
      The content type of the source, if stored as bytes
    • source

      Map<String,Object> source()
      A map representation of the source

      Important: This can lose precision on numbers with a decimal point. It converts numbers like "n": 1234.567 to a double which only has 52 bits of precision in the mantissa. This will come up most frequently when folks write nanosecond precision dates as a decimal number.

    • internalSourceRef

      BytesReference internalSourceRef()
      A byte representation of the source
    • filter

      Source filter(SourceFilter sourceFilter)
      Apply a filter to this source, returning a new Source
    • extractValue

      default Object extractValue(String path, @Nullable Object nullValue)
      For the provided path, return its value in the source. Both array and object values can be returned.
      Parameters:
      path - the value's path in the source.
      nullValue - a value to return if the path exists, but the value is 'null'. This helps in distinguishing between a path that doesn't exist vs. a value of 'null'.
      Returns:
      the value associated with the path in the source or 'null' if the path does not exist.
    • empty

      static Source empty(XContentType xContentType)
      An empty Source, represented as an empty map
    • fromBytes

      static Source fromBytes(BytesReference bytes)
      Build a Source from a bytes representation with an unknown XContentType
    • fromBytes

      static Source fromBytes(BytesReference bytes, XContentType type)
      Build a Source from a bytes representation with a known XContentType
    • fromMap

      static Source fromMap(Map<String,Object> map, XContentType xContentType)
      Build a Source from a Map representation. Note that null is accepted as an input and interpreted as an empty map
      Parameters:
      map - the java Map to use as a source
      xContentType - the XContentType to serialize this source
    • lazy

      static Source lazy(Supplier<Source> sourceSupplier)
      Build a source lazily if one of its methods is called