# 2.x shingle aggregation feature is lost in 5.x?

**URL:** <https://discuss.elastic.co/t/2-x-shingle-aggregation-feature-is-lost-in-5-x/68395>\
**Category:** Elasticsearch\
**Created:** [December 8, 2016, 6:54am UTC](https://discuss.elastic.co/t/2-x-shingle-aggregation-feature-is-lost-in-5-x/68395 "2016-12-08T06:54:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ray33](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ray33/32/13704_2.png) [@Ray33](https://discuss.elastic.co/u/Ray33)\
**Post date:** [December 8, 2016, 6:54am UTC](https://discuss.elastic.co/t/2-x-shingle-aggregation-feature-is-lost-in-5-x/68395/1 "2016-12-08T06:54:08Z")

</div>

In ES2.x, a string field with shingle analyzer (see below mapping) was able to produce a nested term aggregation, where the nested aggregation produced the most common phrases (due to shingle analyzer).  
For example, for data:  
Country, data  
US, donald trump  
US, donald duck  
US, donald duck  
US, donald trump  
US, donald trump

The query would be able to retrieve that donald trump is the most searched term in US and donald duck is the second .

In ES5 where a field can be either text or keyword, it limits the query options to be either:

- keyword field - Top hits word - a **single** word aggregation, which means that on the above example it will show only donald as the most search word.
- text field (where it enables single analyzer) - it doesn't allow aggregation.

Any suggestion how to achieve a top searches aggregation for phrases in ES5 ?

This is the sample of shingle definition in 2.x :

> {  
> "mappings": {  
> "searches": {  
> "properties": {  
> "q": {  
> "type": "string",  
> "analyzer": "shingle\_analyzer"  
> }  
> }  
> }  
> },  
> "settings": {  
> "analysis": {  
> "filter": {  
> "shingle\_filter": {  
> "type": "shingle",  
> "max\_shingle\_size": 4,  
> "min\_shingle\_size": 2  
> }  
> },  
> "analyzer": {  
> "shingle\_analyzer": {  
> "filter": ["lowercase",  
> "shingle\_filter"],  
> "type": "custom",  
> "tokenizer": "standard"  
> }  
> }  
> }  
> }  
> }

The nested aggregation would be similar to this:

> {  
> "query" : {  
> "match\_all" : { }  
> },  
> "aggregations" : {  
> "countries" : {  
> "terms" : {  
> "field" : "country"  
> },  
> "aggregations" : {  
> "top\_searches" : {  
> "terms" : {  
> "field" : "q",  
> "size" : 3,  
> "min\_doc\_count" : 2,  
> "include" : ".{4,35}"  
> }  
> }  
> }  
> }  
> }  
> }

---

<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 5, 2017, 6:54am UTC](https://discuss.elastic.co/t/2-x-shingle-aggregation-feature-is-lost-in-5-x/68395/2 "2017-01-05T06:54:20Z")

</div>

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