# How to get Alphabetic Facet (A-Z) on name field

**URL:** https://discuss.elastic.co/t/how-to-get-alphabetic-facet-a-z-on-name-field/62386
**Category:** Elasticsearch
**Created:** [October 6, 2016, 1:35pm UTC](https://discuss.elastic.co/t/how-to-get-alphabetic-facet-a-z-on-name-field/62386 "2016-10-06T13:35:56Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Srinivasulu\_Dagda](https://avatars.discourse-cdn.com/v4/letter/s/e47c2d/32.png) [@Srinivasulu\_Dagda](https://discuss.elastic.co/u/Srinivasulu_Dagda)
#### Post date: [October 6, 2016, 1:35pm UTC](https://discuss.elastic.co/t/how-to-get-alphabetic-facet-a-z-on-name-field/62386/1 "2016-10-06T13:35:56Z")

</div>

For example:

If I have docs with following name

1. Maaz
2. John
3. Sarah
4. Symonds

The facets response should be something like  
{  
"facets": {  
"name": {  
"\_type": "terms",  
"missing": 0,  
"total": 4,  
"other": 0,  
"terms": [  
{  
"term": "S",  
"count": 2  
},  
{  
"term": "M",  
"count": 1  
},  
{  
"term": "J",  
"count": 1  
}  
}

This is my query

curl -X POST 'localhost:9200/test/test/\_search?pretty' -d '{"query": {  
"match\_all": {}} , "aggs" : { "myName" : { "terms" : { "field":"name",  
"script" : "term[0]" } } } }'

receiving this error

"error": {  
"root\_cause": [  
{  
"type": "script\_exception",  
"reason": "failed to run inline script [term[0]] using lang [groovy]"  
}  
],  
"type": "search\_phase\_execution\_exception",  
"reason": "all shards failed",  
"phase": "query",  
"grouped": true,  
"failed\_shards": [  
{  
"shard": 0,  
"index": "test",  
"node": "o6\_h5ieaRP2tCLj-xtD1-g",  
"reason": {  
"type": "script\_exception",  
"reason": "failed to run inline script [term[0]] using lang [groovy]",  
"caused\_by": {  
"type": "missing\_property\_exception",  
"reason": "No such property: term for class: 483879787eba1d741e12ba33ec3f642790b70837"  
}  
}  
}  
]  
},  
"status": 500

---

<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 5, 2017, 10:14pm UTC](https://discuss.elastic.co/t/how-to-get-alphabetic-facet-a-z-on-name-field/62386/2 "2017-07-05T22:14:16Z")

</div>


