I am using following aggregation:
searchOptions.aggs = { categories: { terms: { field: \"CategoryId\" } } }
This works howeve
If you want to get category name for that id then,
{ "size": 0, "aggs": { "category": { "terms": { "field": "categoryId" }, "aggs":{ "categoryName" :{ "terms" :{ "field" :"categoryName" } } } } } }
So, sub-aggregation(which is nested in above) gives you categoryName for its id.