且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在弹簧数据弹性搜索中设置结果大小为零

更新时间:2023-02-19 09:38:15

如果您使用ES 1.x,您可以做的是省略 ,并指定搜索类型 COUNT

If you're using ES 1.x, what you can do is leave out the Pageable and specify the search type COUNT instead.

SearchQuery searchQuery = new NativeSearchQueryBuilder()
            .withIndices(indexName).withTypes(typeName)
            .withQuery(queryBuilder).withAggregation(aggsBuilder)
            .withSearchType(SearchType.COUNT).build();

截至ES 2.x, SearchType.COUNT 将被废弃,不再可用,但是对于ES 1.x需要这样做。

As of ES 2.x, SearchType.COUNT will be deprecated and not available anymore, but for ES 1.x needs this should do the job.

请注意,有一个类似的需求,对于其他用户来说,但问题仍然是开放的。

Note that there's a similar need for other users, too, but the issue is still open.