Elasticsearch 分页来源 - 大小结果 window 太大
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}"
}
如何提高分页结果/限制?
也欢迎任何其他方法,谢谢。
如错误所示,Elastic 将只显示 10000 行。
所以要显示更多的数字,您需要使用 scroll
函数
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
可以在此处找到带有滚动的 js 搜索示例。
基于 elasticsearch 文档https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html
Note that from + size can not be more than the index.max_result_window
index setting which defaults to 10,000
作为替代,您可以尝试使用 scroll
或 searchAfter
。对于更实时的查询,searchAfter
更合适。
滚动文档
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
SearchAfter 文档
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html
好吧,我可以使用这个 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
}
}
我想为我的文档创建页面,每个页面应该有 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}"
}
如何提高分页结果/限制?
也欢迎任何其他方法,谢谢。
如错误所示,Elastic 将只显示 10000 行。
所以要显示更多的数字,您需要使用 scroll
函数
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
可以在此处找到带有滚动的 js 搜索示例。
基于 elasticsearch 文档https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html
Note that from + size can not be more than the index.max_result_window index setting which defaults to 10,000
作为替代,您可以尝试使用 scroll
或 searchAfter
。对于更实时的查询,searchAfter
更合适。
滚动文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
SearchAfter 文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html
好吧,我可以使用这个 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
}
}