0

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
    have you tried to specify `$limit => 10000` ? – Val Aug 19 '16 at 14:20
  • yes and that helps,but maybe some cases when I need more than 10000, is it possible? – Avet Antonyan Aug 19 '16 at 14:24
  • Ideally, you should do a [scan/scroll](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html) instead, but I'm not certain that elastiquent provides that feature. – Val Aug 19 '16 at 14:28
  • How many more than 10000 are we talking? And what's the use case behind this need? – Val Aug 19 '16 at 14:28
  • it's for adult website with huge content, so I don't know how many results could be, but anyway, I'll let it 10000 for now, thanks for answer – Avet Antonyan Aug 19 '16 at 14:44

2 Answers2

2

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.

Community
  • 1
  • 1
EdgeCaseBerg
  • 2,761
  • 1
  • 23
  • 39
0

Try This

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


  $videos = Video::searchByQuery($params);
Parithiban
  • 1,656
  • 11
  • 16