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

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

etsetra/elasticsearch
=====================

1.0.7(4y ago)2109MITPHPPHP ^7.4 || ^8.0

Since Sep 25Pushed 4y agoCompare

[ Source](https://github.com/etsetra/Elasticsearch)[ Packagist](https://packagist.org/packages/etsetra/elasticsearch)[ RSS](/packages/etsetra-elasticsearch/feed)WikiDiscussions main Synced 1mo ago

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

Elasticsearch
=============

[](#elasticsearch)

### Installation

[](#installation)

```
composer require etsetra/elasticsearch

```

1. Create config file

    $ php artisan vendor:publish --tag="etsetra-elasticsearch-config"
2. Update .env file

    ELASTICSEARCH\_SERVERS=127.0.0.1:9200,127.0.0.1:9201,127.0.0.1:9202

    ELASTICSEARCH\_RETRIES=2

    ELASTICSEARCH\_PASSWORD=1234 //This password is unique to you. Used to delete index

    ELASTICSEARCH\_PREFIX=app //prefix of indexes

### Model &amp; Migration

[](#model--migration)

```
$ php artisan elasticsearch:model MyModel

// Model created successfully.

```

or with migration

```
$ php artisan elasticsearch:model MyModel --m

// Model created successfully.

// Created Migration: 2021_09_25_151308_create_my_model_table

$ php artisan migrate

```

You can enter standard elasticsearch mapping parameters into the created migration file.

### Delete Index

[](#delete-index)

```
$ php artisan elasticsearch:index:delete

```

[![resim](https://user-images.githubusercontent.com/40306558/134776544-d1311bc5-24f0-4e65-ba01-2e2174531acb.png)](https://user-images.githubusercontent.com/40306558/134776544-d1311bc5-24f0-4e65-ba01-2e2174531acb.png)

The password is the ELASTICSEARCH\_PASSWORD value in the env file.

### Put Mapping

[](#put-mapping)

```
use App\Models\MyModel;

(new MyModel)->putIndexMapping(
    [
        'new_column_name' => [
            'type' => 'keyword'
        ]
    ]
);

```

### Search Document

[](#search-document)

```
use App\Models\MyModel;

$data = (new MyModel)->find(
    [
        'bool' => [
            'filter' => [
                'terms' => [
                    'user_id' => [ 1 ]
                ]
            ]
        ]
    ],
    [
        'from' => 0,
        'size' => 10,
        'sort' => [
            [
                'created_at' => [
                    'order' => 'desc'
                ]
            ]
        ]
    ]
);

// You can use all parameters of Elasticsearch.

// Results
stdClass Object
(
    [success] => ok
    [source] => Array
        (
            [0] => Array
                (
                    [id] => J6SzTtlUFpTQ
                    [user_id] => 1
                    [description] => 3 - Dolor egestas velit ligula nunc tortor ultricies quam consequat hac inceptos congue ullamcorper nisl.
                    [created_at] => 2021-09-25T15:23:25+00:00
                    [lang] => en
                )

            [1] => Array
                (
                    [id] => tky4EtIvlp1b
                    [user_id] => 1
                    [description] => Suspendisse ante commodo duis dignissim, elit mi orci vulputate hac curabitur duis dignissim
                    [created_at] => 2021-09-25T15:23:25+00:00
                    [lang] => en
                )
        )

    [aggregations] => Array
        (
        )

    [stats] => Array
        (
            [total] => 2
        )
)

```

### Create &amp; Update Document

[](#create--update-document)

```
use App\Models\MyModel;

// Create document
$create = (new MyModel)->create(
    [
        'id' => 'abcd1234',
        'user_id' => 1,
        'description' => 'Lorem ipsum...',
        'created_at' => '2021-09-25T15:23:25+00:00',
        'lang' => 'en',
    ],
    false, // upsert (bool, default = false)
    false, // should queue (bool, default = false)
);

// Update document
$update = (new MyModel)->update(
    'my_doc_id',
    [
        'description' => 'Lorem ipsum text...',
    ],
    false, // should queue (bool, default = false)
);

// Update by script
$update = (new MyModel)->script(
    'my_doc_id',
    [
        'ctx._source.views = 0;',
    ],
    false, // should queue (bool, default = false)
);

```

### Delete Document

[](#delete-document)

```
use App\Models\MyModel;

$delete = (new MyModel)->delete(
    'my_doc_id',
    false, // should queue (bool, default = false)
);

// Delete by Query
$items = (new MyModel)->deleteByQuery(
    [
      'bool' => [
        'must' => [
          [
            'match' => [ 'user_id' => 1 ]
          ]
        ]
      ]
    ],
    true // shouldQueue
);

```

### Get Document

[](#get-document)

```
use App\Models\MyModel;

$item = (new MyModel)->get('my_doc_id');

// Results
stdClass Object
(
    [success] => ok
    [source] => stdClass Object
        (
            [id] => J6SzTtlUFpTQFUm5LABP
            [user_id] => 1
            [description] => 'Lorem text...',
            [likes] => 0
            [created_at] => 2021-09-25T15:23:25+00:00
        )

)

```

### Bulk Actions

[](#bulk-actions)

```
use Etsetra\Elasticsearch\Console\BulkApi;

BulkApi::chunk(
  'my_model', // index name
  'J6SzTtlUFpTQ', // doc id
  [ 'ctx._source.views += 1' ], // doc body
  'script' // action type
);

// Action Types;
// script: elasticsearch java scripts,
// index: upsert document,
// create: create document,

// Alternate
BulkApi::chunk(
  'my_model',
  'J6SzTtlUFpTQ',
  [
    'user_id' => 2,
    'video_id' => 'dummy1234'
  ],
  'index' // action type
);

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

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

Total

8

Last Release

1595d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[teamtnt/tntsearch

A fully featured full text search engine written in PHP

3.2k3.0M28](/packages/teamtnt-tntsearch)[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)

PHPackages © 2026

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