Search code examples
phpelasticsearchfoselasticabundle

how to use scroll in foselasticabundle?


I would like to know how can i set scroll in foselasticabundle? I have this code

$res = $this->commentIndex->createSearch($query, ['scroll' => '1m']);
 $res->addType('reading');
 $res->scroll();

I know Im already close getting the result of my query. Can you help me which of the function in foselasticabundle I can use to display the results of my query. Im trying deep study the code of foselasticabundle.


Solution

  • I found the answer of the issue in this link

    I have this code the same in the link

    $search = $this->commentIndex->createSearch();
    $search->addType('reading');
    $search->setQuery($query);
    $scroll = new \Elastica\Scroll($search);
    $results = [];
    
    
    foreach ($scroll as $scrollId => $resultSet) {
          foreach ($resultSet->getDocuments() as $doc) {
             $results[$doc->getId()] = $doc;
          }
       }
    

    So far in this approach I can get the scroll id and the results i need. But if you found another way, hoping you can post it in this question.