嗨,我正在尝试通过elasticSearch查询获取所有结果,但是如果$ limit值为null,它只会返回10个结果。
$videos = Video::searchByQuery([
'match' => [
$field => $request->$field
],
],null,null,null);
那么如何获得所有结果呢?
最佳答案
这是因为default size for requests is 10并没有将长度限制传递给任何框架,可能会将其设置为默认值。您可以使用from和size较大的值:
Though from and size can be set as request parameters, they can also be set within the search body. from defaults to 0, and size defaults to 10.
但是,正如question very similar to yours中指出的那样,仅使用
from
和size
就无法进行无限制的搜索,如果您确实需要处理非常大的结果集,则使用ES documentation has some suggestions on search types可能会很好,使用scrollthe scroll API can be used to retrieve large numbers of results (or even all results) from a single search request, in much the same way as you would use a cursor on a traditional database.
Scrolling is not intended for real time user requests, but rather for processing large amounts of data
不过请注意最后一句话,如果这是实时请求,则您可能需要仔细阅读第三个链接,以决定采取哪种最佳措施。
另外,如果您在问题中描述用例,可能会有所帮助,好像这是针对用户返回的结果,我无法想象他们想一次看到所有结果,并且对分页内容感到满意方法。
完成研究并了解基础知识之后,建议您查看正在使用的库的文档以确定如何进行。
P.s.下次您问有关ES的问题时,还包括您使用的版本,因为这会影响某些答案,具体取决于您的要求。
关于php - Elasticquent(ElasticSearch)Laravel限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60640663/