PHPackages                             ccennis/larelastic - 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. [API Development](/categories/api)
4. /
5. ccennis/larelastic

ActiveLibrary[API Development](/categories/api)

ccennis/larelastic
==================

Generic Wrapper for elasticsearch and indexing

2.0.5(3mo ago)05PHPPHP ^8.2

Since Apr 7Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/ccennis/larelastic)[ Packagist](https://packagist.org/packages/ccennis/larelastic)[ RSS](/packages/ccennis-larelastic/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (4)Dependencies (8)Versions (17)Used By (0)

larelastic
==========

[](#larelastic)

An indexing and querying package to create, maintain and search an elastic instance with [Laravel Scout](https://laravel.com/docs/5.8/scout) as backbone.

### Contents

[](#contents)

- [Installation](#installation)
    - [Indexes](#indexing)
        - [Create and Maintain Index](#createMaintain)
        - [Migrating data](#migrating)
        - [Updating index](#updateIndex)
        - [Drop index](#dropIndex)
        - [Additional Configuration Options](#additionalOptions)
- [Usage and Examples](#usage)
    - [Searching](#searching)
        - [Where Example](#where)
        - [orWhere Example](#orWhere)
        - [Multimatch Example](#multi)
        - [Pagination Example](#pagination)
        - [Sorting Example](#sorting)
        - [Aggs Example](#aggs)
        - [Multimatch Example](#multimatch)

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

[](#installation)

### Laravel

[](#laravel)

##### Add the Third Party Service Providers in config/app.php

[](#add-the-third-party-service-providers-in-configappphp)

```
Larelastic\Elastic\Providers\ElasticServiceProvider::class
```

##### Add the Third Party Aliases in config/app.php

[](#add-the-third-party-aliases-in-configappphp)

```
'Elastic' => Larelastic\Elastic\Facades\Elastic::class
```

##### Get Config Files

[](#get-config-files)

```
php artisan vendor:publish
```

##### Add the following variables to your .env file

[](#add-the-following-variables-to-your-env-file)

```
ELASTICSEARCH_HOST=http://elastic:9200
ELASTICSEARCH_PORT=9200
SCOUT_DRIVER=elastic
SCOUT_ELASTIC_HOST=http://elastic:9200
```

 Indexing
-------------------------------------------

[](#-indexing)

(for a completely new installation -- skip ahead past 3rd step if index exists)

Since this package relies on the existence of models and index configurators to create, search and maintain indices, you must run the below commands to generate and set up the appropriate objects.

1.) create an indexConfigurator model (in this example, "Tattoo"):

```
 php artisan make:index-configurator TattooIndexConfigurator

```

2.) create your searchable Model:

```
php artisan make:searchable-model Product --index-configurator=TattooIndexConfigurator

```

3.) create your Elastic index using model with full path: ```
php artisan elastic:create-index "App\Models\Tattoo"

```

 Indexing
-------------------------------------------

[](#-indexing-1)

4.) add data to your index

`php artisan scout:import "App\Models\Tattoo"`

### Migrating to new Index

[](#migrating-to-new-index)

```
php artisan elastic:migrate "App\MyModel" my_index_v2

```

This process creates a new index, imports all data from previous to this index, and then links the old index to this new one via an alias

###  Update a mapping:

[](#-update-a-mapping)

```
php artisan elastic:update-mapping "App\\Models\MyModel"

```

### Update index:

[](#update-index)

```
php artisan elastic:update-index "App\Models\MyModelConfigurator"

```

###  Drop index:

[](#-drop-index)

```
php artisan elastic:drop-index "App\Models\MyModel"

```

###  Additional Configuration Options:

[](#-additional-configuration-options)

In your designated model, you may want to make use of the method:

```
public function searchableQuery()
{
    return $self->newQuery();
}

```

This will enable you to fine tune the actual query that is sent to elastic if you need to eager load or specify relationships.

 Usage and Examples
--------------------------------------------------

[](#-usage-and-examples)

Where/OrWhere queries make use of the [bool](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) methods (`must`, `must_not`, and `should`). Syntax is meant to be eloquent-like, but must use the `search` trait to differentiate it from actual Eloquent.

### Valid Operators

[](#valid-operators)

OperatorFunctionUsage=equals-&gt;where('col', '=', 'value')
 -&gt;where('col', 'value')&lt;&gt;not equals-&gt;where('col', '&lt;&gt;', 'value')inin field array-&gt;where('col', 'in', \['value'\])begins\_withsearch phrase beginning matched to search-&gt;where('col', 'begins\_with', 'value')ends\_withsearch phrase ending matched to search-&gt;where('col', 'ends\_with', 'value')containssearch phrase found in field-&gt;where('col', 'contains', 'value')gte&gt;=-&gt;where('col', 'gte', 'value')lte&lt;=-&gt;where('col', 'lte', 'value')gt&gt;-&gt;where('col', 'gt', 'value')lt&lt;-&gt;where('col', 'lt', 'value')betweendate found between two dates-&gt;where('col', 'between', \['value1', 'value2'\])existsthe value is not null and is found in index-&gt;where('col', 'exists')#### Sample `Where` query

[](#sample-where-query)

```
$response = Tattoo::search()->where('name', 'mold')->get();
$response = Tattoo::search()->where('name', '=', 'mold')->get();
```

Both of the above queries are valid. Default operator is '=' unless provided.

#### Sample `Or Where` query

[](#sample-or-where-query)

```
$response = Tattoo::search()->orWhere(['name', '=', 'mold'],['name', '=', 'Element'])->get();
```

takes two arrays, makes use of the `should` bool operator from Elastic. Evaluates to "find this OR that".

```
$response = Tattoo::search()->orWhere(function($query, $boolean){
            $query->where('name', '=','Mold', $boolean)
            ->where('model', '=','test', $boolean);
            return $query;
        })->orWhere(function($query, $boolean){
            $query->where('name', '=','element', $boolean)
            ->where('model', '=','test', $boolean);
            return $query;
        })->get();
```

Closure, makes use of multiple groupings under `should` bool operator from Elastic. Evaluates to "find (this AND that) OR (this and that)".

#### Sample `Multimatch` query

[](#sample-multimatch-query)

```
 $response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold')->get();

```

This makes use of the [multimatch](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html) elastic function, takes an array of fields. Default search type is [phrase prefix](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-phrase), but accepts an argument to override, such as [best\_fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-best-fields):

```
 $response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold', 'best_fields')->get();

```

#### Pagination

[](#pagination)

```
 $response = Tattoo::search()->whereMulti(['name', 'model'],'=','Mold')->paginate(20);

```

Pagination functions much the same as in eloquent. It will wrap your response in the Paginator Length Aware metadata fields:

```
first_page_url: "http://myProject.com?page=1",
from: 1,
last_page: 2,
last_page_url: "http://myProject.com?page=3",
next_page_url: "http://myProject.com?page=2",
path: "http://myProject.com",
per_page: 20,
prev_page_url: null,
to: 2,
total: 36

```

#### Sorting

[](#sorting)

Simple Sorting:

```
$response = Tattoo::search()->where('name', 'mold')
sort->('name','desc')->get()
```

Sorting defaults to asc and can be stacked for multiple sorts.

If you need to specify a field\_type for the sort field (i.e. 'keyword' or 'raw') you can include it as a param:

```
$response = Tattoo::search()->where('name', 'mold')
sort->('name', 'desc', 'keyword')->get()
```

The above may be necessary in the event you are already querying a nested object and want to ensure the datatype is listed separately.

#### Aggregation (aggs)

[](#aggregation-aggs)

```
$response = Tattoo::search()->where('name', 'mold')
->rollup('card_color')->get();
```

initial support for aggs takes a column name and creates buckets to count all matches. result set will be under an "aggs" object, like so:

```
{
	aggs: {
		agg_field: {
			doc_count_error_upper_bound: 0,
			sum_other_doc_count: 0,
			buckets: [{
					key: "G",
					doc_count: 35
				},
				{
					key: "B",
					doc_count: 1
				}
			]
		}
	}
}
```

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance81

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% 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 ~59 days

Recently: every ~3 days

Total

13

Last Release

103d ago

Major Versions

1.6 → 2.0.02026-02-23

### Community

Maintainers

![](https://www.gravatar.com/avatar/9572189dde381eeec827414f393fda85f36e92a1a1e5694bb9d85757b65280f8?d=identicon)[ccennis](/maintainers/ccennis)

---

Top Contributors

[![ccennis](https://avatars.githubusercontent.com/u/37984545?v=4)](https://github.com/ccennis "ccennis (8 commits)")[![ccennis-somar](https://avatars.githubusercontent.com/u/239052387?v=4)](https://github.com/ccennis-somar "ccennis-somar (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ccennis-larelastic/health.svg)

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

###  Alternatives

[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[unopim/unopim

UnoPim Laravel PIM

10.3k2.2k](/packages/unopim-unopim)[matchish/laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout

7451.7M3](/packages/matchish-laravel-scout-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

399654.3k](/packages/jeroen-g-explorer)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

84735.1k](/packages/flow-php-flow)[rapidez/core

Rapidez Core

1822.4k65](/packages/rapidez-core)

PHPackages © 2026

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