ES维护篇-解决reason=Result window is too large, from + size must be less than or equal to: [500000] but was [786820].

首先搞清楚这个报错是什么意思

{"msg":"Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]; nested exception is ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Result window is too large, from + size must be less than or equal to: [500000] but was [786820]. 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.]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Result window is too large, from + size must be less than or equal to: [500000] but was [786820]. 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.]];","code":500}

 参数解释

max_result_window 是 Elasticsearch 中一个重要的搜索参数,它控制了单个搜索请求返回的最大结果数。具体来说,它定义了从搜索结果中的哪个位置开始返回结果,以及要返回多少个结果。

默认情况下,Elasticsearch 的 max_result_window 参数设置为 10000。这意味着,如果您执行一个搜索请求,请求的结果超过了 10000 条记录,那么只会返回前 10000 条记录,并且 Elasticsearch 会在响应中包含一个 hits.total 字段,该字段表示总共匹配了多少条记录。

如果您需要检索更多的结果,可以通过增加 from 和 size 参数来获取更多的结果,但是 from + size 不能超过 max_result_window 的值。如果您的搜索结果超过了 max_result_window 的值,那么 Elasticsearch 将会返回一个错误,提示您使用 scroll API 或者增加 max_result_window 的值来处理这个问题。

需要注意的是,将 max_result_window 参数设置得太大可能会影响 Elasticsearch 的性能。因此,建议在使用 max_result_window 参数时,根据实际情况和性能要求来选择合适的值。

如何使用api查询当前index.max_result_window 设置的最大限制

 要查询 Elasticsearch 群集上当前设置的 index.max_result_window 的最大限制,可以使用以下 API 请求:
GET /_cluster/settings?include_defaults=true

该请求将返回一个包含当前群集设置的 JSON 响应。如果 index.max_result_window 未显式设置,则将返回默认值。

要检查特定索引的 index.max_result_window 设置,请使用以下 API 请求:

GET /<index>/_settings?include_defaults=true

将 <index> 替换为您要查询的索引名称。此请求将返回包含该索引设置的 JSON 响应。如果 index.max_result_window 未显式设置,则将返回默认值。

请注意,如果使用默认设置,则 index.max_result_window 默认为10000。如果您需要更高的结果窗口大小,则必须显式设置此值。但是,需要注意的是,将此值设置得太高可能会影响 Elasticsearch 群集的性能,因此应该谨慎使用。

如何使用api修改index.max_result_window 设置的最大限制

您可以使用 Elasticsearch 的 API 来修改 index.max_result_window 的最大限制。下面是一些示例请求:

  1. 通过 PUT /<index>/_settings 修改单个索引的 index.max_result_window
PUT /<index>/_settings
{
  "index.max_result_window": 100000
}

将 <index> 替换为您要修改的索引名称,将 100000 替换为您想要设置的最大结果窗口大小。如上所述,需要谨慎使用较高的值,因为它可能会影响 Elasticsearch 群集的性能。

  1. 通过 PUT /_cluster/settings 修改整个集群的 index.max_result_window
PUT /_cluster/settings
{
  "persistent": {
    "index.max_result_window": 100000
  }
}

这将修改整个 Elasticsearch 集群上的 index.max_result_window 的最大限制。persistent 对象中的设置将被持久化,而 transient 对象中的设置将在集群重新启动后失效。

需要注意的是,修改 index.max_result_window 可能会对 Elasticsearch 群集的性能产生影响。如果您需要更高的结果窗口大小,建议先进行基准测试,并根据测试结果来选择合适的值。

 

posted @ 2023-05-12 09:19  不会跳舞的胖子  阅读(963)  评论(0编辑  收藏  举报