# What's the difference between "store" and "doc\_values" in field properties?

**URL:** https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045
**Category:** Elasticsearch
**Created:** [December 27, 2016, 8:11am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045 "2016-12-27T08:11:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ccclyt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ccclyt/32/14162_2.png) [@ccclyt](https://discuss.elastic.co/u/ccclyt)
#### Post date: [December 27, 2016, 8:11am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045/1 "2016-12-27T08:11:24Z")

</div>

inverted index is used for terms to find the doc\_ids,  
doc\_values are used for doc\_ids to find values of a field, and will be serialized into the disk.  
However what about the property "store"? I just don't understand.

btw: can you show me why I can't sort by a field if I set "doc\_values" : false and "store" : true?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [December 27, 2016, 8:27am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045/2 "2016-12-27T08:27:59Z")

</div>

If it's not stored then you can't return the field value, see [https://www.elastic.co/guide/en/elasticsearch/reference/5.1/mapping-store.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/mapping-store.html)

---

<div class="post-metadata">

### Author: ![ccclyt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ccclyt/32/14162_2.png) [@ccclyt](https://discuss.elastic.co/u/ccclyt)
#### Post date: [December 27, 2016, 9:12am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045/3 "2016-12-27T09:12:01Z")

</div>

yes, the doc said so.  
But, when you set doc\_values: true, the field value is already serialized into the disk, right?  
Why can't ElasticSearch return the value in the doc\_value files?

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [December 27, 2016, 9:51am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045/4 "2016-12-27T09:51:15Z")

</div>

Elasticsearch can return doc values fields:  
[https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-request-docvalue-fields.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/search-request-docvalue-fields.html)

Stored fields are designed for optimal storage whereas doc values are  
designed the access field values quickly. During the execution of query  
many of doc values fields are accessed for candidate hits, so the access  
must be fast. This the reason why you should use doc values in sorting,  
aggregations and scrips. Today many features in ES use doc values  
automatically.

On the other hand stored fields should be used for return field values for  
the top matching documents. In ES by default it is used just for that. Just  
fetching stored fields for a couple of documents is fine (stored values are  
decompressed and send back to the client). They shouldn't be used during  
execution of a query as it would make the entire search request  
significantly slower. (you can use stored fields in scripts, but really you  
shouldn't do that)

---

<div class="post-metadata">

### Author: ![ccclyt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ccclyt/32/14162_2.png) [@ccclyt](https://discuss.elastic.co/u/ccclyt)
#### Post date: [December 27, 2016, 10:13am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045/5 "2016-12-27T10:13:47Z")

</div>

so when I set my property below:  
"prop\_1":{ "type":"string", "index":"not\_analyzed","store":true,"doc\_values":true}  
there would be 4 separate files stored in the disk: one for store, one for index, another for doc\_values, the other of course is for \_source. Am I right?

---

<div class="post-metadata">

### Author: ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)
#### Post date: [December 27, 2016, 11:03am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045/6 "2016-12-27T11:03:18Z")

</div>

Yes, so `prop_1` would be stored on its own as an indexed, doc values and stored field. On top of that the `prop_1` is stored to into the `_source` field together with your other fields.

Unless you have a very specific reason, I think you should set `store` to `false` as it doesn't get you anything extra and you would use more disk space.

---

<div class="post-metadata">

### Author: ![ccclyt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ccclyt/32/14162_2.png) [@ccclyt](https://discuss.elastic.co/u/ccclyt)
#### Post date: [December 27, 2016, 11:08am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045/7 "2016-12-27T11:08:36Z")

</div>

definitly yes:)  
great answer, thx for that!

---

<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: [January 24, 2017, 11:08am UTC](https://discuss.elastic.co/t/whats-the-difference-between-store-and-doc-values-in-field-properties/70045/8 "2017-01-24T11:08:40Z")

</div>

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