PHPackages                             belyys7/elasticsearch-its-easy - 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. belyys7/elasticsearch-its-easy

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

belyys7/elasticsearch-its-easy
==============================

Simple search with elasticsearch

1.1.1(3y ago)06MITPHPPHP ^7.1

Since Apr 9Pushed 3y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

Elasticsearch it`s easy SDK
===========================

[](#elasticsearch-its-easy-sdk)

Elasticsearch it`s easy SDK for working with Elasticsearch like with constructor

Documentation
-------------

[](#documentation)

The documentation for the Elasticsearch REST API can be found [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/rest-apis.html).

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](https://getcomposer.org/download/).

Either run

```
composer require idapgroup/elasticsearch-its-easy

```

or add

```
{
  "require": {
    "idapgroup/elasticsearch-its-easy": "^1.0.0"
  }
}
```

to the requirement section of your `composer.json` file.

Quickstart
----------

[](#quickstart)

### Prepare the data you want to store in elasticsearch

[](#prepare-the-data-you-want-to-store-in-elasticsearch)

```
$data = [
    [
        'user' => [
            'id' => 100,
            'email' => 'stepan21@gmail.com',
            'name' => 'Stepan',
            'age' => 21,
            'birthday' => '2001-06-15',
        ],
        'work' => [
            'position' => [
                'id' => 25,
                'name' => 'php developer',
            ],
            'skills' => [
                [
                    'id' => 36,
                    'name' => 'php'
                ],
                [
                    'id' => 40,
                    'name' => 'mysql'
                ],
                [
                    'id' => 56,
                    'name' => 'js'
                ],
            ],
            'salary' => 4000
        ],
        'location' => [
            'lat' => 50.445077,
            'lon' => 30.521215
        ],
    ],
    [
        'user' => [
            'id' => 101,
            'email' => 'luigi@gmail.com',
            'name' => 'Luigi',
            'age' => 29,
            'birthday' => '2005-03-20',
        ],
        'work' => [
            'position' => [
                'id' => 12,
                'name' => 'js developer',
            ],
            'skills' => [
                [
                    'id' => 56,
                    'name' => 'js'
                ],
                [
                    'id' => 70,
                    'name' => 'mongodb'
                ],
                [
                    'id' => 1,
                    'name' => 'html'
                ],
                [
                    'id' => 2,
                    'name' => 'css'
                ],
            ],
            'salary' => 2700
        ],
        'location' => [
            'lat' => 47.454589,
            'lon' => 32.915673
        ],
    ],
];
```

### Create your class to be expanded by basic search

[](#create-your-class-to-be-expanded-by-basic-search)

```
use IdapGroup\ElasticsearchItsEasy\ModelSearchBase;

class StaffModelSearch extends ModelSearchBase
{
    public function setRules() : void
    {
        $this->rules = [
            self::GROUP_MUST => [
                self::RULE_EQUAL => [
                    'userId' => 'user.id',
                ],
            ],
            self::GROUP_SHOULD => [
                self::RULE_LIKE => [
                    'userEmail' => 'user.email',
                    'userName' => 'user.name',
                ],
                self::RULE_IN => [
                    'workSkillsId' => 'work.skills.id',
                ],
            ],
            self::GROUP_FILTER => [
                self::RULE_EQUAL => [
                    'workPositionId' => 'work.position.id'
                ],
                self::RULE_RANGE_NUMBER => [
                    'userAge' => 'user.age',
                    'workSalary' => 'work.salary',
                ],
                self::RULE_RANGE_DATE => [
                    'birthday' => 'user.birthday',
                ],
            ],
            self::GROUP_LOCATION => [
                'location' => self::SORT_DESC,
            ],
        ];
    }

    public function setSort() : void
    {
        $this->sort = [
            'user.id' => self::SORT_DESC,
        ];
    }

}
```

### Create model based on elasticsearch configuration

[](#create-model-based-on-elasticsearch-configuration)

```
$staffModelSearch = new StaffModelSearch('es01', '9200', 'staff_search');
```

### Indexing Documents in Elasticsearch

[](#indexing-documents-in-elasticsearch)

```
$staffModelSearch->reCreateIndex();

foreach ($data as $item) {
    $staffModelSearch->addDocument($item, 'user.id', $item['user']['id']);
}
```

### Example #1: search as list with pagination

[](#example-1-search-as-list-with-pagination)

#### Specify search keys and their values

[](#specify-search-keys-and-their-values)

```
$params = [
    'userId' => 100,
    'workPositionId' => 25,
    'userEmail' => 'stepan21@gmail.com',
    'userName' => 'Stepan',
    'workSkillsId' => [36, 40],
    'userAge' => ['min' => 18, 'max' => 65],
    'workSalary' => ['min' => 500, 'max' => 5000],
    'location' => [
        'point' => [
            'lat' => 48.454589,
            'lon' => 33.915673,
            'distance' => 100000
        ],
        'rectangle' => [
            'topLeftLat' => 55.710929,
            'topLeftLng' => 14.090451,
            'bottomRightLat' => 41.830140,
            'bottomRightLng' => 41.802791
        ],
    ],
    'page' => 1,
    'limit' => 20
];
```

### Set data output limits if required and search

[](#set-data-output-limits-if-required-and-search)

```
//$staffModelSearch->enableFixLimitResult(50);
$result = $staffModelSearch->searchList($params);
```

### The result of the response will be in the format

[](#the-result-of-the-response-will-be-in-the-format)

```
[
    'result' => [
        [
            'user' => [
                'id' => 100,
                'email' => 'stepan21@gmail.com',
                'name' => 'Stepan',
                'age' => 21
            ],
            'work' => [
                'position' => [
                    'id' => 25,
                    'name' => 'php developer',
                ],
                'skills' => [
                    [
                        'id' => 36,
                        'name' => 'php'
                    ],
                    [
                        'id' => 40,
                        'name' => 'mysql'
                    ],
                    [
                        'id' => 56,
                        'name' => 'js'
                    ],
                ],
                'salary' => 4000
            ],
            'location' => [
                'lat' => 50.445077,
                'lon' => 30.521215
            ],
        ],
        //... etc.
    ],
    'pagination' => [
        'totalCount' => (int),
        'pageCount' => (int),
        'currentPage' => (int)
    ]
]
```

### Example #2: search for map

[](#example-2-search-for-map)

#### Specify search keys and their values

[](#specify-search-keys-and-their-values-1)

```
$params = [
    'userId' => 100,
    'workPositionId' => 25,
    'userEmail' => 'stepan21@gmail.com',
    'userName' => 'Stepan',
    'workSkillsId' => [36, 40],
    'userAge' => ['min' => 18, 'max' => 65],
    'workSalary' => ['min' => 500, 'max' => 5000],
    'location' => [
        'point' => [
            'lat' => 48.454589,
            'lon' => 33.915673,
            'distance' => 100000
        ],
        'rectangle' => [
            'topLeftLat' => 55.710929,
            'topLeftLng' => 14.090451,
            'bottomRightLat' => 41.830140,
            'bottomRightLng' => 41.802791
        ],
    ],
];
```

#### Execute search

[](#execute-search)

```
$result = $staffModelSearch->searchMap($params);
```

### The result of the response will be in the format

[](#the-result-of-the-response-will-be-in-the-format-1)

```
[
    [
        'user' => [
            'id' => 100,
            'email' => 'stepan21@gmail.com',
            'name' => 'Stepan',
            'age' => 21
        ],
        'work' => [
            'position' => [
                'id' => 25,
                'name' => 'php developer',
            ],
            'skills' => [
                [
                    'id' => 36,
                    'name' => 'php'
                ],
                [
                    'id' => 40,
                    'name' => 'mysql'
                ],
                [
                    'id' => 56,
                    'name' => 'js'
                ],
            ],
            'salary' => 4000
        ],
        'location' => [
            'lat' => 50.445077,
            'lon' => 30.521215
        ],
    ],
    //... etc.
]
```

Additional settings
-------------------

[](#additional-settings)

#### Custom clustering (useful when markers on the map overlap each other and the maximum zoom does not solve the problem)

[](#custom-clustering-useful-when-markers-on-the-map-overlap-each-other-and-the-maximum-zoom-does-not-solve-the-problem)

```
$params = [
    //...
    'location' => [
        'point' => [
            'lat' => 48.454589,
            'lon' => 33.915673,
            'distance' => 100000
        ],
        'rectangle' => [
            'topLeftLat' => 55.710929,
            'topLeftLng' => 14.090451,
            'bottomRightLat' => 41.830140,
            'bottomRightLng' => 41.802791
        ],
        'clustering' => true,
        'zoom' => 1,
    ],
    //...
];
```

#### Response structure example

[](#response-structure-example)

```
[
    // Cluster 1
    [
        [
            // data
        ],
        [
            // data
        ],
        //...
    ],
    // Cluster 2
    [
        [
            // data
        ],
        [
            // data
        ],
        //...
    ],
    //... etc.
]
```

#### Overwrite rules

[](#overwrite-rules)

```
// Describe the rules in the associative array as required by the ES documentation
$overWriteRules = [
    'must' => [
        [
            'term' => [
                'user.name.keyword' => 'Stepan',
            ],
        ],
        [
            'term' => [
                'user.age' => 21,
            ],
        ],
        //...
    ],
    //...
];

// Use a Method to Set Your Rules
$staffModelSearch->setOverWriteRules($overWriteRules);
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Total

5

Last Release

1104d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/76eee69096007276d581fdcedb44cc821b0643f448edbfde8347ad9bf48d9b6b?d=identicon)[belyys7](/maintainers/belyys7)

---

Top Contributors

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

---

Tags

elasticsearch

### Embed Badge

![Health badge](/badges/belyys7-elasticsearch-its-easy/health.svg)

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

###  Alternatives

[mailerlite/laravel-elasticsearch

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

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[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)[jsq/amazon-es-php

Support for using IAM authentication with the official Elasticsearch PHP client

9310.6M13](/packages/jsq-amazon-es-php)[babenkoivan/elastic-client

The official PHP Elasticsearch client integrated with Laravel

544.0M6](/packages/babenkoivan-elastic-client)[madewithlove/elasticsearcher

Wrapper on top of the ElasticSearch PHP SDK which allows easier index/document/query management.

264133.2k2](/packages/madewithlove-elasticsearcher)

PHPackages © 2026

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