PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] elasticquent/Elasticquent paginate issue, It returns all data

 January 19, 2022     elasticsearch, laravel, laravel-5, laravel-5.2, pagination     No comments   

Issue

I'm using 'elasticquent/Elasticquent' elasticsearch package for Laravel 5.2

here is my code

 $videos = Video::searchByQuery(['match_all' => []],null, null, 300, null, ['id' => 'desc']) ->paginate(42);

I want to get last 300 items with pagination 42 item per page, but it still returns all 300 items, not 42. Does anyone knows how to solve that problem?


Solution

As mentioned in the documentation found here, you can query by using the following function:

public static function searchByQuery(
    $query = null, 
    $aggregations = null, 
    $sourceFields = null, 
    $limit = null, 
    $offset = null, 
    $sort = null
)

Parameter 4 ($limit) and 5 ($offset) can be used to create pagination.


In your case the following query would grants you 42 results, from offset, 0.

$videos = Video::searchByQuery(['match_all' => []],null, null, 42, 0, ['id' => 'desc']);


Answered By - Nicklas Kevin Frank
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing