Interface SourceLoader.SyntheticFieldLoader

All Known Implementing Classes:
FlattenedSortedSetDocValuesSyntheticFieldLoader, SortedNumericDocValuesSyntheticFieldLoader, SortedSetDocValuesSyntheticFieldLoader, 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.