Elasticsearch aggregation from springboot

I am trying to get all the values for a filed with count using Aggregation Here is my code

Query searchQuery = new NativeSearchQueryBuilder()
           SearchHits<Measurement> meas = elasticsearchTemplate.search(searchQuery, Measurement.class);

i am able to get the docCount in bucket but not the keyAsString keyAsString is always null. am i looking correct places for the result.
i am trying to build facets for measurementName field.


I haven't dug too deep in the code. I assume you ran bucket.getKeyAsString() before looking in the debug output? I just want to make sure, that there is no lazy initialization happening, as the BytesRef above named key seems not to be null.

Apart from that, this looks perfectly fine from a code perspective, I do have pretty much the same code in my own app.