Elasticquent(ElasticSearch) Laravel limit

◇◆丶佛笑我妖孽 提交于 2021-02-05 11:21:27

问题


Hi I'm trying to get all results with elasticSearch query, but it returns only 10 results if $limit value is null.

$videos = Video::searchByQuery([
                'match' => [
                    $field => $request->$field
                ],
        ],null,null,null);

so how to get all results ?


回答1:


That's because the default size for requests is 10 and not passing a length limit to any framework is probably going to set it to the default. You can use from and size with large values though:

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.

But, as pointed out in a question very similar to yours, there's no way to do an unlimited sized search just using from and size, and the ES documentation has some suggestions on search types if you really need to process a very large result set, it might be good to use scroll

the 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

Take note of the last sentence though, if this is for a real time request you might want to read that third link carefully to decide what the best course of action to take is.

Also, if you describe your use case in your question, it might be helpful as if this is for a user-returned result, I can't imagine that they want to see all your results at once, and would be content with a paginated approach.

Once you've done that research and understand the underlying, I'd suggest you look in the documentation of the library you're using to determine how to proceed.

P.s. Next time you ask a question about ES also include the version you're using, as that will affect some answers depending on what you're asking about.




回答2:


Try This

$params = [
    "search_type" => "scan",
    "scroll" => "30s",
    "size" => 50,
    'match' => [
                $field => $request->$field
            ],
    ];


  $videos = Video::searchByQuery($params);


来源:https://stackoverflow.com/questions/39041247/elasticquentelasticsearch-laravel-limit

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