Which one is the best to retrieve selected fields from a search: `_source` or `fields`?

_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???

Is your test using realistic document sizes and structures? The amont of work required to parse the source document will increase with size.

Thanks for your reply! The test ran in the real production environment.
The test used the same query but different approach to retrieve selected fields (_source and no fields vs fields and _source=false). Before executing those 2 tests, I had also warmed up both queries.

What is the average size of your documents?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.