PHPackages                             chenyuanqi/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. chenyuanqi/elasticsearch

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

chenyuanqi/elasticsearch
========================

elasticsearch laravel service

v1.0.0(9y ago)3382MITPHPPHP &gt;=7.0

Since May 9Pushed 8y ago1 watchersCompare

[ Source](https://github.com/chenyuanqi/elasticsearch)[ Packagist](https://packagist.org/packages/chenyuanqi/elasticsearch)[ RSS](/packages/chenyuanqi-elasticsearch/feed)WikiDiscussions master Synced 2mo ago

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

chenyuanqi/elasticsearch not only for laravel5
==============================================

[](#chenyuanqielasticsearch-not-only-for-laravel5)

This package depends on "elasticsearch/elasticsearch" and it provides a unified API across a variety of different full text search services.

> Notice: Test for elasticsearch 2.x, even than 5.x; whatever, some function cannot take effect for the low one.

The following dependencies are needed for the listed search drivers:

```
{
"php": ">=7.0",
"illuminate/support": "~5.1",
"elasticsearch/elasticsearch": "~5.0"
}
```

Structure
---------

[](#structure)

├── Commands
│ └── ElasticsearchService.php
├── config
│ └── elasticsearch.php
├── Analyze.php
├── Builder.php
├── Query.php
├── SearchFacade.php
└── SearchServiceProvider.php

Suggestion
----------

[](#suggestion)

For safety reasons, please install the plugin: [shield](https://www.elastic.co/downloads/shield "shield")
For search effectively, these plugins may be useful for you:
1、[head](https://github.com/mobz/elasticsearch-head)
2、[bigdesk](https://github.com/hlstudio/bigdesk)
3、[kopt](https://github.com/lmenezes/elasticsearch-kopf)
4、[sql](https://github.com/NLPchina/elasticsearch-sql)
5、[ik](https://github.com/medcl/elasticsearch-analysis-ik)
6、[pinyin](https://github.com/gitchennan/elasticsearch-analysis-lc-pinyin)
7、[同义词](https://github.com/bells/elasticsearch-analysis-dynamic-synonym)
8、[简繁转换](https://github.com/medcl/elasticsearch-analysis-stconvert)

Install
-------

[](#install)

You can edit composer.json file, in the require object:

```
{
"chenyuanqi/elasticsearch": "dev-master"
}
```

Or use composer command:

```
composer require chenyuanqi/elasticsearch
```

After that, run composer update to install this package.
Actually, it was finished but in ***laravel5*** that you still let the service provider to app/config/app.php, within the providers array.

```
'providers' => [
	// elasticsearch service
	chenyuanqi\elasticsearch\SearchServiceProvider::class,
],
```

Add a class alias to app/config/app.php, within the aliases array.

```
'aliases' => [
	// elasticsearch service facade
	'Search' => chenyuanqi\elasticsearch\SearchFacade::class,
],
```

Configure
---------

[](#configure)

In ***laravel5***, publish the default config file to your application then make modifications as you can.

```
php artisan vendor:publish
```

However, default config file is *config/elasticsearch.php*.

Laravel Usage
-------------

[](#laravel-usage)

### 1、search for create index

[](#1search-for-create-index)

```
Search::createIndex();
```

Notice: Index name must be lowercase.

### 2、search for mapping due to config

[](#2search-for-mapping-due-to-config)

```
Search::createMapping();
Search::updateMapping();
Search::deleteMapping();
```

### 3、search for select index and type

[](#3search-for-select-index-and-type)

```
Search::index('test')->type('test');
```

Notice: Here index and type has default value.

### 4、search for insert data

[](#4search-for-insert-data)

```
$data = [
    'name'  => 'Kyyomi',
    'age'   => 18,
    'birth' => '2017-03-03'
];
// However, you can set id for the record. For instance, "Search::insert($data, 1);"
Search::insert($data);
```

### 5、search for update data

[](#5search-for-update-data)

Here provide two way for update data,

```
$data = [
    'birth' => '1999-03-03'
];
// update by id
Search::updateById($data, 1);
// update by query
Search::queryString('name:"Kyyomi"')->update($data);
```

By the way, use update by query must open the script setting

```
# In elasticsearch 2.3.3, allow script operate
  script.inline: true
  script.indexed: true
  script.file: true
  script.engine.groovy.inline.update: true
  script.engine.groovy.inline.aggs: true
```

### 6、search for increase or decrease data

[](#6search-for-increase-or-decrease-data)

```
Search::queryString('name:"海盗之王"')->increase('age');
Search::queryString('name:"海盗之王"')->increase('age', 2);
Search::queryString('name:"海盗之王"')->decrease('age', 3);
```

Like update by query, increase or decrease also open the script setting

### 7、search for delete data

[](#7search-for-delete-data)

Here provide two way for delete data,

```
$data = [
    'birth' => '1999-03-03'
];
// delete by id
Search::deleteById(1);
// delete by query, not support for version >2.0 (consider plugin: delete-by-query)
Search::queryString('name:"Kyyomi"')->delete();
```

### 8、search for clean index

[](#8search-for-clean-index)

```
Search::truncate();
```

### 9、search for bulk

[](#9search-for-bulk)

```
$data = [
    [
        'index',
        '_id'  => 1,
        'name' => 'viki',
        'age'  => 18
    ],
    [
        'create',
        '_id'  => 2,
        'name' => 'lucy',
        'age'  => 15
    ],
    [
        'update',
        '_id'  => 1,
        'name' => 'vikey',
        'age'  => 28
    ],
    [
        'delete',
        '_id' => 2
    ]
]
Search::bulk($data);
```

Notice: Default handle is 'index'.

### 10、everything is for search

[](#10everything-is-for-search)

You can select fields show for search.

```
Search::pluck(['name', 'age'])->search();
```

Default paging is true and show the result first ten, If you don't need it

```
Search::pluck(['name', 'age'])->search(false);
```

Construct the conditions with queryString, just like that

```
Search::queryString('name=Kyyomi');
```

Or the conditions with filter

```
Search::filter('status', 'show');
```

Or the conditions with ids

```
Search::ids([1, 2, 3]);
// If other field with in or not in function
Search::whereIn('name', ['A', 'B', 'C']);
Search::whereNotIn('name', ['A', 'B', 'C']);
```

Or the conditions with match

```
Search::match('name', 'Kyyomi', 'match');
Search::match(['name', 'age'], 'Kyyomi', 'multi_match');
Search::match('Kyyomi');
```

Or the conditions with term

```
Search::term('name', 'Kyyomi');
```

Or the conditions with bool

```
// The third parameter include must(default value), must_not, should, filter.
Search::bool('name', 'Kyyomi', 'must_not');
```

Or the conditions with null

```
Search::isNull('name');
// If need the field is not null
Search::isNotNull('name');
```

Or the conditions with aggregation

```
Search::max('id');
Search::min('id');
Search::sum('id');
Search::avg('id');
```

Or the conditions with range

```
Search::range('age', [7, 18], ['gt', 'lte']);
```

However, the range query has fourth parameter which use as extra action.
Or the conditions with where query

```
Search::where('id', '=', 100)->search();
// The same as last sentence
Search::where('id', 100)->search();
Search::where('id', '=', 100)->orWhere('age', '>=', 18)->search();
// Also, we can use like query
Search::where('name', 'like', '%天天%')->search();
// any more where function like whereBetween, whereNotBetween
Search::whereBetween('id', [1, 2]);
```

Here are two ways When we need paging.

```
// paging style
Search::queryString('name:"珍珠海盗"')->limit(0, 10)->search();
// scroll style
Search::queryString('name:"珍珠海盗"')->scroll(1000, '30s', 'scan')->search();
// If you want use scroll id for search or delete it
Search::searchByScrollId('xxx');
Search::deleteByScrollId('xxx');
```

And count the record, just use the count function.

```
Search::queryString('name:"珍珠海盗"')->count();
```

At last, use the debug function that output the debug message as you need.

```
Search::queryString('name:"珍珠海盗"')->search();
Search::debug();
// If you need curl sentence, do it
Search::toCurl();
```

Notice: you must output the message after search.

Others Usage
------------

[](#others-usage)

You know, it uses the facade design pattern above all of [laravel usage](https://github.com/chenyuanqi/elasticsearch#laravel-usage).
So in here, just replace the Search object like that:

```
use chenyuanqi\elasticsearch\Builder;
$search = new Builder(false);
```

All right, Happy hacking~

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

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

Total

3

Last Release

3220d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.0

v0.0.2PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/338a1c37843b8b16dcb531bf954c54553312434b980b590da803f19a0e181c5a?d=identicon)[chenyuanqi](/maintainers/chenyuanqi)

---

Top Contributors

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

---

Tags

elasticsearchlaravel5phpsearchlaravelelasticsearch

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/chenyuanqi-elasticsearch/health.svg)](https://phpackages.com/packages/chenyuanqi-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)

PHPackages © 2026

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