elasticsearch-php 使用详细教程
先看官方教程地址如下
快速开始 | Elasticsearch-PHP | Elastic
在 composer.json 文件中引入 elasticsearch-php:官方的"~6.0"会报错,改成7就可以
{ "require": { "elasticsearch/elasticsearch": "~7.0" }}
用 composer 安装客户端:
curl -s http://getcomposer.org/installer | phpphp composer.phar install --no-dev
注意PHP版本必须选择7.4版本以上,不然报以下错误
D:\phpStudy\PHPTutorial\WWW\mqtt\fastadmin\es>curl -s http://getcomposer.org/installer | phpDownloading...Composer (version 2.5.1) successfully installed to: D:\phpStudy\PHPTutorial\WWW\mqtt\fastadmin\es\composer.pharUse it: php composer.pharSome settings on your machine may cause stability issues with Composer.If you encounter issues, try to change the following:The Windows OneDrive folder is not supported on PHP versions below 7.2.23 and 7.3.10.Upgrade your PHP (7.3.4) to use this location with Composer.
Some settings on your machine may cause stability issues with Composer.If you encounter issues, try to change the following:The Windows OneDrive folder is not supported on PHP versions below 7.2.23 and 7.3.10.Upgrade your PHP (7.2.1) to use this location with Composer.
超时错误要加入Packagist 镜像使用方法
将镜像换成腾讯云
composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/
将镜像换成阿里云
composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
修改当前项目的 composer.json 配置文件,打开命令行窗口(windows用户)或控制台(Linux、Mac 用户),进入你的项目的根目录(也就是 composer.json 文件所在目录),执行如下命令:
composer config repo.packagist composer https://packagist.phpcomposer.com
各种报错处理方法
要忽略 输入:composer install --ignore-platform-reqs
D:\phpStudy\PHPTutorial\WWW\mqtt\fastadmin\es>composer install --ignore-platform-reqsNo composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.Loading composer repositories with package informationUpdating dependenciesYour requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires elasticsearch/elasticsearch, it could not be found in any version, there may be a typo in the package name.Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see for more details. - It's a private package and you forgot to add a custom repository to find itRead for further common problems.D:\phpStudy\PHPTutorial\WWW\mqtt\fastadmin\es>php composer.phar install --no-devNo composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.Loading composer repositories with package informationUpdating dependenciesYour requirements could not be resolved to an installable set of packages. Problem 1 - Root composer.json requires elasticsearch/elasticsearch, it could not be found in any version, there may be a typo in the package name.Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see for more details. - It's a private package and you forgot to add a custom repository to find itRead for further common problems.Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.D:\phpStudy\PHPTutorial\WWW\mqtt\fastadmin\es>composer update --ignore-platform-reqs
最后下载成功
composer require elasticsearch/elasticsearch="^7.0"
D:\phpStudy\PHPTutorial\WWW\mqtt\fastadmin\es>composer require elasticsearch/elasticsearch="^7.0"./composer.json has been updatedRunning composer update elasticsearch/elasticsearchLoading composer repositories with package informationUpdating dependenciesLock file operations: 5 installs, 0 updates, 0 removals - Locking elasticsearch/elasticsearch (v7.17.1) - Locking ezimuel/guzzlestreams (3.0.1) - Locking ezimuel/ringphp (1.2.2) - Locking psr/log (1.1.4) - Locking react/promise (v2.9.0)Writing lock fileInstalling dependencies from lock file (including require-dev)Package operations: 5 installs, 0 updates, 0 removals - Downloading psr/log (1.1.4) - Downloading react/promise (v2.9.0) - Downloading ezimuel/guzzlestreams (3.0.1) - Downloading ezimuel/ringphp (1.2.2) - Downloading elasticsearch/elasticsearch (v7.17.1) - Installing psr/log (1.1.4): Extracting archive - Installing react/promise (v2.9.0): Extracting archive - Installing ezimuel/guzzlestreams (3.0.1): Extracting archive - Installing ezimuel/ringphp (1.2.2): Extracting archive - Installing elasticsearch/elasticsearch (v7.17.1): Extracting archive1 package suggestions were added by new dependencies, use `composer suggest` to see details.Generating autoload files1 package you are using is looking for funding.Use the `composer fund` command to find out more!Failed to audit installed packages.
报如下错误 解决办法:将type修改为_doc,默认的数据类型
Fatal error: Uncaught Elasticsearch\Common\Exceptions\BadRequest400Exception: {"error":"no handler found for uri [/my_index/my_type/my_id] and method [POST]"} in D:\phpstudy_pro\WWW\mqtt\fastadmin\es\vendor\elasticsearch\elasticsearch\class="lazy" data-src\Elasticsearch\Connections\Connection.php on line 693
$params = [ 'index' => 'test', 'type' => '_doc', 'id' => '5' // http://192.168.2.109:9200/test/_doc/5];
错误 解决access_control_exception:因为 ES 的安装路径中存在空格,修改路径即可
Fatal error: Uncaught Elasticsearch\Common\Exceptions\ServerErrorResponseException: {"error":{"root_cause":[{"type":"access_control_exception","reason":"access denied (\"java.io.FilePermission\" \"D:\\Program%20Files%20(x86)\\elasticsearch-8.6.1\\plugins\\ik\\config\\IKAnalyzer.cfg.xml\" \"read\")"}],"type":"access_control_exception","reason":"access denied (\"java.io.FilePermission\" \"D:\\Program%20Files%20(x86)\\elasticsearch-8.6.1\\plugins\\ik\\config\\IKAnalyzer.cfg.xml\" \"read\")"},"status":500} in D:\phpstudy_pro\WWW\mqtt\fastadmin\es\vendor\elasticsearch\elasticsearch\class="lazy" data-src\Elasticsearch\Connections\Connection.php on line 726
来源地址:https://blog.csdn.net/sinat_36001828/article/details/128813355
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341