# Terms Aggregation buckets returns only single words and not phrases. Truncates the text after space

**URL:** <https://discuss.elastic.co/t/terms-aggregation-buckets-returns-only-single-words-and-not-phrases-truncates-the-text-after-space/20908>\
**Category:** Elasticsearch\
**Created:** [November 24, 2014, 6:50am UTC](https://discuss.elastic.co/t/terms-aggregation-buckets-returns-only-single-words-and-not-phrases-truncates-the-text-after-space/20908 "2014-11-24T06:50:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vishal\_Sharma\_2](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Vishal\_Sharma\_2](https://discuss.elastic.co/u/Vishal_Sharma_2)\
**Post date:** [November 24, 2014, 6:50am UTC](https://discuss.elastic.co/t/terms-aggregation-buckets-returns-only-single-words-and-not-phrases-truncates-the-text-after-space/20908/1 "2014-11-24T06:50:41Z")

</div>

HI,

I have implemented the aggregation in one of my elastic search module. It  
works perfect but the terms aggregation bucket returns only single words  
and truncates the values after space.

Any idea?

Here is my schema, sample query and return:

_Schema:_  
community/Ideas/\_mapping?pretty  
{

"community" : {  
"mappings" : {  
"Ideas" : {  
"properties" : {  
"body" : {  
"type" : "string"  
},  
"categories" : {  
"type" : "string"  
}

```
    }

}

```

}

_Sample Query:_

POST /community/\_search  
{  
"aggregations": {  
"Category": {  
"terms": {  
"field": "categories",  
"min\_doc\_count": 1,  
"size": 0  
}  
}  
},  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"\_all": {  
"query": "ping search"  
}  
}  
}  
]  
}  
}  
}

_Return_:  
"aggregations": {  
"Category": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 0,  
"buckets": [  
{  
"key": "administration",  
"doc\_count": 166  
},  
{  
"key": "pingfederate",  
"doc\_count": 132  
}  
]  
}  
}

Now "Administration" should be "Administration in domain". But, it somehow  
truncates after administration. It looks fine in the Source node of hits.

Please help.

