简体   繁体   English

如何在 Elasticsearch 中获取带有分页的总记录

[英]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.在我的product索引中,我有 60K 条记录,我正在使用fromsize参数运行匹配查询。 by default, ES support a 10k record search so I have increased it to 60k.默认情况下,ES 支持 10k 记录搜索,因此我将其增加到 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.我的问题是我已经从 API 传递大小参数,我想用相同的分页大小参数搜索 60K 记录。

So how I can match 60k records with my pagination size param.那么我如何将 60k 记录与我的分页大小参数匹配。

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:这里有 60K 大小的代码:

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.在我的查询中,如果我使用 size=60K,我会得到 20 条记录(没有我会得到 12 条记录),但我不能使用分页参数。

If I get your question correctly,如果我正确地回答了你的问题,

size parameter is the number of hits/documents you want in response. size参数是您想要响应的点击数/文档数。 It's not that elasticsearch will process your query only in first size number of documents.并不是说 elasticsearch 只会在第一个大小的文档中处理您的查询。 10K is the maximum number of documents you can get in response. 10K 是您可以响应的最大文档数。 If you specify size more than 10K, elastic search will give you an error like this.如果你指定大小超过 10K,弹性搜索会给你这样的错误。 ES error ES错误

Without worring about the above problem, use from and size as the parameters for your pagination.不用担心上述问题,使用fromsize作为分页的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM