PHPackages                             royalcms/elasticsearch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. royalcms/elasticsearch

ActiveLibrary[Search &amp; Filtering](/categories/search)

royalcms/elasticsearch
======================

An easy way to use the official PHP ElasticSearch client in your Royalcms applications.

v7.1.0(5y ago)022MITPHPPHP ^7.2.5CI failing

Since Mar 13Pushed 5y agoCompare

[ Source](https://github.com/royalcms/royalcms-elasticsearch)[ Packagist](https://packagist.org/packages/royalcms/elasticsearch)[ Docs](https://github.com/royalcms/royalcms-elasticsearch)[ RSS](/packages/royalcms-elasticsearch/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (6)Versions (3)Used By (0)

Royalcms-Elasticsearch
======================

[](#royalcms-elasticsearch)

在Laravel或Royalcms应用程序中使用 [官方Elastic Search客户端](https://github.com/elastic/elasticsearch-php) 的简便方法。

- [Royalcms-Elasticsearch](#royalcms-elasticsearch)
    - [安装与配置](#installation-and-configuration)
        - [通过.env文件的替代配置方法](#alternative-configuration-method-via-env-file)
    - [用法](#usage)
    - [高级用法](#advanced-usage)
    - [Copyright and License](#copyright-and-license)

安装与配置
-----

[](#安装与配置)

通过composer安装最新版本的 `royalcms/royalcms-elasticsearch` 软件包：

```
composer require royalcms/royalcms-elasticsearch
```

##### 通过.env文件的替代配置方法

[](#通过env文件的替代配置方法)

按照上述建议发布配置文件后，可以配置ElasticSearch 通过将以下内容添加到应用程序的 `.env` 文件中（具有适当的值）：

```
ELASTICSEARCH_HOST=localhost
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_SCHEME=http
ELASTICSEARCH_USER=
ELASTICSEARCH_PASS=
```

用法
--

[](#用法)

`Elasticsearch` 外观只是 [ES客户端](https://github.com/elastic/elasticsearch-php) 的入口点，因此以前您可能使用过：

```
$data = [
    'body' => [
        'testField' => 'abc'
    ],
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
];

$client = ClientBuilder::create()->build();
$return = $client->index($data);
```

现在，您可以将后两行替换为：

```
$return = RC_Elasticsearch::index($data);
```

这将在默认连接上运行命令。 您可以在以下位置运行命令 任何连接（请参见 `defaultConnection` 设置和 `connections` 数组 配置文件）。

```
$return = RC_Elasticsearch::connection('connectionName')->index($data);
```

高级用法
----

[](#高级用法)

因为该软件包是官方Elastic客户端的包装，所以您可以 使用此程序包几乎可以做任何事情。 您不仅可以执行标准 CRUD操作，但您可以通过编程方式监视弹性集群的运行状况， 备份它，或对其进行更改。 其中一些操作是通过 此程序包愉快地支持的“命名空间”命令。

要获取索引的统计信息：

```
$stats = RC_Elasticsearch::indices()->stats(['index' => 'my_index']);
$stats = RC_Elasticsearch::nodes()->stats();
$stats = RC_Elasticsearch::cluster()->stats();
```

要创建和还原快照（请首先阅读有关创建存储库路径和插件的Elastic文档）：

```
$response = RC_Elasticsearch::snapshots()->create($params);
$response = RC_Elasticsearch::snapshots()->restore($params);
```

要删除整个索引（请注意！）：

```
$response = RC_Elasticsearch::indices()->delete(['index' => 'my_index']);
```

请记住，此软件包是许多非常复杂且有据可查的Elastic功能的薄包装。 有关这些功能以及用于调用它们的方法和参数的信息可以在 [Elastic文档](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html) 中找到。 可通过 [Elastic论坛](https://discuss.elastic.co/) 以及 [Stack Overflow](https://stackoverflow.com/questions/tagged/elasticsearch) 之类的网站获得有关使用它们的帮助。

Copyright and License
---------------------

[](#copyright-and-license)

[royalcms-elasticsearch](https://github.com/royalcms/royalcms-elasticsearch)was written by [Royal Wang](https://royalcms.cn) and is released under the [MIT License](LICENSE.md).

Copyright (c) 2020 Royal Wang

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~192 days

Total

2

Last Release

2064d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1106638?v=4)[Hao.Dongfang](/maintainers/royalwang)[@royalwang](https://github.com/royalwang)

---

Tags

clientsearchlaravelelasticsearchroyalcms

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/royalcms-elasticsearch/health.svg)

```
[![Health](https://phpackages.com/badges/royalcms-elasticsearch/health.svg)](https://phpackages.com/packages/royalcms-elasticsearch)
```

###  Alternatives

[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[gtk/larasearch

A driver based solution to searching your Eloquent models supports Laravel 5.2 and Elasticsearch engine.

133.9k](/packages/gtk-larasearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
