ebrahim
ebrahim

Reputation: 1

How to page more than 10,000 data with Laravel and Elastic-Search?

$params = [
    'index' => 'my_index',
    'body'  => [
        'query' => [
            'match' => [
                'testField' => 'abc'
            ]
        ]
    ]
];
$response = $client->search($params);

How to page more than 10,000 data with Laravel and Elastic-Search ?```

How can I paginate the data like this?

Upvotes: 0

Views: 78

Answers (1)

Musab Dogan
Musab Dogan

Reputation: 3580

For pagination you can use the following methods:

  1. from-size
  2. search after

You can add the 'from' and 'size' parameters to the $params array like this:

$params = [
    'index' => 'my_index',
    'body'  => [
        'query' => [
            'match' => [
                'testField' => 'abc'
            ]
        ]
    ],
    'from' => 0,
    'size' => 10
];
$response = $client->search($params);

The 'from' parameter determines the starting point for the results, and the 'size' parameter determines the number of results to return. In this example, the query will return the first 10 results starting from the first one (0-based index).

References: https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html

Upvotes: 0

Related Questions