Elasticsearch -from + size设置

探讨Elasticsearch在大数据环境下进行分页查询时遇到的限制,即size参数不能超过10000的问题,并介绍如何在集群环境中正确设置index.max_result_window参数以解决此问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Elasticsearch 查询索引结果时,用于分页的两个属性 from和size。用于查询时,默认from=0、size=0。而在生产环境时,查询的数据要大很多。有时是几百G,甚至P级。

在设置size时,超过10000。会出现报错。

Result window is too large, from + size must be less than or equal to:[10000] but was
[12000]. See the scroll api for a more efficient way to requestlarge data sets. This 
limit can be set by changing the[index.max_result_window] index level parameter

说是size 不能超过10000! 查阅资料,显示可以通过设置,改变:

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

经过测试,还是不可以。原因是我的Elasticsearch是集群环境(部署了三个master两个data节点)。上面的方式只能改变单节点的size。

我想要不就通过yaml文件,不是环境变量。重新部署吧。大胆猜想,然后实践。因为是kubernetes部署的elasticsearch集群。所以直接改他们的yaml文件,重新部署就行啦。

加上配置:

         - name: "index.max_result_window"
           value: "10000000"

然后部署:

  kubectl apply -f  es.yaml

但是查看状态的时候,出错。查看日志:

*******************************************************************************
Found index level settings on node level configuration.

Since elasticsearch 5.x index level settings can NOT be set on the nodes 
configuration like the elasticsearch.yaml, in system properties or command line 
arguments.In order to upgrade all indices the settings must be updated via the 
/${index}/_settings API. Unless all settings are dynamic all indices must be closed 
in order to apply the upgradeIndices created in the future should use index templates 
to set default values. 

Please ensure all required values are updated on all indices by executing: 

curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{
  "index.max_result_window" : "100000"
}'
*******************************************************************************

[2018-11-23T07:03:13,840][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [elasticsearch-master-0] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: node settings must not contain any index level settings
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-5.6.4.jar:5.6.4]

可以看到es 5.X以后,就不可以在yaml文件,系统属性,以及命令行参数设置索引级别的配置啦。

因此只能通过他给的提示:

curl -XPUT 'http://localhost:9200/_all/_settings?preserve_existing=true' -d '{
  "index.max_result_window" : "100000"
}'

设置size长度。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值