繁体   English   中英

Elasticsearch分页自-大小结果窗口太大

[英]Elasticsearch Pagination From - Size Result window is too large

我想为文档创建页面,每个页面应该有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/zh-cn/elasticsearch/reference/current/search-request-from-size.html

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

或者,您可以尝试使用scrollsearchAfter 对于更实时的查询, searchAfter更合适。

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

SearchAfter文档https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/search-request-search-after.html

如错误所示,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 } }'

增加max_result_window如下,它的工作原理

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

暂无
暂无

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

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