# Terms Aggregation on Text field, fielddata true. Wrong doc\_count

**URL:** <https://discuss.elastic.co/t/terms-aggregation-on-text-field-fielddata-true-wrong-doc-count/74594>\
**Category:** Elasticsearch\
**Created:** [February 10, 2017, 4:28am UTC](https://discuss.elastic.co/t/terms-aggregation-on-text-field-fielddata-true-wrong-doc-count/74594 "2017-02-10T04:28:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anks](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anks](https://discuss.elastic.co/u/anks)\
**Post date:** [February 10, 2017, 4:28am UTC](https://discuss.elastic.co/t/terms-aggregation-on-text-field-fielddata-true-wrong-doc-count/74594/1 "2017-02-10T04:28:05Z")

</div>

Hi

I am trying to run terms aggregation on full text field with type as 'text' and fielddata enabled.

I am getting doc\_count 1 per document match instead of frequency of term.

**Mapping -**

{"mappings":{"data":{"properties":{"content":{"type":"text","fielddata":true} } }}}

**Index data -**

/test/data/1  
{"content":"concrete concrete"}

**Query -**  
{  
"query": {  
"match": {  
"\_id": "1"  
}  
},  
"aggs": {  
"content": {  
"terms": {  
"field": "content"  
}  
}  
}  
}

**Response -**

{  
"took": 4,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 1,  
"hits": [  
{  
"\_index": "test",  
"\_type": "data",  
"\_id": "1",  
"\_score": 1,  
"\_source": {  
"content": "concrete concrete"  
}  
}  
]  
},  
"aggregations": {  
"content": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "concrete",  
"doc\_count": **1**  
}  
]  
}  
}  
}

doc\_count should be 2 ?

Thanks,  
Ankita

---

<div class="post-metadata">

**Author:** ![wenpos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wenpos/32/15326_2.png) [@wenpos](https://discuss.elastic.co/u/wenpos)\
**Post date:** [February 10, 2017, 6:56am UTC](https://discuss.elastic.co/t/terms-aggregation-on-text-field-fielddata-true-wrong-doc-count/74594/2 "2017-02-10T06:56:49Z")

</div>

In fact , the docs number match the query is one. Once you put data {"content":"concrete concrete guess"}, and terms aggs it, result is :  
"buckets": [  
{  
"key": "concrete",  
"doc\_count": 1  
}  
,  
{  
"key": "guess",  
"doc\_count": 1  
}  
]  
I think this indicates that the field was firstly analyzed to two terms "concrete" and "guess" , remove duplicate term，and then group by the two terms.

---

<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:** [March 10, 2017, 6:56am UTC](https://discuss.elastic.co/t/terms-aggregation-on-text-field-fielddata-true-wrong-doc-count/74594/3 "2017-03-10T06:56:54Z")

</div>

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