弹性搜索分页自 - 大小结果窗口太大



我想为我的文档提供页面,每个页面应该有 1000 个结果。

文档大小: 95.000 文档

因此,从产品编号 10k 开始,我希望从这一点获得 1K 结果,但是,使用此查询,我得到了下面提到的错误

查询:

this.es.search({
  index: indexName,
  type: type,
  from: 10000,
  size: 1000,
  body: {}
});

错误:

{
    "msg": "[query_phase_execution_exception] Result window is too large, from + size must be less than or equal to: [10000] but was [16000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.",
    "path": "/products/Product/_search",
    "query": {},
    "body": "{"from":10000,"size":1000}",
    "statusCode": 500,
    "response": "{"error":{"root_cause":[{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [16000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting."}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"products","node":"bTGkra6dTB-0Z_8jVUNByQ","reason":{"type":"query_phase_execution_exception","reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [16000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting."}}]},"status":500}"
}

如何提高分页结果/限制?

也欢迎任何其他方法,谢谢。

基于 elasticsearch 文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

注意 from + size 不能大于 index.max_result_window 默认为 10,000 的索引设置

作为替代方法,您可以尝试使用 scrollsearchAfter .对于更实时的查询,searchAfter更适合。

滚动文档https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html

搜索文档后https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html

按如下方式增加max_result_window,它有效

PUT indexName/_settings
{
  "index": {
    "max_result_window": 10000000
  }
}

正如错误显示的那样,Elastic 只会显示 10000 行。

因此,要显示超过该数字的数字,您需要使用 scroll 功能

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html

可以在此处找到使用滚动进行 js 搜索的示例。

异步等待与 elasticsearch 搜索/滚动

好吧

,我可以使用此 CURL 增加分页限制

curl -XPUT "http://localhost:9200/my_index/_settings" -d '{ "index" : { "max_result_window" : 500000 } }'

最新更新