我想为我的文档提供页面,每页应该有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}"
}
如何增加分页结果/限制?
欢迎任何其他方法,谢谢。
答案 0 :(得分:2)
基于elasticsearch文档https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html
请注意,from + size不能超过index.max_result_window 索引设置,默认为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
答案 1 :(得分:1)
由于错误显示Elastic只显示10000行。
因此要显示超过该数字,您需要使用scroll
功能
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html
可以在此处找到带滚动的js搜索示例。
答案 2 :(得分:1)
好吧,我可以使用此CURL增加分页限制
// GET: api/currencies
[HttpGet]
[ResponseCache(Duration = 60)]
public async Task<IEnumerable<GetCurrencyResponse>> Get()
{
var currencies = await _currencyService.GetCurrenciesAsync();
return currencies;
}
答案 3 :(得分:0)
按如下所示增加max_result_window
,就可以了
PUT indexName/_settings
{
"index": {
"max_result_window": 10000000
}
}