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


(Srinivasulu Dagda) #1

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


(system) #2