簡體   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