PHPackages                             pion/laravel-lelastico - 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. pion/laravel-lelastico

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

pion/laravel-lelastico
======================

v0.2.4(4y ago)39.7k↓50%2[1 issues](https://github.com/pionl/laravel-lelastico/issues)MITPHPPHP &gt;=7.4

Since Apr 16Pushed 3y ago2 watchersCompare

[ Source](https://github.com/pionl/laravel-lelastico)[ Packagist](https://packagist.org/packages/pion/laravel-lelastico)[ RSS](/packages/pion-laravel-lelastico/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (17)Used By (0)

Lelastico - easier elastic search for Laravel
=============================================

[](#lelastico---easier-elastic-search-for-laravel)

[![Total Downloads](https://camo.githubusercontent.com/70bcb72f74974d5cd8cc64bba5789369112abd248eb31d720ed04af7ce40a9df/68747470733a2f2f706f7365722e707567782e6f72672f70696f6e2f6c61726176656c2d6c656c61737469636f2f646f776e6c6f6164733f666f726d61743d666c6174)](https://packagist.org/packages/pion/laravel-elastico)[![Latest Stable Version](https://camo.githubusercontent.com/1effc4e9fe725974d9e263fb728af45ab144f9660f207cb5a0f6e2edc11dd76f/68747470733a2f2f706f7365722e707567782e6f72672f70696f6e2f6c61726176656c2d6c656c61737469636f2f762f737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/pion/laravel-elastico)[![Latest Unstable Version](https://camo.githubusercontent.com/6fa55dad86c5295cc68ff095d781f228c9f4f266e790d286a293cf6971520565/68747470733a2f2f706f7365722e707567782e6f72672f70696f6e2f6c61726176656c2d6c656c61737469636f2f762f756e737461626c653f666f726d61743d666c6174)](https://packagist.org/packages/pion/laravel-elastico)[![License](https://camo.githubusercontent.com/e909f883d2bcb96ed53a07340ae79d10dbb428405418decf7e1b409e06925db8/68747470733a2f2f706f7365722e707567782e6f72672f70696f6e2f6c61726176656c2d6c656c61737469636f2f6c6963656e7365)](https://packagist.org/packages/pion/laravel-lelastico)

Introduction
------------

[](#introduction)

Focus of this library is to make it easier to manage elastic indices (wit mappings / settings), create reusable query building (manual or from request).

- Adds ability to manage elasticsearch indices with wrapper class which will help to you create/update index write documents (with bulk mode) etc.
- Adds ability to create a query builder with query filters for each index.
- Adds ability to build a query builder from request data (reusable component).

Requirements
------------

[](#requirements)

- Composer
- PHP 7.4+

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

[](#installation)

**1. Add custom repository to composer.json**

```
"repositories": {
    {
        "type": "git",
        "url": "https://github.com/pionl/elasticsearch-query-builder.git"
    }
}

```

**2. Install via composer**

```
composer require pion/laravel-lelastico

```

**3. Add the service provider (Laravel 5.4 and below - supports Auto discovery)**

```
\Lelastico\LelasticoServiceProvider::class,
```

Dependencies
------------

[](#dependencies)

- [erichard/elasticsearch-query-builder](https://github.com/erichard/elasticsearch-query-builder) - at this moment forked version with additional functions.
- [elasticsearch/elasticsearch](https://github.com/elasticsearch/elasticsearch), version 7 and above (tested with 7.5).

Usage
-----

[](#usage)

**Set elastic hosts**

> For development, you can use default value in the config without password: localhost:9200

Use `ELASTICSEARCH_HOSTS` environment for setting elastic search hosts. [Format](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/configuration.html).

**Resolve elastic search client**

```
$client = resolve(\Elasticsearch\Client::class);

```

```
$client = $container->make(\Elasticsearch\Client::class);

```

**Mapping types constants**

Property mappings types using constants like:

- MappingTypes::KEYWORD
- MappingTypes::TEXT
- MappingTypes::TEXT\_WITH\_KEYWORD
- MappingTypes::SHORT
- MappingTypes::SHORT\_WITH\_KEYWORD
- MappingTypes::LONG
- MappingTypes::LONG\_WITH\_KEYWORD
- MappingTypes::INTEGER
- MappingTypes::INTEGER\_WITH\_KEYWORD
- MappingTypes::DATE
- MappingTypes::BOOLEAN
- MappingTypes::FLOAT
- MappingTypes::textWithAnalyzer(string $analyzer, string $searchAnalyzer), builds

**Adding indices**

1. Create your indices by extending `AbstractElasticIndex` and implementing `createIndexName` for elastic index

    - Implement `propertyMappings` for custom mappings.

    ```
    protected function propertyMappings(): array
    {
      return [
          'id' => MappingTypes::KEYWORD,
          'name' => MappingTypes::TEXT_WITH_KEYWORD,
          'is_verified' => MappingTypes::BOOLEAN,
          'email' => MappingTypes::textWithAnalyzer('fulltext'),
          'created_at' => MappingTypes::DATE,
          'updated_at' => MappingTypes::DATE,
          'deleted_at' => MappingTypes::DATE,
      ];
    }
    ```

    - Implement `settings` for custom index settings

    ```
    protected function settings(): array
    {
      // Add support for partial text search
      return [
          'index' => [
              'analysis' => [
                  'filter' => [
                      'fulltext_filter' => [
                          // Always from start of beginning of each token
                          'type' => 'edge_ngram',
                          'min_gram' => 3,
                          'max_gram' => 20,
                      ],
                  ],
                  'analyzer' => [
                      'fulltext' => [
                          'type' => 'custom',
                          'tokenizer' => 'standard',
                          'filter' => ['lowercase', 'fulltext_filter'],
                      ],
                  ],
              ],
          ],
      ];
    }
    ```
2. Create or update `lelastico.php` config with indices classes.

    ```
    return [
        'indices' => [
            \App\ElasticSearch\Indices\UsersIndex::class,
        ],
    ];
    ```
3. Update or create indices in elastic (stores settings / mapping) using `php artisan elastic:indices`

    ```
    Updates the elastic indices
            --only="only", handle only given index
            --f, will delete the index and data. Will new index with mappings
            --d, will delete the index and data
            --skip-settings-update, when upadting, the index is closed / opened due the settings update. You can skip it
            by provided this option.

    ```

**Sorting**

**By default we are sorting by `_id` after any HasSorting logic to ensure that pagination is correct.**

You can turn this feature by using `$builder->setSortById(false);`

To enable sortable behavior add `HasSorting` trait to your instance of `AbstractBuilder` and implement method `allowedSortFields`.

```
/**
 * Allowed fields for sorting.
 *
 * Key is the name of the field in the query.
 * Value is the name of the field in the index.
 *
 * @return array
 */
public function allowedSortFields(): array
{
    return [
        'goals' => 'goals_count',
        'minutes' => 'played_minutes',
    ];
}

```

With sorting enabled you can sort the results using `sort` request query parameter. This parameter accepts list of fields for sorting in format `{field_name}:{sort_direction}`.

Available directions for sorting are `asc` and `desc` and if not specified the default sort direction is set to `asc`.

**Examples:**

`sort[]=goals`

`sort[]=goals:asc&sort[]=minutes:desc`

Configuration
-------------

[](#configuration)

- `log_measurement` Logs every query to log (default false). You can use `ELASTICSEARCH_LOG_MEASUREMENT` env.
- `log_debug` Debug logs every query data to a log (true in local environment). You can use `ELASTICSEARCH_LOG_DEBUG` env.
- `service` Enables to change available indices (implement IndicesServiceContract or extend IndicesService)
- `prefix` Used prefix for index names - uses APP\_NAME and replace '-' to '\_', converts name to slug variant.
- `hosts` A list of IPS for your elastic search - . Use `;` separator. Default localhost:9200.

TODO
----

[](#todo)

- improve documentation
- add `make` console.

Changelog
---------

[](#changelog)

Can be found in [releases](https://github.com/pionl/laravel-elastico/releases).

Contribution or extending
-------------------------

[](#contribution-or-extending)

See [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute changes. All contributions are welcome.

Sponsors
--------

[](#sponsors)

> This library was created and improved thanks to clients projects.

- [Azzurro, Travel agency](https://www.azzurro.cz)
- [Certisys, s.r.o.](https://certisys.cz)

Copyright and License
---------------------

[](#copyright-and-license)

[laravel-elastico](https://github.com/pionl/laravel-elastico)was written by [Martin Kluska](http://kluska.cz) and is released under the [MIT License](LICENSE.md).

Copyright (c) 2020 Martin Kluska

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82.6% 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 ~50 days

Recently: every ~110 days

Total

15

Last Release

1524d ago

### Community

Maintainers

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

---

Top Contributors

[![pionl](https://avatars.githubusercontent.com/u/1878831?v=4)](https://github.com/pionl "pionl (19 commits)")[![vitezslav-lindovsky](https://avatars.githubusercontent.com/u/677034?v=4)](https://github.com/vitezslav-lindovsky "vitezslav-lindovsky (2 commits)")[![erikpach](https://avatars.githubusercontent.com/u/2639228?v=4)](https://github.com/erikpach "erikpach (1 commits)")[![jakubdibala](https://avatars.githubusercontent.com/u/7672104?v=4)](https://github.com/jakubdibala "jakubdibala (1 commits)")

---

Tags

elasticsearchlaravellaravel-package

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/pion-laravel-lelastico/health.svg)

```
[![Health](https://phpackages.com/badges/pion-laravel-lelastico/health.svg)](https://phpackages.com/packages/pion-laravel-lelastico)
```

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

74310.9M66](/packages/laravel-mcp)[laravel-doctrine/orm

An integration library for Laravel and Doctrine ORM

8425.3M87](/packages/laravel-doctrine-orm)[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)[mailerlite/laravel-elasticsearch

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

934529.3k2](/packages/mailerlite-laravel-elasticsearch)

PHPackages © 2026

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