Download the PHP package sllhsmile/hyperf-elasticsearch without Composer

On this page you can find all versions of the php package sllhsmile/hyperf-elasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package hyperf-elasticsearch

Sllhsmile Hyperf Elasticsearch

面向 Hyperf 3.x 的 Elasticsearch 7/8/9 ORM 风格客户端。它在官方 PHP Client 之上提供 Document Model、链式 Query Builder、多连接、Bulk、索引与 Alias 管理、PIT 深分页,以及适配 Hyperf 协程环境的 HTTP 客户端。

业务代码可以通过 Model 和 QueryBuilder 完成常见的文档读写与搜索;复杂场景仍可直接传递 Elasticsearch DSL 或调用底层 endpoint。

这个包不是 Eloquent,不提供关系、事务,也不负责 MySQL 到 Elasticsearch 的自动同步。如果项目只需要少量原生 DSL,直接使用官方客户端可能更简单。

目录

兼容性

请使用相互匹配的 Hyperf、hyperf/elasticsearch、官方 PHP Client 和 Elasticsearch Server:

Hyperf hyperf/elasticsearch elasticsearch/elasticsearch Elasticsearch Server
3.0.x 3.0.x 7.17.x 7.17.x
3.1.x 3.1.x 7.17.x 7.17.x
3.2.x 3.2.x 8.x 8.x
3.2.x 3.2.x 9.x 9.x

当前版本要求 PHP >=8.1。同一个运行实例只能安装一个官方客户端主版本,建议显式指定目标版本,不要让 Composer 猜测 Elasticsearch Server 的版本。

安装

根据 Elasticsearch Server 主版本选择一条命令。

ES 7.17:

ES 8:

ES 9:

包会通过 Hyperf ConfigProvider 自动注册依赖。发布配置文件:

配置将写入 config/autoload/elasticsearch.php。

配置连接

连接启用了 API Key 时,在 .env 中配置:

本地无认证节点只需要:

也可以通过 ELASTICSEARCH_USERNAME 和 ELASTICSEARCH_PASSWORD 使用 Basic Auth。API Key 与 Basic Auth 不能同时配置;API Key 应填写 Elasticsearch 创建 API Key 时返回的 base64 encoded 值。

不要把密钥写入 PHP 文件、提交到 Git 或打印到日志。生产环境应保持 TLS 校验开启;使用私有 CA 时可将 verify_tls 配置为证书文件路径。

五分钟快速开始

1. 定义模型

创建 app/Model/Article.php:

2. 建立索引、写入并查询

下面的服务可直接由 Hyperf 容器实例化。示例会创建索引以形成完整闭环;生产项目应把索引初始化放在部署脚本或独立命令中。

首次执行会返回一条包含 article-1 的搜索结果。示例中的 refresh => wait_for 用于确保写入后立即可搜索;高吞吐写入场景不应为每条文档强制刷新。

常用操作

文档生命周期

create()、save() 和 update() 返回 hydrate 后的模型。exists() 表示模型是否已写入或从 Elasticsearch 命中,getKey() 返回文档 _id。

链式查询

原始 DSL

需要在链式 DSL 上追加不冲突的顶层字段时使用 rawDsl();需要完全控制请求体时使用 replaceDsl()。

功能导航

场景 主要入口 详细文档
多连接与客户端缓存 Manager::connection() / purge() 连接管理
Document Model DocumentModel 模型与 CRUD
Query Builder where、whereMatch、whereNested 查询条件
排序、高亮与聚合 orderBy、highlight、aggs 查询选项
深分页 searchAfter、PitManager PIT
批量写入 BulkManager、BulkOperation Bulk
索引与 Alias IndexManager 索引管理
响应与异常 SearchResponse、包内异常 响应处理
未封装 endpoint ClientInterface::call() Raw request

完整配置、所有公开方法和版本差异请查看 USAGE.md。

Hyperf 与连接行为

配置支持 hosts、API Key、Basic Auth、timeout、connect_timeout、retries、verify_tls、headers 和 client_options。字段结构和多连接示例见 安装与配置。

常见问题

Composer 报依赖冲突

先检查兼容性表中的四个版本是否属于同一组合。Hyperf 3.0/3.1 使用 Client 7.17;Hyperf 3.2 使用 Client 8 或 9。不要在同一个项目中约束多个官方客户端主版本。

写入成功但立即搜索不到

Elasticsearch 默认是近实时搜索。测试或必须立即搜索的场景可以为写入传递 refresh => wait_for;生产批量写入应遵循正常 refresh 周期。

HTTPS 证书校验失败

生产环境不要关闭证书验证。使用私有 CA 时,将 verify_tls 设置为 CA 文件路径;false 只适合受控的本地测试环境。

模型提示没有可用客户端

在 Hyperf 应用内确认包的 ConfigProvider 已加载。脱离 Hyperf 容器进行单元测试时,可以通过 Article::setClient($client) 设置测试客户端。

从旧包名迁移

如果项目仍依赖 sllhsmile/elasticsearch,先移除旧包,再按目标 ES 版本安装新包:

PHP 命名空间仍为 SllhSmile\Elasticsearch\,现有 use 引用无需修改。

开发与反馈

发现缺陷或需要新功能,请通过 GitHub Issues 提交可复现示例,并注明 Hyperf、官方 PHP Client 和 Elasticsearch Server 版本。

License

MIT


All versions of hyperf-elasticsearch with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
elasticsearch/elasticsearch Version ^8.0 || ^9.0
hyperf/collection Version ^3.0
hyperf/config Version ^3.0
hyperf/context Version ^3.0
hyperf/guzzle Version ^3.0
psr/container Version ^1.0 || ^2.0
psr/log Version ^1.1 || ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sllhsmile/hyperf-elasticsearch contains the following files

Loading the files please wait ...