zulqarnain
zulqarnain

Reputation: 1626

How to get total records with pagination in Elasticsearch

In my product index I have 60K records, I'm running a match query with from, size params. by default, ES support a 10k record search so I have increased it to 60k.

My issue is I'm already passing size param from API & I want to search in 60K records with the same pagination size param.

So how I can match 60k records with my pagination size param.

Here is my code:

const query = {
    query: {
        match: {
            name: {
                query: req.text
            }
        }
    }
}

const { body: { hits } } = await esclient.search({
    from: req.skip || 0,
    size: req.offset || 50,
    index: productsIndex,
    type: productsType,
    body: query,
});

here code with 60K size:

const query = {
    query: {
        match: {
            name: {
                query: req.text
            }
        }
    },
    size:60000
}

in my query, if I use size=60K, I'm getting 20 records (without that I'm getting 12 records) but I can't use pagination params.

Upvotes: 0

Views: 94

Answers (1)

Aakash Rana
Aakash Rana

Reputation: 23

If I get your question correctly,

size parameter is the number of hits/documents you want in response. It's not that elasticsearch will process your query only in first size number of documents. 10K is the maximum number of documents you can get in response. If you specify size more than 10K, elastic search will give you an error like this. ES error

Without worring about the above problem, use from and size as the parameters for your pagination.

Upvotes: 0

Related Questions