Interface SourceLoader.SyntheticFieldLoader

All Known Subinterfaces:
CompositeSyntheticFieldLoader.DocValuesLayer, CompositeSyntheticFieldLoader.Layer
All Known Implementing Classes:
BinaryDocValuesSyntheticFieldLoader, CompositeSyntheticFieldLoader, CompositeSyntheticFieldLoader.MalformedValuesLayer, CompositeSyntheticFieldLoader.StoredFieldLayer, SortedNumericDocValuesSyntheticFieldLoader, SortedSetDocValuesSyntheticFieldLoaderLayer, SourceLoader.DocValuesBasedSyntheticFieldLoader, StringStoredFieldFieldLoader
Enclosing interface:
SourceLoader

public static interface SourceLoader.SyntheticFieldLoader
Load a field for SourceLoader.Synthetic.

SourceLoader.SyntheticFieldLoaders load values through objects vended by their storedFieldLoaders() and docValuesLoader(org.apache.lucene.index.LeafReader, int[]) methods. Then you call write(org.elasticsearch.xcontent.XContentBuilder) to write the values to an XContentBuilder which also clears them.

This two loaders and one writer setup is specifically designed to efficiently load the _source of indices that have thousands of fields declared in the mapping but that only have values for dozens of them. It handles this in a few ways:

  • docValuesLoader(org.apache.lucene.index.LeafReader, int[]) must be called once per document per field to load the doc values, but detects up front if there are no doc values for that field. It's linear with the number of fields, whether or not they have values, but skips entirely missing fields.
  • storedFieldLoaders() are only called when the document contains a stored field with the appropriate name. So it's fine to have thousands of these declared in the mapping and you don't really pay much to load them. Just the cost to build Map used to address them.
  • Object fields that don't have any values loaded by either means bail out of the loading process and don't pass control down to any of their children. Thus it's fine to declare huge object structures in the mapping and you only spend time iterating the ones you need. Or that have doc values.
  • Field Details

  • Method Details

    • storedFieldLoaders

      A Stream mapping stored field paths to a place to put them so they can be included in the next document.
    • docValuesLoader

      SourceLoader.SyntheticFieldLoader.DocValuesLoader docValuesLoader(org.apache.lucene.index.LeafReader leafReader, int[] docIdsInLeaf) throws IOException
      Build something to load doc values for this field or return null if there are no doc values for this field to load.
      Parameters:
      docIdsInLeaf - can be null.
      Throws:
      IOException
    • prepare

      default void prepare()
      Perform any preprocessing needed before producing synthetic source and deduce whether this mapper (and its children, if any) have values to write. The expectation is for this method to be called before hasValue() and write(XContentBuilder) are used.
    • hasValue

      boolean hasValue()
      Has this field loaded any values for this document?
    • write

      void write(XContentBuilder b) throws IOException
      Write values for this document.
      Throws:
      IOException
    • setIgnoredValues

      default boolean setIgnoredValues(Map<String,List<IgnoredSourceFieldMapper.NameValue>> objectsWithIgnoredFields)
      Allows for identifying and tracking additional field values to include in the field source.
      Parameters:
      objectsWithIgnoredFields - maps object names to lists of fields they contain with special source handling
      Returns:
      true if any matching fields are identified
    • fieldName

      String fieldName()
      Returns the canonical field name for this loader.
    • reset

      void reset()
      Resets the loader to remove any stored data and prepare it for processing new document. This is an alternative code path to write(org.elasticsearch.xcontent.XContentBuilder) that is executed when values are loaded but not written. Loaders are expected to also reset their state after writing currently present data.