PHPackages                             liuwave/think-elastic - 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. liuwave/think-elastic

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

liuwave/think-elastic
=====================

ThinkPHP Elasticsearch 扩展

2.0(6y ago)07MITPHPPHP &gt;=7.4.0

Since Sep 11Pushed 6y agoCompare

[ Source](https://github.com/liuwave/think-elastic)[ Packagist](https://packagist.org/packages/liuwave/think-elastic)[ RSS](/packages/liuwave-think-elastic/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (3)Versions (8)Used By (0)

Think Elastic
=============

[](#think-elastic)

ThinkPHP Elasticsearch 扩展 ,fork于 [kainonly/think-elastic](https://github.com/kainonly/think-elastic)，做了些更改：

1. 增加门面函数
2. 将database中的配置分离到config/elasticsearch.php

[![Packagist Version](https://camo.githubusercontent.com/a68fa30b768924cea67a1106c092afd5961040e7378bc630293044315e392220/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6975776176652f7468696e6b2d656c61737469632e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/a68fa30b768924cea67a1106c092afd5961040e7378bc630293044315e392220/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6975776176652f7468696e6b2d656c61737469632e7376673f7374796c653d666c61742d737175617265)[![Packagist](https://camo.githubusercontent.com/7b3fd626c2a4d0ae58d700d963a430365c6abe47dc98b6cb349cc874f3611dc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6975776176652f7468696e6b2d656c61737469632e7376673f636f6c6f723d626c7565267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/7b3fd626c2a4d0ae58d700d963a430365c6abe47dc98b6cb349cc874f3611dc4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6975776176652f7468696e6b2d656c61737469632e7376673f636f6c6f723d626c7565267374796c653d666c61742d737175617265)[![PHP from Packagist](https://camo.githubusercontent.com/88dc09f5f9403bac62a5af2bde62db2ea892444373d979f863d7c3a59f9d543f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6975776176652f7468696e6b2d656c61737469632e7376673f636f6c6f723d626c7565267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/88dc09f5f9403bac62a5af2bde62db2ea892444373d979f863d7c3a59f9d543f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6975776176652f7468696e6b2d656c61737469632e7376673f636f6c6f723d626c7565267374796c653d666c61742d737175617265)[![Packagist](https://camo.githubusercontent.com/f7c1929ccb9a9db15da48c83062e0ccaab589f335ebb0220f290a7d10ffa83a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6975776176652f7468696e6b2d656c61737469632e7376673f636f6c6f723d626c7565267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f7c1929ccb9a9db15da48c83062e0ccaab589f335ebb0220f290a7d10ffa83a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6975776176652f7468696e6b2d656c61737469632e7376673f636f6c6f723d626c7565267374796c653d666c61742d737175617265)

#### 安装

[](#安装)

```
composer require liuwave/think-elastic
```

安装后服务将自动注册，新建配置文件config/elasticsearch.php

```
use think\facade\Env;
return [
  'default' => [
      // 集群连接
    'hosts' => explode(',', Env::get('elasticsearch.hosts', 'localhost:9200')),
      // 重试次数
    'retries' => 0,
      // 公共CA证书
    'SSLVerification' => null,
      // 开启日志
    'logger' => null,
      // 配置 HTTP Handler
    'handler' => null,
      // 设置连接池
    'connectionPool' => Elasticsearch\ConnectionPool\StaticNoPingConnectionPool::class,
      // 设置选择器
    'selector' => Elasticsearch\ConnectionPool\Selectors\RoundRobinSelector::class,
      // 设置序列化器
    'serializer' => Elasticsearch\Serializers\SmartSerializer::class
  ]
];
```

- **hosts** `array` 集群连接
- **retries** `int` 重试次数
- **SSLVerification** `string` 公共CA证书
- **logger** `LoggerInterface` 开启日志
- **handler** `mixed` 配置 HTTP Handler
- **connectionPool** `AbstractConnectionPool|string` 设置连接池
- **selector** `SelectorInterface|string` 设置选择器
- **serializer** `SerializerInterface|string` 设置序列化器

#### client(string $label = 'default')

[](#clientstring-label--default)

- **label** `string` 配置label
- **Return** `Elasticsearch\Client`

写入文档

```
use think\elastic\facade\Elastic;

$response = Elastic::client()->index([
    'index' => 'test',
    'id' => 'test',
    'body' => [
        'value' => 1
    ]
]);

// ^ array:8 [▼
//   "_index" => "test"
//   "_type" => "_doc"
//   "_id" => "test"
//   "_version" => 1
//   "result" => "created"
//   "_shards" => array:3 [▼
//     "total" => 2
//     "successful" => 1
//     "failed" => 0
//   ]
//   "_seq_no" => 0
//   "_primary_term" => 1
// ]
```

获取文档

```
use think\elastic\facade\Elastic;

$response = Elastic::client()->get([
    'index' => 'test',
    'id' => 'test'
]);

// ^ array:8 [▼
//   "_index" => "test"
//   "_type" => "_doc"
//   "_id" => "test"
//   "_version" => 1
//   "_seq_no" => 0
//   "_primary_term" => 1
//   "found" => true
//   "_source" => array:1 [▼
//     "value" => 1
//   ]
// ]
```

搜索文档

```
use think\elastic\facade\Elastic;

$response = Elastic::client()->search([
    'index' => 'test',
    'body' => [
        'query' => [
            'match' => [
                'value' => 1
            ]
        ]
    ]
]);

// ^ array:4 [▼
//   "took" => 4
//   "timed_out" => false
//   "_shards" => array:4 [▼
//     "total" => 1
//     "successful" => 1
//     "skipped" => 0
//     "failed" => 0
//   ]
//   "hits" => array:3 [▼
//     "total" => array:2 [▼
//       "value" => 1
//       "relation" => "eq"
//     ]
//     "max_score" => 1.0
//     "hits" => array:1 [▼
//       0 => array:5 [▼
//         "_index" => "test"
//         "_type" => "_doc"
//         "_id" => "test"
//         "_score" => 1.0
//         "_source" => array:1 [▼
//           "value" => 1
//         ]
//       ]
//     ]
//   ]
// ]
```

删除文档

```
use think\elastic\facade\Elastic;

$response = Elastic::client()->delete([
    'index' => 'test',
    'id' => 'test'
]);

// ^ array:8 [▼
//   "_index" => "test"
//   "_type" => "_doc"
//   "_id" => "test"
//   "_version" => 2
//   "result" => "deleted"
//   "_shards" => array:3 [▼
//     "total" => 2
//     "successful" => 1
//     "failed" => 0
//   ]
//   "_seq_no" => 1
//   "_primary_term" => 1
// ]
```

删除索引

```
use think\elastic\facade\Elastic;

$response = Elastic::client()->indices()->delete([
    'index' => 'test',
]);

// ^ array:1 [▼
//   "acknowledged" => true
// ]
```

创建索引

```
use think\elastic\facade\Elastic;

$response = Elastic::client()->indices()->create([
    'index' => 'test'
]);

// ^ array:3 [▼
//   "acknowledged" => true
//   "shards_acknowledged" => true
//   "index" => "test"
// ]
```

> `think-elastic` 使用了 [elasticsearch/elasticsearch](https://packagist.org/packages/elasticsearch/elasticsearch) ，更多方法可查看 [Elasticsearch-PHP](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html) 完整文档

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity63

Established project with proven stability

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

Recently: every ~42 days

Total

7

Last Release

2271d ago

Major Versions

1.5 → 2.02020-02-27

PHP version history (2 changes)1.3PHP &gt;=7.2.0

1.5PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea0000cba67ced68f357012faa62e87dacfcf16716cf1a0bef43958da234ebb5?d=identicon)[liuwave](/maintainers/liuwave)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/liuwave-think-elastic/health.svg)

```
[![Health](https://phpackages.com/badges/liuwave-think-elastic/health.svg)](https://phpackages.com/packages/liuwave-think-elastic)
```

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[mailerlite/laravel-elasticsearch

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

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[ongr/elasticsearch-dsl

Elasticsearch DSL library

46411.9M45](/packages/ongr-elasticsearch-dsl)[matchish/laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout

7431.6M2](/packages/matchish-laravel-scout-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[ongr/elasticsearch-bundle

Elasticsearch bundle for Symfony.

3151.1M15](/packages/ongr-elasticsearch-bundle)

PHPackages © 2026

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