Elasticsearch aggregation from springboot

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

Query searchQuery = new NativeSearchQueryBuilder()
                   .withQuery(QueryBuilders.matchAllQuery())
                   .addAggregation(AggregationBuilders.terms("ProgramNames").field("measurementName").order(BucketOrder.key(true)))
                   .build();
           
           SearchHits<Measurement> meas = elasticsearchTemplate.search(searchQuery, Measurement.class);

error
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.
mea(3)
measR(4)
meart(6)

Hey,

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.

--Alex

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