# Ordering the buckets alphabetically by their terms in an ascending manner

**URL:** <https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234>\
**Category:** Elasticsearch\
**Created:** [February 7, 2017, 2:44pm UTC](https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234 "2017-02-07T14:44:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akhilesh\_Anb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhilesh_anb/32/4343_2.png) [@Akhilesh\_Anb](https://discuss.elastic.co/u/Akhilesh_Anb)\
**Post date:** [February 7, 2017, 2:44pm UTC](https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234/1 "2017-02-07T14:44:55Z")

</div>

I have upgraded Elasticsearch recently from 2.4.1 to 5.1.2

I'm using the query,

> GET /question/question\_name/\_search  
> {  
> "size": 0,  
> "aggs": {  
> "agg": {  
> "terms": {  
> "field": "question\_name.raw",  
> "order": {  
> "\_term": "asc"  
> },  
> "size": 10000  
> }  
> }  
> }  
> }

Response :

> {  
> "took": 3,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 2122,  
> "max\_score": 0,  
> "hits":   
> },  
> "aggregations": {  
> "agg": {  
> "doc\_count\_error\_upper\_bound": 0,  
> "sum\_other\_doc\_count": 0,  
> "buckets":   
> }  
> }  
> }

It's returning buckets as empty .

Anyone please help me on this.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 7, 2017, 3:19pm UTC](https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234/2 "2017-02-07T15:19:55Z")

</div>

Hey,

can you check your mapping, if you have a field called `question_name.raw`?

--Alex

---

<div class="post-metadata">

**Author:** ![Akhilesh\_Anb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhilesh_anb/32/4343_2.png) [@Akhilesh\_Anb](https://discuss.elastic.co/u/Akhilesh_Anb)\
**Post date:** [February 7, 2017, 3:27pm UTC](https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234/3 "2017-02-07T15:27:26Z")

</div>

I checked the mapping and i found this:

> GET /question\_search\_navigation\_data/question\_name\_details/\_mapping

> "question\_name": {  
> "type": "text",  
> "fields": {  
> "keyword": {  
> "type": "keyword",  
> "ignore\_above": 256  
> }

---

<div class="post-metadata">

**Author:** ![Akhilesh\_Anb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhilesh_anb/32/4343_2.png) [@Akhilesh\_Anb](https://discuss.elastic.co/u/Akhilesh_Anb)\
**Post date:** [February 7, 2017, 3:28pm UTC](https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234/4 "2017-02-07T15:28:59Z")

</div>

Same query worked fine before upgrading the Elasticsearch

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 7, 2017, 3:29pm UTC](https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234/5 "2017-02-07T15:29:46Z")

</div>

Hey,

you have not ported over the mappings. You need to use `question_name.keyword` to make it work.

--Alex

---

<div class="post-metadata">

**Author:** ![Akhilesh\_Anb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/akhilesh_anb/32/4343_2.png) [@Akhilesh\_Anb](https://discuss.elastic.co/u/Akhilesh_Anb)\
**Post date:** [February 7, 2017, 3:40pm UTC](https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234/6 "2017-02-07T15:40:59Z")

</div>

Thank you very much. It worked for me.

---

<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 7, 2017, 3:41pm UTC](https://discuss.elastic.co/t/ordering-the-buckets-alphabetically-by-their-terms-in-an-ascending-manner/74234/7 "2017-03-07T15:41:38Z")

</div>

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