_source
vs fields
: which is fastest to retrieve selected fields?
The ES 8.10.x official doc mentioned that ES will load whole _source object while using _source
and the doc preferred to use fields
.
- You can use both of these methods, though the
fields
option is preferred because it consults both the document data and index mappings.- A document’s _source is stored as a single field in Lucene. This structure means that the whole _source object must be loaded and parsed even if you’re only requesting part of it.
- Elasticsearch always attempts to load values from _source. This behavior has the same implications of source filtering where Elasticsearch needs to load and parse the entire _source to retrieve just one field.
My simple test using same query: the time_in_nanos of FetchFieldsPhase is much higher than that of FetchSourcePhase!
Please help me find which one is fastest to retrieve fields from a search only considering retrieval speed???