Company
Date Published
Author
Njal Karevoll
Word count
1020
Language
English
Hacker News points
None

Summary

Managing Elasticsearch fields when conducting searches is crucial for optimizing performance by controlling the amount of data transferred. By using the fields parameter, users can limit the fields returned for each search hit, significantly reducing data size and bandwidth usage. For example, minimizing document sizes from 20KB to 800 bytes can drastically decrease bandwidth needs from 20 MB/s to 800 KB/s for 100 requests per second. The source parameter, while enabled by default, can be filtered to include or exclude specific parts of a document, although this does not save CPU or disk resources. Nested fields require the use of the source field due to their non-leaf nature, while unstored fields can be accessed via fielddata_fields, which caches terms in memory, making it efficient if already used for sorting or faceting. Additionally, script fields allow for dynamic computation of field values, though they necessitate enabling dynamic scripts with associated security considerations. These strategies collectively enhance the efficiency of data retrieval in Elasticsearch.