Why do I need “store”:”yes” in elasticsearch?

I thought that if “store” is set to “no” it would mean I could not
retrieve the specific field, but had to get the whole _source and
parse it on the client side.

That’s exactly what elasticsearch does for you when a field is not stored (default) and the _source field is enabled (default too).

You usually send a field to elasticsearch because you either want to search on it, or retrieve it. But it’s true that if you don’t store the field explicitly and you don’t disable the source you can still retrieve the field using the _source. This means that in some cases it might actually make sense to have a field that is not indexed nor stored.

When you store a field, that’s done in the underlying lucene. Lucene is an inverted index, that allows for fast full-text search and gives back document ids given text queries. Beyond the inverted index Lucene has some kind of storage where the field values can be stored in order to be retrieved given a document id. You usually store in lucene the fields that you want to return as search results. Elasticsearch doesn’t require to store every field that you want to return because it always stores by default every document that you send to it, thus it’s always able to return everything you sent to it as search result.

In just a few cases it might be useful to store fields explicitly in lucene: when the _source field is disabled, or when we want to avoid parsing it, even if the parsing is done automatically by elasticsearch.
Keep in mind though that retrieving many stored fields from lucene might require one disk seek per field while with retrieving only the _source from lucene and parsing it in order to retrieve the needed fields is just a single disk seek and just faster in most of the cases.

Leave a Comment