# Understanding doc\_values

**URL:** <https://discuss.elastic.co/t/understanding-doc-values/90318>\
**Category:** Elasticsearch\
**Created:** [June 21, 2017, 3:04pm UTC](https://discuss.elastic.co/t/understanding-doc-values/90318 "2017-06-21T15:04:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![misomij](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/misomij/32/10700_2.png) [@misomij](https://discuss.elastic.co/u/misomij)\
**Post date:** [June 21, 2017, 3:04pm UTC](https://discuss.elastic.co/t/understanding-doc-values/90318/1 "2017-06-21T15:04:51Z")

</div>

Hi all,

I read the documentation about [doc\_values](https://www.elastic.co/guide/en/elasticsearch/guide/current/_deep_dive_on_doc_values.html) and I'm trying to apply it in es 2.4.5

In my understanding I can enable doc\_values and disable fielddata on a not\_analyzed string and be able to do aggregations on it.

So I created a template to use doc\_values and not fielddata

> POST \_template/test  
> {  
> "order": 0,  
> "template": "test",  
> "settings": {  
> "number\_of\_shards": 1,  
> "number\_of\_replicas": 0  
> },  
> "mappings": {  
> "data": {  
> "properties": {  
> "name": {  
> "type": "string",  
> "fielddata": {  
> "format": "disabled"  
> },  
> "index": "not\_analyzed",  
> "doc\_values": true  
> }  
> }  
> }  
> }  
> }

Then I indexed a document in a new index matching the pattern

> POST test/data/1  
> {  
> "name":"The Undertaker"  
> }

I can search that field

> GET test/\_search  
> {  
> "query": {  
> "match\_all": {}  
> }  
> }

> {  
> "took": 1,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 1,  
> "successful": 1,  
> "failed": 0  
> },  
> "hits": {  
> "total": 1,  
> "max\_score": 1,  
> "hits": [  
> {  
> "\_index": "test",  
> "\_type": "data",  
> "\_id": "1",  
> "\_score": 1,  
> "\_source": {  
> "name": "The Undertaker"  
> }  
> }  
> ]  
> }  
> }

But I can't do aggregations

> GET test/\_search  
> {  
> "size": 20,  
> "aggs": {  
> "nameagg": {  
> "terms": {  
> "field": "name",  
> "size": 10  
> }  
> }  
> }  
> }

> {  
> "error": {  
> "root\_cause": [  
> {  
> "type": "illegal\_state\_exception",  
> "reason": "Field data loading is forbidden on [name]"  
> }  
> ],  
> "type": "search\_phase\_execution\_exception",  
> "reason": "all shards failed",  
> "phase": "query\_fetch",  
> "grouped": true,  
> "failed\_shards": [  
> {  
> "shard": 0,  
> "index": "test",  
> "node": "1smXs7ldTr67Vuwu-GKagQ",  
> "reason": {  
> "type": "illegal\_state\_exception",  
> "reason": "Field data loading is forbidden on [name]"  
> }  
> }  
> ]  
> },  
> "status": 500  
> }

I would expect to be able to aggregate on this field, at least this is what I understood from the docs.  
Why is it complaining about fielddata?  
Anyone can help me to understand this?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [June 23, 2017, 2:35pm UTC](https://discuss.elastic.co/t/understanding-doc-values/90318/2 "2017-06-23T14:35:24Z")

</div>

> [@misomij](#):
>
> I would expect to be able to aggregate on this field, at least this is what I understood from the docs.  
> Why is it complaining about fielddata?  
> Anyone can help me to understand this?

This does look like an issue, the syntax looks correct for disabling fielddata and enabling doc\_values, but it seems to thing fielddata is enabled regardless.

I did test and since doc\_values are the default for `not_analyzed` fields in 2.4.5, you can use:

```
POST _template/test
{
  "order": 0,
  "template": "test",
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "data": {
      "properties": {
        "name": {
          "type": "string",
          "index": "not_analyzed"
        }
      }
    }
  }
}

```

And then your example works

---

<div class="post-metadata">

**Author:** ![misomij](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/misomij/32/10700_2.png) [@misomij](https://discuss.elastic.co/u/misomij)\
**Post date:** [June 29, 2017, 10:56am UTC](https://discuss.elastic.co/t/understanding-doc-values/90318/3 "2017-06-29T10:56:39Z")

</div>

Ok so it means:

- doc\_values are enabled by default for not\_analyzed strings
- indexing my document i will have doc\_values and aggs will use it
- fielddata is not disabled, but since my is a not\_analyzed string it will never use ti (instead uses doc\_values)

am I correct?  
how can I confirm this is an issue? should I open one on github?

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [June 29, 2017, 4:58pm UTC](https://discuss.elastic.co/t/understanding-doc-values/90318/4 "2017-06-29T16:58:45Z")

</div>

> [@misomij](#):
>
> fielddata is not disabled, but since my is a not\_analyzed string it will never use ti (instead uses doc\_values)

Fielddata is still going to be disabled in this case. Doc values will be used for sorting and aggregations.

> [@misomij](#):
>
> how can I confirm this is an issue? should I open one on github?

This is an issue (I was able to reproduce it), so yes, please do open an issue on github.

---

<div class="post-metadata">

**Author:** ![misomij](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/misomij/32/10700_2.png) [@misomij](https://discuss.elastic.co/u/misomij)\
**Post date:** [June 30, 2017, 7:50am UTC](https://discuss.elastic.co/t/understanding-doc-values/90318/5 "2017-06-30T07:50:06Z")

</div>

opened issue [#25484](https://github.com/elastic/elasticsearch/issues/25484)

---

<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:** [July 28, 2017, 7:50am UTC](https://discuss.elastic.co/t/understanding-doc-values/90318/6 "2017-07-28T07:50:08Z")

</div>

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