# How to use "aggs" on a text type field

**URL:** <https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619>\
**Category:** Elasticsearch\
**Created:** [June 13, 2019, 11:03am UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619 "2019-06-13T11:03:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![zatom](https://avatars.discourse-cdn.com/v4/letter/z/f0a364/32.png) [@zatom](https://discuss.elastic.co/u/zatom)\
**Post date:** [June 13, 2019, 11:03am UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619/1 "2019-06-13T11:03:32Z")

</div>

Hi everyone!

I have a problem that I have been unable to solve for the past couple of months. I am using ES 6. In my index, there is a field of type "text". Documents keep increasing every day. I want to check & count all the fields with their values created on a particular day/date. My field value looks like this " abc/456/xyz/23-b/mnb.cb" . Everytime I try to use aggs on this field, Elastic search tokenizes like "abc", "456", "xyz", "23",etc and counts every tokens how many times they occur throughout an index. My main objective is to see how many duplicates are there, and I want ES to take my field value "abc/456/xyz/23-b/mnb.cb" as a single string and tell me if there is any exact looking value if any for a particular date. I have tried doing textfield=True, but it doesnot let me. Lot of people are talking about update mapping ; index=not analyzed. But, looks like you can't do it anymore. its either true or false only at the time of indexing and I don't want to reindex. What are my options here? please help!!

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [June 13, 2019, 11:12am UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619/2 "2019-06-13T11:12:15Z")

</div>

Hi zatom,

What you are looking for is the [keyword](https://www.elastic.co/guide/en/elasticsearch/reference/master/keyword.html) data type which does not break strings into multiple tokens

---

<div class="post-metadata">

**Author:** ![zatom](https://avatars.discourse-cdn.com/v4/letter/z/f0a364/32.png) [@zatom](https://discuss.elastic.co/u/zatom)\
**Post date:** [June 13, 2019, 11:16am UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619/3 "2019-06-13T11:16:57Z")

</div>

@Mark_Harwood Hi Mark. can I update that in my mapping setting? or I can do it only at the time of indexing?

Thank you

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [June 13, 2019, 11:23am UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619/4 "2019-06-13T11:23:53Z")

</div>

> [@zatom](#):
>
> Hi Mark. can I update that in my mapping setting?

It's not possible to change the type from `text` to `keyword` but you can use the [reindex](https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-reindex.html) api to copy the docs to a new index with the correct mapping

---

<div class="post-metadata">

**Author:** ![zatom](https://avatars.discourse-cdn.com/v4/letter/z/f0a364/32.png) [@zatom](https://discuss.elastic.co/u/zatom)\
**Post date:** [June 13, 2019, 11:37am UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619/5 "2019-06-13T11:37:59Z")

</div>

@Mark_Harwood Thanx for the suggestion. What are the cost of reindexing if any? My index has more than 20million documents. Is it a good idea to reindex for that amount of volume? How long should it take?

PUT my\_index  
{  
"mappings": {  
"properties": {  
"tags": {  
"type": "keyword"  
}  
}  
}  
}

Will this get applied to all my fields or a particular field if I specify?

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [June 13, 2019, 12:33pm UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619/6 "2019-06-13T12:33:23Z")

</div>

> [@zatom](#):
>
> What are the cost of reindexing if any?

At least the same as the cost of original indexing - it's essentially reading and writing again all of the content. The storage will of course be doubled until you delete the old index

> [@zatom](#):
>
> Will this get applied to all my fields or a particular field if I specify?

That might be how you declare a new field but cannot be used to change the type of an existing `tags` field in an index.

---

<div class="post-metadata">

**Author:** ![zatom](https://avatars.discourse-cdn.com/v4/letter/z/f0a364/32.png) [@zatom](https://discuss.elastic.co/u/zatom)\
**Post date:** [June 13, 2019, 12:51pm UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619/7 "2019-06-13T12:51:07Z")

</div>

@Mark_Harwood thank you. Will let you know if any questions in future

---

<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 11, 2019, 12:51pm UTC](https://discuss.elastic.co/t/how-to-use-aggs-on-a-text-type-field/185619/8 "2019-07-11T12:51:09Z")

</div>

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