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

**URL:** <https://discuss.elastic.co/t/which-one-is-the-best-to-retrieve-selected-fields-from-a-search-source-or-fields/355270>\
**Category:** Elasticsearch\
**Created:** [March 13, 2024, 1:40am UTC](https://discuss.elastic.co/t/which-one-is-the-best-to-retrieve-selected-fields-from-a-search-source-or-fields/355270 "2024-03-13T01:40:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deadlyn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deadlyn/32/116784_2.png) [@deadlyn](https://discuss.elastic.co/u/deadlyn)\
**Post date:** [March 13, 2024, 1:40am UTC](https://discuss.elastic.co/t/which-one-is-the-best-to-retrieve-selected-fields-from-a-search-source-or-fields/355270/1 "2024-03-13T01:40:20Z")

</div>

`_source` vs `fields`: which is fastest to retrieve selected fields?

The [ES 8.10.x official doc](https://www.elastic.co/guide/en/elasticsearch/reference/8.10/search-fields.html) 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???

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 13, 2024, 3:27am UTC](https://discuss.elastic.co/t/which-one-is-the-best-to-retrieve-selected-fields-from-a-search-source-or-fields/355270/2 "2024-03-13T03:27:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![deadlyn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deadlyn/32/116784_2.png) [@deadlyn](https://discuss.elastic.co/u/deadlyn)\
**Post date:** [March 13, 2024, 5:25am UTC](https://discuss.elastic.co/t/which-one-is-the-best-to-retrieve-selected-fields-from-a-search-source-or-fields/355270/3 "2024-03-13T05:25:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 13, 2024, 6:16am UTC](https://discuss.elastic.co/t/which-one-is-the-best-to-retrieve-selected-fields-from-a-search-source-or-fields/355270/4 "2024-03-13T06:16:57Z")

</div>

What is the average size of your documents?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 10, 2024, 6:17am UTC](https://discuss.elastic.co/t/which-one-is-the-best-to-retrieve-selected-fields-from-a-search-source-or-fields/355270/5 "2024-04-10T06:17:16Z")

</div>

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