PHPackages                             eddie/elastic-search - 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. eddie/elastic-search

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

eddie/elastic-search
====================

137PHPCI failing

Since Jun 15Pushed 6y ago1 watchersCompare

[ Source](https://github.com/EddieLau0402/ElasticSearch)[ Packagist](https://packagist.org/packages/eddie/elastic-search)[ RSS](/packages/eddie-elastic-search/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

### 环境需求

[](#环境需求)

- PHP &gt;= 7.0

### 依赖

[](#依赖)

`"elasticsearch/elasticsearch": "^6.0"`

### 使用说明

[](#使用说明)

> 获取实例

```
$es = new \Eddie\ElasticSearch\Slim\Es([
    'hosts' => [
        'localhost:9200',
        /* others... */
    ],

    /* 指定 index, type 方式1 */
    //'index' => 'your_index',
    //'type' => 'doc'
]);
```

> 索引操作

```
/* 指定 index, type 方式2 */
$es
    ->setIndex('your_index')
    ->setType('doc')
;
/* 获取当前 index, type */
$es->getIndex();
$es->getType();

/* 创建索引 */
$ret = $es->createIndex('your_index');

/* 带参数创建索引 */
//ret = $es->createIndex('your_index', [
//    'settings' => [
//        'numbber_of_shards' => 1,
//        'number_of_replicas' => 1,
//    ]
//]);

/* 删除索引 */
$ret = $es->deleteIndex('your_index');

/* 索引是否存在 */
$ret = $es->existsIndex('your_index'); // true|false
```

> 文档操作

```
/* 创建文档 */
$ret = $es->createDocument([
    'id' => 'abc123',
    'key1' => 'val1',
    'key2' => 'val2',
]);

/* 获取文档 */
$ret = $es->getDocument('abc123');

/* 删除文档 */
$ret = $es->deleteDocument('abc123');
```

> 查询操作

```
$ret = $es
   /* 条件 "且" */
   ->where('key', 'val')
   ->where(['key' => 'val'])

   /* 条件 "或" */
   ->orWhere('key', 'val')
   ->orWhere(['key' => 'val'])

   /* 条件 "非" */
   ->whereNot('key', 'val')
   ->whereNot(['key' => 'val'])

   ->whereGt('key', 'val')               // 大于
   ->whereGte('key', 'val')              // 大于等于
   ->whereLt('key', 'val')               // 小于
   ->whereLte('key', 'val')              // 小于等于
   ->whereBetween('key', ['min', 'max']) // 指定范围
   /*
    * "或"条件 - 在 where 前加"or"; 如: "orWhereGt", "orWhereBetween"
    * "非"条件 - 在 where 后加"not"; 如: "whereNotGt", "whereNotBetween"
    */

   ->whereHas('key')     // 包含某字段
   ->orWhereHas('key')   // 包含某字段("或"条件)
   ->whereNotHas('key')  // 不包含某字段

   // 可以传入数组, 表示包含多字段;
   ->whereHas(['key1', 'key2', '...'])
   ->orWhereHas(['key1', 'key2', '...'])
   ->whereNotHas(['key1', 'key2', '...'])

   // 聚合查询
   // 方式一:
   //->aggregate([
   //    'aggs' => [
   //        'alias' => [
   //            'terms' => [
   //                'field' => 'your_aggregate_field',
   //                //'size' => 10
   //            ]
   //        ]
   //    ]
   //])
   // 方式二:
   ->aggregate(
       (new Aggregation())
           ->setTerms('your_aggregate_field')
           // 最大值
           ->addSubAgg((new Aggregation())->setMax('field', 'alias'), ['size' => 10])
           // 最大值
           ->addSubAgg((new Aggregation())->setMin('field', 'alias'))
           // 平均值
           ->addSubAgg((new Aggregation())->setAvg('field'))
   )

   ->limit(10) // 获取记录条目数, 相当于"size"
   ->skip(0)   // 偏移量, 相当于"from"

   // 执行查询
   ->get()
   //->get(['key1', 'key2']) // 返回部分字段
;

//$es->flush(); // 清空查询条件
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/63401b098899655553af696e7eb941823b39a31dfc239f39e967f006e4061252?d=identicon)[EddieLau0402](/maintainers/EddieLau0402)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/eddie-elastic-search/health.svg)

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15024.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

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

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

175.9M9](/packages/shyim-opensearch-php-dsl)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)

PHPackages © 2026

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