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

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

rapidez/laravel-scout-elasticsearch
===================================

Search among multiple models with ElasticSearch and Laravel Scout

1.0.0(10mo ago)028.3k↓44.3%2MITPHPPHP ^8.1CI passing

Since Jul 1Pushed 10mo ago1 watchersCompare

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

READMEChangelog (2)Dependencies (10)Versions (3)Used By (2)

Laravel Scout ElasticSearch &amp; Opensearch
============================================

[](#laravel-scout-elasticsearch--opensearch)

[![Import progress report](https://raw.githubusercontent.com/rapidez/laravel-scout-elasticsearch/master/docs/demo.gif)](https://raw.githubusercontent.com/rapidez/laravel-scout-elasticsearch/master/docs/demo.gif)

 [![Build Status](https://github.com/rapidez/laravel-scout-elasticsearch/actions/workflows/test-application.yaml/badge.svg)](#) [![Total Downloads](https://camo.githubusercontent.com/e42bec99d71e416dba920c5c84c2e6f081530c47dede4f73fa198737019d2ed8/68747470733a2f2f706f7365722e707567782e6f72672f7261706964657a2f6c61726176656c2d73636f75742d656c61737469637365617263682f642f746f74616c2e737667)](https://packagist.org/packages/rapidez/laravel-scout-elasticsearch) [![Latest Version](https://camo.githubusercontent.com/bc44a4cbc2d4c2dbe7237c831b64d9ef7b74aebb50ccd1f3c7ff623300619d70/68747470733a2f2f706f7365722e707567782e6f72672f7261706964657a2f6c61726176656c2d73636f75742d656c61737469637365617263682f762f737461626c652e737667)](https://packagist.org/packages/rapidez/laravel-scout-elasticsearch) [![License](https://camo.githubusercontent.com/33a48cdd20fdb262f8316afdc1f5a0ffbbb33e2b2a92d43df45fde20578ab66b/68747470733a2f2f706f7365722e707567782e6f72672f7261706964657a2f6c61726176656c2d73636f75742d656c61737469637365617263682f6c6963656e73652e737667)](https://packagist.org/packages/rapidez/laravel-scout-elasticsearch)

This package is based on the great work done by [Serhii Shliakhov](https://github.com/matchish) if you just need ElasticSearch support check out [his project](https://github.com/matchish/laravel-scout-elasticsearch) as this package's main focus is supporting Opensearch indexing via Scout in the same way.

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.

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

[](#two_hearts-features)

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

- Laravel Scout 10.x support
- Laravel Nova 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.
- Parallel import to make your import as fast as possible (in [alpha version](https://github.com/rapidez/laravel-scout-elasticsearch/releases/tag/8.0.0-alpha.1) for now)
- Import all searchable models at once.
- A fully configurable mapping for each model.
- Support for Elasticsearch and Opensearch.

🚀 Installation
--------------

[](#rocket-installation)

Use composer to install the package:

```
composer require rapidez/laravel-scout-elasticsearch

```

Set env variables

```
SCOUT_DRIVER=Rapidez\ScoutElasticSearch\Engines\ElasticSearchEngine

```

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

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

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

Set `ELASTICSEARCH_HOST` env variable

```
ELASTICSEARCH_HOST=host:port

```

or use commas as separator for additional nodes

```
ELASTICSEARCH_HOST=host:port,host:port

```

You can disable SSL verification by setting the following in your env

```
ELASTICSEARCH_SSL_VERIFICATION=false

```

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

Basic OpenSearch support is provided. Add to your .env file OpenSearch as backend.

Default is ElasticSearch

```
SCOUT_SEARCH_BACKEND=opensearch

```

💡 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 Rapidez\ScoutElasticSearch\Searchable\ImportSourceFactory;
...
public function register(): void
{
$this->app->bind(ImportSourceFactory::class, MyImportSourceFactory::class);
```

Here is an example of `MyImportSourceFactory`

```
namespace Rapidez\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');
    }
}
```

You can also customize your indexed data when you save models by leveraging the [`toSearchableArray`](https://laravel.com/docs/9.x/scout#configuring-searchable-data) method provided by Laravel Scout through the `Searchable` trait

#### Example:

[](#example)

```
class Product extends Model
{
    use Searchable;

    /**
     * Get the indexable data array for the model.
     *
     * @return array
     */
    public function toSearchableArray()
    {
        $with = [
            'categories',
        ];

        $this->loadMissing($with);

        return $this->toArray();
    }
}
```

This example will make sure the categories relationship gets always loaded on the model when saving it.

### 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.

🆓 License
---------

[](#free-license)

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

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance54

Moderate activity, may be stable

Popularity28

Limited adoption so far

Community25

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.5% 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

2

Last Release

308d ago

Major Versions

0.0.1 → 1.0.02025-07-14

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/72222911?v=4)[Rapidez](/maintainers/rapidez)[@rapidez](https://github.com/rapidez)

---

Top Contributors

[![matchish](https://avatars.githubusercontent.com/u/818563?v=4)](https://github.com/matchish "matchish (488 commits)")[![hkulekci](https://avatars.githubusercontent.com/u/586318?v=4)](https://github.com/hkulekci "hkulekci (54 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)")[![SineMah](https://avatars.githubusercontent.com/u/8180962?v=4)](https://github.com/SineMah "SineMah (12 commits)")[![Orest-Divintari](https://avatars.githubusercontent.com/u/9808549?v=4)](https://github.com/Orest-Divintari "Orest-Divintari (11 commits)")[![Fayne](https://avatars.githubusercontent.com/u/3952854?v=4)](https://github.com/Fayne "Fayne (7 commits)")[![jalmatari](https://avatars.githubusercontent.com/u/2941118?v=4)](https://github.com/jalmatari "jalmatari (7 commits)")[![yocmen](https://avatars.githubusercontent.com/u/11200640?v=4)](https://github.com/yocmen "yocmen (6 commits)")[![indykoning](https://avatars.githubusercontent.com/u/15870933?v=4)](https://github.com/indykoning "indykoning (6 commits)")[![royduin](https://avatars.githubusercontent.com/u/1703233?v=4)](https://github.com/royduin "royduin (4 commits)")[![hulkur](https://avatars.githubusercontent.com/u/11457732?v=4)](https://github.com/hulkur "hulkur (3 commits)")[![Jade-GG](https://avatars.githubusercontent.com/u/32514269?v=4)](https://github.com/Jade-GG "Jade-GG (2 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (2 commits)")[![rafaucau](https://avatars.githubusercontent.com/u/25438601?v=4)](https://github.com/rafaucau "rafaucau (2 commits)")[![ganicus](https://avatars.githubusercontent.com/u/1510161?v=4)](https://github.com/ganicus "ganicus (2 commits)")[![jackraymund](https://avatars.githubusercontent.com/u/8265560?v=4)](https://github.com/jackraymund "jackraymund (2 commits)")[![youanden](https://avatars.githubusercontent.com/u/183880?v=4)](https://github.com/youanden "youanden (1 commits)")[![AmirrezaNasiri](https://avatars.githubusercontent.com/u/19557224?v=4)](https://github.com/AmirrezaNasiri "AmirrezaNasiri (1 commits)")[![chrysanthos](https://avatars.githubusercontent.com/u/48060191?v=4)](https://github.com/chrysanthos "chrysanthos (1 commits)")

---

Tags

searchlaravelelasticsearchextendedscout

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/rapidez-laravel-scout-elasticsearch/health.svg)](https://phpackages.com/packages/rapidez-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)