- Vishal

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [November 24, 2014, 8:52am UTC](https://discuss.elastic.co/t/terms-aggregation-buckets-returns-only-single-words-and-not-phrases-truncates-the-text-after-space/20908/2 "2014-11-24T08:52:42Z")

</div>

Hi,

When you put string data into elasticsearch, it will first be tokenized  
before being indexed. You need to let elasticsearch know that field values  
should not be tokenized by specifying "index": "not\_analyzed" in the  
mapping of your "categories" field.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Mon, Nov 24, 2014 at 7:50 AM, Vishal Sharma [vishals@grazitti.com](mailto:vishals@grazitti.com) wrote:

> HI,
> 
> I have implemented the aggregation in one of my Elasticsearch module. It  
> works perfect but the terms aggregation bucket returns only single words  
> and truncates the values after space.
> 
> Any idea?
> 
> Here is my schema, sample query and return:
> 
> _Schema:_  
> community/Ideas/\_mapping?pretty  
> {
> 
> "community" : {  
> "mappings" : {  
> "Ideas" : {  
> "properties" : {  
> "body" : {  
> "type" : "string"  
> },  
> "categories" : {  
> "type" : "string"  
> }
> 
> ```
> }
> 
> }
> 
> ```
> 
> }
> 
> _Sample Query:_
> 
> POST /community/\_search  
> {  
> "aggregations": {  
> "Category": {  
> "terms": {  
> "field": "categories",  
> "min\_doc\_count": 1,  
> "size": 0  
> }  
> }  
> },  
> "query": {  
> "bool": {  
> "must": [  
> {  
> "match": {  
> "\_all": {  
> "query": "ping search"  
> }  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> _Return_:  
> "aggregations": {  
> "Category": {  
> "doc\_count\_error\_upper\_bound": 0,  
> "sum\_other\_doc\_count": 0,  
> "buckets": [  
> {  
> "key": "administration",  
> "doc\_count": 166  
> },  
> {  
> "key": "pingfederate",  
> "doc\_count": 132  
> }  
> ]  
> }  
> }
> 
> Now "Administration" should be "Administration in domain". But, it somehow  
> truncates after administration. It looks fine in the Source node of hits.
> 
> Please help.
> 
> - Vishal
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
Adrien Grand

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7nCphhhnHwExMpfQmaG7eMZvE2BqjH0y4kqj9Yk9drHg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7nCphhhnHwExMpfQmaG7eMZvE2BqjH0y4kqj9Yk9drHg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Vishal\_Sharma\_2](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Vishal\_Sharma\_2](https://discuss.elastic.co/u/Vishal_Sharma_2)\
**Post date:** [November 24, 2014, 9:40am UTC](https://discuss.elastic.co/t/terms-aggregation-buckets-returns-only-single-words-and-not-phrases-truncates-the-text-after-space/20908/3 "2014-11-24T09:40:21Z")

</div>

Thanks a lot. That helps!

_Vishal Sharma\*\*TL, SFDC_T: +1 650 288 6711  
E: [vishals@grazitti.com](mailto:vishals@grazitti.com) [alok@grazitti.com](mailto:alok@grazitti.com)  
[www.grazitti.com](http://www.grazitti.com) [image: Description: LinkedIn]  
[http://www.linkedin.com/company/grazitti-interactive](http://www.linkedin.com/company/grazitti-interactive)[image: Description:  
Twitter] [https://twitter.com/grazitti](https://twitter.com/grazitti)[image: fbook]  
[https://www.facebook.com/grazitti.interactive](https://www.facebook.com/grazitti.interactive)_Zak_Calendar  
Salesforce1TM Calendar  
App for Teams  
[https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B5UPKEA3](https://appexchange.salesforce.com/listingDetail?listingId=a0N3000000B5UPKEA3)

On Mon, Nov 24, 2014 at 2:22 PM, Adrien Grand \<  
[adrien.grand@elasticsearch.com](mailto:adrien.grand@elasticsearch.com)\> wrote:

> Hi,
> 
> When you put string data into elasticsearch, it will first be tokenized  
> before being indexed. You need to let elasticsearch know that field values  
> should not be tokenized by specifying "index": "not\_analyzed" in the  
> mapping of your "categories" field.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#string)
> 
> On Mon, Nov 24, 2014 at 7:50 AM, Vishal Sharma [vishals@grazitti.com](mailto:vishals@grazitti.com)  
> wrote:
> 
> > HI,
> > 
> > I have implemented the aggregation in one of my Elasticsearch module. It  
> > works perfect but the terms aggregation bucket returns only single words  
> > and truncates the values after space.
> > 
> > Any idea?
> > 
> > Here is my schema, sample query and return:
> > 
> > _Schema:_  
> > community/Ideas/\_mapping?pretty  
> > {
> > 
> > "community" : {  
> > "mappings" : {  
> > "Ideas" : {  
> > "properties" : {  
> > "body" : {  
> > "type" : "string"  
> > },  
> > "categories" : {  
> > "type" : "string"  
> > }
> > 
> > ```
> > }
> > 
> > }
> > 
> > ```
> > 
> > }
> > 
> > _Sample Query:_
> > 
> > POST /community/\_search  
> > {  
> > "aggregations": {  
> > "Category": {  
> > "terms": {  
> > "field": "categories",  
> > "min\_doc\_count": 1,  
> > "size": 0  
> > }  
> > }  
> > },  
> > "query": {  
> > "bool": {  
> > "must": [  
> > {  
> > "match": {  
> > "\_all": {  
> > "query": "ping search"  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }
> > 
> > _Return_:  
> > "aggregations": {  
> > "Category": {  
> > "doc\_count\_error\_upper\_bound": 0,  
> > "sum\_other\_doc\_count": 0,  
> > "buckets": [  
> > {  
> > "key": "administration",  
> > "doc\_count": 166  
> > },  
> > {  
> > "key": "pingfederate",  
> > "doc\_count": 132  
> > }  
> > ]  
> > }  
> > }
> > 
> > Now "Administration" should be "Administration in domain". But, it  
> > somehow truncates after administration. It looks fine in the Source node of  
> > hits.
> > 
> > Please help.
> > 
> > - Vishal
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/9652d1d2-39eb-44d3-9b88-b2444801279a%40googlegroups.com?utm_medium=email&utm_source=footer)  
> > .  
> > For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).
> 
> --  
> Adrien Grand
> 
> --  
> You received this message because you are subscribed to a topic in the  
> Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit  
> [https://groups.google.com/d/topic/elasticsearch/KtJQY-l716o/unsubscribe](https://groups.google.com/d/topic/elasticsearch/KtJQY-l716o/unsubscribe).  
> To unsubscribe from this group and all its topics, send an email to  
> [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7nCphhhnHwExMpfQmaG7eMZvE2BqjH0y4kqj9Yk9drHg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7nCphhhnHwExMpfQmaG7eMZvE2BqjH0y4kqj9Yk9drHg%40mail.gmail.com)  
> [https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7nCphhhnHwExMpfQmaG7eMZvE2BqjH0y4kqj9Yk9drHg%40mail.gmail.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j7nCphhhnHwExMpfQmaG7eMZvE2BqjH0y4kqj9Yk9drHg%40mail.gmail.com?utm_medium=email&utm_source=footer)  
> .
> 
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAGMB1mZUx54rhesV%2B6szV9a76kHvu5fNnf%2BMTHk0g3wtsnGMuQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGMB1mZUx54rhesV%2B6szV9a76kHvu5fNnf%2BMTHk0g3wtsnGMuQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:48am UTC](https://discuss.elastic.co/t/terms-aggregation-buckets-returns-only-single-words-and-not-phrases-truncates-the-text-after-space/20908/4 "2017-07-06T00:48:09Z")

</div>


