PHPackages                             own3d/laravel-scout-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. own3d/laravel-scout-elasticsearch

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

own3d/laravel-scout-elasticsearch
=================================

Search among multiple models with ElasticSearch and Laravel Scout

5.0.3(3y ago)08MITPHPPHP ^8.0

Since Mar 30Pushed 3y agoCompare

[ Source](https://github.com/own3d/laravel-scout-elasticsearch)[ Packagist](https://packagist.org/packages/own3d/laravel-scout-elasticsearch)[ Patreon](https://www.patreon.com/matchish)[ RSS](/packages/own3d-laravel-scout-elasticsearch/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (30)Used By (0)

 [ ![Scout ElasticSearch](https://raw.githubusercontent.com/matchish/laravel-scout-elasticsearch/master/docs/banner.svg?sanitize=true) ](https://github.com/matchish/laravel-scout-elasticsearch) [![Import progress report](https://raw.githubusercontent.com/matchish/laravel-scout-elasticsearch/master/docs/demo.gif)](https://raw.githubusercontent.com/matchish/laravel-scout-elasticsearch/master/docs/demo.gif)

 [![Build Status](https://camo.githubusercontent.com/3203839515426543054ac9b11d06fc46dde42fc539392e9c3fdd978e2143668c/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f6d617463686973682f6c61726176656c2d73636f75742d656c61737469637365617263682f6d61737465722e737667)](https://travis-ci.com/matchish/laravel-scout-elasticsearch) [![Code quality](https://camo.githubusercontent.com/5ca3e414791b00e5eb3077b32f5dcba6dde3715832668bdb47dbf931f58d0d5e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d617463686973682f6c61726176656c2d73636f75742d656c61737469637365617263682e7376673f6c6162656c3d7175616c697479)](https://scrutinizer-ci.com/g/matchish/laravel-scout-elasticsearch) [![Coverage](https://camo.githubusercontent.com/afd045109fa2baa2b05345bb0d4d0ddc2e944d26bc27c2b99744d7f6fd91dc7e/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d617463686973682f6c61726176656c2d73636f75742d656c61737469637365617263682e737667)](https://scrutinizer-ci.com/g/matchish/laravel-scout-elasticsearch) [![Total Downloads](https://camo.githubusercontent.com/c7f319c85e0ed45a9a3a753527dc0722a00503db4a69138bc607b5e7f84aeadd/68747470733a2f2f706f7365722e707567782e6f72672f6d617463686973682f6c61726176656c2d73636f75742d656c61737469637365617263682f642f746f74616c2e737667)](https://packagist.org/packages/matchish/laravel-scout-elasticsearch) [![Latest Version](https://camo.githubusercontent.com/4d515f3d6bb97c9f71903009b25f408446c8935b697f51112f661ec6f4e6d134/68747470733a2f2f706f7365722e707567782e6f72672f6d617463686973682f6c61726176656c2d73636f75742d656c61737469637365617263682f762f737461626c652e737667)](https://packagist.org/packages/matchish/laravel-scout-elasticsearch) [![License](https://camo.githubusercontent.com/dfef7487193b120dfb01a97ace414c6584ac78c97f46d41e241476f3436c8d35/68747470733a2f2f706f7365722e707567782e6f72672f6d617463686973682f6c61726176656c2d73636f75742d656c61737469637365617263682f6c6963656e73652e737667)](https://packagist.org/packages/matchish/laravel-scout-elasticsearch)

#### For PHP8 support use [php8](https://github.com/matchish/laravel-scout-elasticsearch/tree/php8) branch

[](#for-php8-support-use-php8-branch)

#### For Laravel Framework &lt; 6.0.0 use [3.x](https://github.com/matchish/laravel-scout-elasticsearch/tree/3.x) branch

[](#for-laravel-framework--600-use-3x-branch)

The package provides the perfect starting point to integrate ElasticSearch into your Laravel application. It is carefully crafted to simplify the usage of ElasticSearch within the [Laravel Framework](https://laravel.com).

It’s built on top of the latest release of [Laravel Scout](https://laravel.com/docs/scout), the official Laravel search package. Using this package, you are free to take advantage of all of Laravel Scout’s great features, and at the same time leverage the complete set of ElasticSearch’s search experience.

If you need any help, [stack overflow](https://stackoverflow.com/questions/tagged/laravel-scout%20laravel%20elasticsearch) is the preferred and recommended way to ask support questions.

💕 Features
----------

[](#two_hearts-features)

Don't forget to ⭐ the package if you like it. 🙏

- Laravel Scout 9.x support
- [Search amongst multiple models](#search-amongst-multiple-models)
- [**Zero downtime** reimport](#zero-downtime-reimport) - it’s a breeze to import data in production.
- [Eager load relations](#eager-load) - speed up your import.
- Import all searchable models at once.
- A fully configurable mapping for each model.
- Full power of ElasticSearch in your queries.

⚠️ Requirements
---------------

[](#warning-requirements)

- PHP version &gt;= 8.0
- Laravel Framework version &gt;= 8.0.0

Elasticsearch versionElasticsearchDSL version&gt;= 7.0&gt;= 3.0.0&gt;= 6.0, &lt; 7.0&lt; 3.0.0🚀 Installation
--------------

[](#rocket-installation)

Use composer to install the package:

`composer require matchish/laravel-scout-elasticsearch`

Set env variables

```
SCOUT_DRIVER=Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine

```

The package uses `\ElasticSearch\Client` from official package, but does not try to configure it, so feel free do it in your app service provider. But if you don't want to do it right now, you can use `Matchish\ElasticSearchServiceProvider` from the package.
Register the provider, adding to `config/app.php`

```
'providers' => [
    // Other Service Providers

    \Matchish\ScoutElasticSearch\ElasticSearchServiceProvider::class
],
```

Set `ELASTICSEARCH_HOST` env variable

```
ELASTICSEARCH_HOST=host:port

```

And publish config example for elasticsearch
`php artisan vendor:publish --tag config`

💡 Usage
-------

[](#bulb-usage)

> **Note:** This package adds functionalities to [Laravel Scout](https://github.com/laravel/scout), and for this reason, we encourage you to **read the Scout documentation first**. Documentation for Scout can be found on the [Laravel website](https://laravel.com/docs/scout).

### Index [settings](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#create-index-settings) and [mappings](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#mappings)

[](#index-settings-and-mappings)

It is very important to define the mapping when we create an index — an inappropriate preliminary definition and mapping may result in the wrong search results.

To define mappings or settings for index, set config with right value.

For example if method `searchableAs` returns `products` string

Config key for mappings should be
`elasticsearch.indices.mappings.products`
Or you you can specify default mappings with config key `elasticsearch.indices.mappings.default`

Same way you can define settings

For index `products` it will be
`elasticsearch.indices.settings.products`

And for default settings
`elasticsearch.indices.settings.default`

### Eager load

[](#eager-load)

To speed up import you can eager load relations on import using global scopes.

You should configure `ImportSourceFactory` in your service provider(`register` method)

```
use Matchish\ScoutElasticSearch\Searchable\ImportSourceFactory;
...
public function register(): void
{
$this->app->bind(ImportSourceFactory::class, MyImportSourceFactory::class);
```

Here is an example of `MyImportSourceFactory`

```
namespace Matchish\ScoutElasticSearch\Searchable;

final class MyImportSourceFactory implements ImportSourceFactory
{
    public static function from(string $className): ImportSource
    {
        //Add all required scopes
        return new DefaultImportSource($className, [new WithCommentsScope()]);
    }
}

class WithCommentsScope implements Scope {

    /**
     * Apply the scope to a given Eloquent query builder.
     *
     * @param \Illuminate\Database\Eloquent\Builder $builder
     * @param \Illuminate\Database\Eloquent\Model $model
     * @return void
     */
    public function apply(Builder $builder, Model $model)
    {
        $builder->with('comments');
    }
}
```

### Zero downtime reimport

[](#zero-downtime-reimport)

While working in production, to keep your existing search experience available while reimporting your data, you also can use `scout:import` Artisan command:

`php artisan scout:import`

The command create new temporary index, import all models to it, and then switch to the index and remove old index.

### Search

[](#search)

To be fully compatible with original scout package, this package does not add new methods.
So how we can build complex queries? There is two ways.
By default, when you pass a query to the `search` method, the engine builds a [query\_string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html) query, so you can build queries like this

```
Product::search('title:this OR description:this) AND (title:that OR description:that')`
```

If it's not enough in your case you can pass a callback to the query builder

```
$results = Product::search('zonga', function($client, $body) {

    $minPriceAggregation = new MinAggregation('min_price');
    $minPriceAggregation->setField('price');

    $maxPriceAggregation = new MaxAggregation('max_price');
    $maxPriceAggregation->setField('price');

    $brandTermAggregation = new TermsAggregation('brand');
    $brandTermAggregation->setField('brand');

    $body->addAggregation($minPriceAggregation);
    $body->addAggregation($brandTermAggregation);

    return $client->search(['index' => 'products', 'body' => $body->toArray()]);
})->raw();
```

`$client` is `\ElasticSearch\Client` object from [elasticsearch/elasticsearch](https://packagist.org/packages/elasticsearch/elasticsearch) package
And `$body` is `ONGR\ElasticsearchDSL\Search` from [ongr/elasticsearch-dsl](https://packagist.org/packages/ongr/elasticsearch-dsl) package

### Search amongst multiple models

[](#search-amongst-multiple-models)

You can do it with `MixedSearch` class, just pass indices names separated by commas to the `within` method.

```
MixedSearch::search('title:Barcelona or to:Barcelona')
    within(implode(',', [
        (new Ticket())->searchableAs(),
        (new Book())->searchableAs(),
    ]))
->get();
```

In this example you will get collection of `Ticket` and `Book` models where ticket's arrival city or book title is `Barcelona`

### Working with results

[](#working-with-results)

Often your response isn't collection of models but aggregations or models with higlights an so on. In this case you need to implement your own implementation of `HitsIteratorAggregate` and bind it in your service provider

[Here is a case](https://github.com/matchish/laravel-scout-elasticsearch/issues/28)

🆓 License
---------

[](#free-license)

Scout ElasticSearch is an open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 87% 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 ~64 days

Recently: every ~194 days

Total

23

Last Release

1175d ago

Major Versions

3.0.3 → 4.0.02020-03-15

3.0.5 → 4.0.42020-12-14

3.0.6 → 4.0.52021-01-05

4.0.5 → 5.0.02021-05-13

4.0.6 → 5.0.32023-02-22

PHP version history (4 changes)1.0.0PHP ^7.1.3

4.0.0PHP ^7.2

4.0.3PHP ^7.2|^7.3

5.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/03da561a330aa76d1a09096b2ee0c48ee53ca51d62fa0239469d9615b6855733?d=identicon)[ghostzero](/maintainers/ghostzero)

---

Top Contributors

[![matchish](https://avatars.githubusercontent.com/u/818563?v=4)](https://github.com/matchish "matchish (381 commits)")[![ametad](https://avatars.githubusercontent.com/u/1582541?v=4)](https://github.com/ametad "ametad (28 commits)")[![burakcakirel](https://avatars.githubusercontent.com/u/3121372?v=4)](https://github.com/burakcakirel "burakcakirel (15 commits)")[![ghostzero](https://avatars.githubusercontent.com/u/6547306?v=4)](https://github.com/ghostzero "ghostzero (3 commits)")[![AmirrezaNasiri](https://avatars.githubusercontent.com/u/19557224?v=4)](https://github.com/AmirrezaNasiri "AmirrezaNasiri (2 commits)")[![ganicus](https://avatars.githubusercontent.com/u/1510161?v=4)](https://github.com/ganicus "ganicus (2 commits)")[![szabizs](https://avatars.githubusercontent.com/u/5064872?v=4)](https://github.com/szabizs "szabizs (1 commits)")[![youanden](https://avatars.githubusercontent.com/u/183880?v=4)](https://github.com/youanden "youanden (1 commits)")[![derpierre65](https://avatars.githubusercontent.com/u/7004269?v=4)](https://github.com/derpierre65 "derpierre65 (1 commits)")[![mackhankins](https://avatars.githubusercontent.com/u/2184080?v=4)](https://github.com/mackhankins "mackhankins (1 commits)")[![mauxtin](https://avatars.githubusercontent.com/u/40521145?v=4)](https://github.com/mauxtin "mauxtin (1 commits)")[![Pluiesurlavitre](https://avatars.githubusercontent.com/u/11065186?v=4)](https://github.com/Pluiesurlavitre "Pluiesurlavitre (1 commits)")[![SachinAgarwal1337](https://avatars.githubusercontent.com/u/5370915?v=4)](https://github.com/SachinAgarwal1337 "SachinAgarwal1337 (1 commits)")

---

Tags

searchlaravelelasticsearchextendedscout

### Embed Badge

![Health badge](/badges/own3d-laravel-scout-elasticsearch/health.svg)

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

###  Alternatives

[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)
