Elasticsearch-PHP 遇到的坑

mervyn 2018年9月11日14:03:07Elasticsearch PHPElasticsearch-PHP 遇到的坑已关闭评论245

目录

大数据量分页查询报错

问题详情

在用elasticsearch-php分页查询时,分页几次后报错,错误内容如下:文章源自编程技术分享-https://mervyn.life/98dabb75.html

{
    "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 [15000]. 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":"es_type",
                "node":"OVgyFsCDsfqwnvXz0nqA",
                "reason":{
                    "type":"query_phase_execution_exception",
                    "reason":"Result window is too large, from + size must be less than or equal to: [10000] but was [15000]. 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
}

解决方法

Elasticsearch 默认是有查询上限的, from + size 的值必须要小于等于 10000, 需要修改对应参数 max_result_window 的值。文章源自编程技术分享-https://mervyn.life/98dabb75.html

PUT http://127.0.0.1:9200/es_type/_settings -d '{ "index" : { "max_result_window" : 100000000}}'

curl 进行 PUT 或 POST 时报错

问题详情

{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}

解决方法

elasticsearch6.x 后需要在执行 curl 命令时加入 header 头文章源自编程技术分享-https://mervyn.life/98dabb75.html

curl -H "Content-Type: application/json"  -XPUT http://127.0.0.1:9200/es_type/_settings -d '
{
    "index" : { "max_result_window" : 100000000}
}'
文章源自编程技术分享-https://mervyn.life/98dabb75.html
weinxin
我的微信公众号
微信扫一扫
mervyn
PHP 将16进制字符转换成汉字 PHP

PHP 将16进制字符转换成汉字

项目代码提供给外部的api,有些参数是中文的。发现有些客户在请求接口的时候,参数的值被转成了16进制,从而导致接口无法正常解析。 此时可以采用如下方法进行转移: <?php $param = &...
PHPStorm 更改 PHP 版本号 Tools

PHPStorm 更改 PHP 版本号

PHPStorm 默认的 PHP 版本是 5.4, 当我们用服务器使用的是 PHP7 时,经常会出现语法错误的提示,这个时候需要将 PHPStorm 中的 PHP 版本进行修改才行。操作步骤如下: P...
从 mysql 用户的角度使用 Elasticsearch 数据库

从 mysql 用户的角度使用 Elasticsearch

本文主要讲述初次接触ES时,如何以使用MySQL的方式来应用 Elasticsearch 从而达到快速入门的目的。 以下例子均基于 Elasticsearch 6.0 例: order_test 表结...
CGI , FastCGI , PHP-CGI 与 PHP-FPM 对比 PHP

CGI , FastCGI , PHP-CGI 与 PHP-FPM 对比

CGI CGI全称是“公共网关接口” ( Common Gateway Interface ),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上。 CGI可以用...