简体   繁体   English

带有自定义@Query注释的Spring-Data弹性搜索回购计数不起作用“预期1,但找到30个结果”

[英]Spring-Data elastic search repo count with custom @Query annotation not working “Expected 1 but found 30 results”

For my application I have to perform a custom count on elastic, I want to use the @Query annotation for this in the ElasticsearchCrudRepository we use. 对于我的应用程序,我必须对弹性执行自定义计数,我想在我们使用的ElasticsearchCrudRepository中为此使用@Query批注。 When I use the following signature: 当我使用以下签名时:

@Query("CUSTOM BOOL QUERY HERE")
long countItemsCustom();

This leads to a java.lang.IllegalArgumentException: Expected 1 but found 30 results Exception since it is executed as an query instead of an count. 这将导致java.lang.IllegalArgumentException: Expected 1 but found 30 results Exception,因为它是作为查询而不是计数执行的。 For spring-data-cassandra we have a special @CountQuery annotation to solve this issue. 对于spring-data-cassandra,我们有一个特殊的@CountQuery批注来解决此问题。 Is there a similar solution in spring-data-elasticsearch ? 在spring-data-elasticsearch中有类似的解决方案吗?

I could use the elastic client or template to perform a custom query and get the results, but I prefer using the existing repository interface for this if possible. 我可以使用弹性客户端或模板来执行自定义查询并获取结果,但是如果可能的话,我更喜欢使用现有的存储库接口。

No, that's not possible at the moment. 不,目前尚不可能。 The ElasticsearchStringQuery class checks the return type of the method that is annotated with the @Query annotation and then executes the ElasticsearchOperations.queryFor...() method that is appropriate for the method's return type. ElasticsearchStringQuery类检查使用@Query注释注释的方法的返回类型,然后执行适合于该方法的返回类型的ElasticsearchOperations.queryFor...()方法。 These are queries for data and not for the count. 这些是查询数据而不是计数。

I created an issue in the Spring Data Elasticsearch Jira to have this feature added. 我在Spring Data Elasticsearch Jira中创建了一个问题以添加此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM