我有一个 Spring Boot 应用程序,并使用 spring-data-elasticsearch-5.1.2 创建一个
scroll
请求以从 elasticsearch 获取大量“书”。设置看起来像这样:
public interface BookRepository extends ElasticsearchRepository<Book, String> {
Stream<Book> findByAuthorName(String authorName);
}
// and client code invokes like
try (Stream<Book> books = bookRepository.findByAuthor(authorName)) {
return books.toList();
}
catch (Exception e) {
// handle
}
这确实有效,但默认情况下滚动请求大小为 500(即生成的查询具有
size: 500
)。我希望能够更改此值以获取更大的结果集,但不确定如何执行此操作。
我尝试更新存储库方法以接受 Pageable
,然后使用更大的页面大小进行调用。例如
public interface BookRepository extends ElasticsearchRepository<Book, String> {
// Add Pageable parameter
Stream<Book> findByAuthorName(String authorName, Pageable page);
}
// Pass pageable with larger size
try (Stream<Book> books = bookRepository.findByAuthor(authorName, Pageable.ofSize(1_000))) {
return books.toList();
}
catch (Exception e) {
// handle
}
但是,生成的查询似乎没有受到影响。
{
"_source": { ... },
"from": 0,
"query": { ... },
"size": 500, <----- HOW TO CHANGE?
"track_scores": false,
"version": true
}
如何更改查询大小?