How can i use a annotation to do an aggragation like @Query(value = “{”query“:”“}”)

本小妞迷上赌 提交于 2019-12-04 05:29:15

问题


How can I use an annotation to do an aggragation like @Query(value = "{"query":""}") with spring-data-elasticsearch?


回答1:


You cannot do it with the @Query annotation whose only purpose is to send a query, not aggregations.

The only way to achieve this with Spring Data Elasticsearch is to leverage NativeSearchQueryBuilder and ElasticsearchTemplate:

SearchQuery searchQuery = new NativeSearchQueryBuilder()
    .withQuery(QueryBuilders.matchAll())
    .withSearchType(COUNT)
    .withIndices("your_index")
    .withTypes("your_type")
    .addAggregation(AggregationBuilders.terms("tags").field("tag"));

elasticsearchTemplate.queryForPage(searchQuery, YourEntity.class);


来源:https://stackoverflow.com/questions/40083696/how-can-i-use-a-annotation-to-do-an-aggragation-like-queryvalue-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!