【问题标题】:Elasticsearch Pagination From - Size Result window is too largeElasticsearch Pagination From - Size Result window is too large
【发布时间】:2018-09-16 10:36:39
【问题描述】:

我想为我的文档创建页面,每个页面应该有 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}"
}

如何增加分页结果/限制?

也欢迎任何其他方法,谢谢。

【问题讨论】:

    标签: node.js elasticsearch elasticsearch-plugin elasticsearch-5


    【解决方案1】:

    如错误所示,Elastic 将仅显示 10000 行。

    所以要显示更多的数字,您需要使用scroll 函数

    https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html

    可以在此处找到使用滚动的 js 搜索示例。

    async await with elasticsearch search/scroll

    【讨论】:

      【解决方案2】:

      基于elasticsearch文档https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

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

      您也可以尝试使用scrollsearchAfter。更实时的查询,searchAfter更合适。

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

      搜索后文档 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html

      【讨论】:

        【解决方案3】:

        好吧,我可以使用这个 CURL 增加分页限制

        curl -XPUT "http://localhost:9200/my_index/_settings" -d '{ "index" : { "max_result_window" : 500000 } }'
        

        【讨论】:

          【解决方案4】:

          如下增加max_result_window,就可以了

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

          【讨论】:

            猜你喜欢
            • 2021-08-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2017-09-05
            • 1970-01-01
            • 2021-02-04
            • 2017-04-05
            • 1970-01-01
            相关资源
            最近更新 更多