PHPackages                             rayful/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. [API Development](/categories/api)
4. /
5. rayful/elasticsearch

ActiveLibrary[API Development](/categories/api)

rayful/elasticsearch
====================

elasticsearch client for php

v0.0.3(8y ago)011MITPHPPHP &gt;=5.4.0

Since Sep 20Pushed 8y ago2 watchersCompare

[ Source](https://github.com/rayful/elasticsearch)[ Packagist](https://packagist.org/packages/rayful/elasticsearch)[ RSS](/packages/rayful-elasticsearch/feed)WikiDiscussions master Synced 4d ago

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

elasticsearch
=============

[](#elasticsearch)

使用 PHP 对 Elasticsearch 做索引管理，以及索引新文档

安装
--

[](#安装)

```
$ composer install

```

添加 mapping
----------

[](#添加-mapping)

```
use Rayful\Elasticsearch\Builder;
use Rayful\Elasticsearch\Writer;

$connectionParams = '127.0.0.1:9200';
$builder = new Builder($connectionParams);
$writer = new Writer($builder);

$db = 'test';
$collection = 'user';

$properties = [
    'name' => a['type' => 'string'],
    'age' => ['type' => 'integer'],
    'balance' => ['type' => 'double'],
    'create_at' => ['type' => 'date']
];

// 更多 mapping type 见官方文档: https://www.elastic.co/guide/en/elasticsearch/reference/2.3/mapping-types.html

$writer->setNamespace($db, $collection)->putMapping($properties);
```

索引单个文档
------

[](#索引单个文档)

```
use Rayful\Elasticsearch\Builder;
use Rayful\Elasticsearch\Writer;

$connectionParams = '127.0.0.1:9200';
$builder = new Builder($connectionParams);
$writer = new Writer($builder);

$db = 'test';
$collection = 'user';

$properties = [
    'name' => ['type' => 'string'],
    'age' => ['type' => 'integer'],
    'balance' => ['type' => 'double'],
    'create_at' => ['type' => 'date']
];

$document = [
    'id'=> '59c1cfb9a008b',
    'name' => 'lvinkim-'.rand(1,1000),
    'age' => rand(10,90),
    'balance' => rand(0,1000),
    'create_at' => time()
];

$writer->setNamespace($db, $collection);

// 手动指定 mapping 字段的类型，如果不手动指定，将由 Elasticsearch 自动生成
$writer->putMapping($properties);

$response = $writer->indexSingleDocument($document);

print_r($response);
```

索引批量文档
------

[](#索引批量文档)

```
use Rayful\Elasticsearch\Builder;
use Rayful\Elasticsearch\Writer;

$connectionParams = '127.0.0.1:9200';
$builder = new Builder($connectionParams);
$writer = new Writer($builder);

$db = 'test';
$collection = 'user';

$properties = [
    'name' => ['type' => 'string'],
    'age' => ['type' => 'integer'],
    'balance' => ['type' => 'double'],
    'create_at' => ['type' => 'date']
];

$documents = genDocuments();

$writer->setNamespace($db, $collection);

// 手动指定 mapping 字段的类型，如果不手动指定，将由 Elasticsearch 自动生成
$writer->putMapping($properties);

$writer->indexMultiDocuments($documents);

function genDocuments()
{
    for ($i = 0; $i < 10000; $i++) {
        $document = [
            'id' => $i . '-' . uniqid(),
            'name' => 'lvinkim-' . rand(1, 1000),
            'age' => rand(10, 90),
            'balance' => rand(0, 1000),
            'create_at' => time()
        ];
        yield $document;
    }
}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~54 days

Total

2

Last Release

3106d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1412a217896637f39725a032a9fc9c77c8feeb843daa3b5b696b8eb0fef53a94?d=identicon)[kingmaxyang](/maintainers/kingmaxyang)

---

Top Contributors

[![xiyanghui](https://avatars.githubusercontent.com/u/32087026?v=4)](https://github.com/xiyanghui "xiyanghui (9 commits)")

### Embed Badge

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

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

###  Alternatives

[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[googleads/googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP

67410.3M25](/packages/googleads-googleads-php-lib)[googleads/google-ads-php

Google Ads API client for PHP

3497.6M9](/packages/googleads-google-ads-php)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k379.4k24](/packages/team-reflex-discord-php)[checkout/checkout-sdk-php

Checkout.com SDK for PHP

553.3M7](/packages/checkout-checkout-sdk-php)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)

PHPackages © 2026

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