PHPackages                             woodfish/laravel-scout-elastic - 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. woodfish/laravel-scout-elastic

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

woodfish/laravel-scout-elastic
==============================

Elastic Driver for Laravel Scout

1.0.0(8y ago)0521PHPPHP &gt;=5.6.4

Since Mar 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/swooder/laravel-scout-elastic)[ Packagist](https://packagist.org/packages/woodfish/laravel-scout-elastic)[ RSS](/packages/woodfish-laravel-scout-elastic/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel Scout Elasticsearch Driver
==================================

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

[![Software License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE.md)[![Travis](https://camo.githubusercontent.com/d94b62a31c0a5047d86e632f16bfb0cc6b200f02cfa83f2cb3b851fc1665ce18/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f74686f6d61736a736e2f6c61726176656c2d73636f75742d656c61737469632e737667)](https://travis-ci.org/thomasjsn/laravel-scout-elastic)[![Packagist](https://camo.githubusercontent.com/7561b63fbd795fdb2b42501f9743ab87653c58f51e48036d83db02539541a388/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74686f6d61736a736e2f6c61726176656c2d73636f75742d656c61737469632e737667)](https://packagist.org/packages/thomasjsn/laravel-scout-elastic)

This package makes is the [Elasticsearch](https://www.elastic.co/products/elasticsearch) driver for Laravel Scout.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

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

[](#installation)

You can install the package via composer:

```
composer require woodfish/laravel-scout-elastic
```

You must add the Scout service provider and the package service provider in your app.php config:

```
// config/app.php
'providers' => [
    ...
    Laravel\Scout\ScoutServiceProvider::class,
    ...
    Woodfish\Elasticsearch\ElasticsearchProvider::class,
],
```

or

```
// lumen bootstrap/app.php
$app->register(Laravel\Scout\ScoutServiceProvider::class);
$app->register(Woodfish\Elasticsearch\ElasticsearchProvider::class);

```

Then you should publish the Elasticsearch configuration using the `vendor:publish` Artisan command.

```
php artisan vendor:publish --provider="Woodfish\Elasticsearch\ElasticsearchProvider"

```

### Setting up Elasticsearch configuration

[](#setting-up-elasticsearch-configuration)

You must have a Elasticsearch server up and running, indices can be created with an Artisan command; see below.

After you've published the Laravel Scout package configuration:

```
// config/scout.php
// Set your driver to elasticsearch
    'driver' => env('SCOUT_DRIVER', 'elasticsearch'),
```

Usage
-----

[](#usage)

### Creating Elasticsearch indexes with proper mapping

[](#creating-elasticsearch-indexes-with-proper-mapping)

You may define custom mappings for Elasticsearch fields in the config. See examples in the [config file](config/elasticsearch.php). If you prefer storing mappings in models, you may create a static public method `mapping()` in each particular model:

```
class Product extends Model
{
    // ...
    public static function mapping() {
        return [
            'title' => [
                'type' => 'text'
            ],
        ];
    }
    // ...
}
```

And then use it in the config file:

```
 'indices' => [

    'realestate' => [
        'settings' => [
            "number_of_shards" => 1,
            "number_of_replicas" => 0,
        ],
        'mappings' => [
            'product' => \App\Product::mapping(),
        ],
    ],
 ]
```

The document type, in this example `product` must match `searchableAs()` for the respective model.

Elasticsearch can set default types to model fields on the first insert if you do not explicitly define them. However; sometimes the defaults are not what you're looking for, or you need to define additional mapping properties.

In that case, we strongly recommend creating indices with proper mappings before inserting any data. For that purpose, there is an Artisan command, called `elastic:make-indices {index}` which creates an index based on the settings in your configuration file.

To create all indices from your config just ignore the `{index}` parameter and run:

```
php artisan elastic:make-indices

```

If the index exists you will be asked if you want to delete and recreate it, or you can use the `--force` flag.

To get information about your existing Elasticsearch indices you may want to use the following command:

```
php artisan elastic:indices

```

### Indexing data

[](#indexing-data)

You may follow instructions from the [official Laravel Scout documentation](https://laravel.com/docs/5.3/scout)to index your data.

### Search

[](#search)

The package supports everything that is provided by Laravel Scout.

The Scout `search` method used the default query method defined in the config file.

Sorting with `orderBy()` method:

```
$products = Product::search($keywords)
            ->orderBy('price', 'desc')
            ->get();
```

#### Elastic specific

[](#elastic-specific)

However, to use the extra Elasticsearch features included in this package, use trait `ElasticSearchable`by adding it to your model instead of `Searchable`:

```
class Product extends Model
{
    // use Searchable;
    use ElasticSearchable;
    // ...
}
```

The package features:

1. The `elasticSearch` method, `elasticSearch($method, $query, array $params = null)`:

```
$products = Product::elasticSearch('multi_match', $q, [
    'fields' => ['title', 'image', 'price'],
    'fuzziness' => 'auto',
    'prefix_length' => 2,
    'operator' => 'AND'
])->get();
```

Parameters are taken from the configuration, for the specific query method, if not supplied. But you may override them.

2. A separate Elasticsearch index for each model.

If you have defined several indices in your [config file](config/elasticsearch.php), you may choose which index a model belongs to by overriding `searchableWithin()` method in your model:

```
public function searchableWithin()
{
    return 'foobar';
}
```

If you do not override `searchableWithin()` in your model, the first index from the config will be used.

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

2991d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f688332d4e259ba48f6f83c6f57c56a498d1d2d99cd3205ba1ef2a87d4ecaf9?d=identicon)[woodfish](/maintainers/woodfish)

---

Top Contributors

[![swooder](https://avatars.githubusercontent.com/u/2777751?v=4)](https://github.com/swooder "swooder (1 commits)")

### Embed Badge

![Health badge](/badges/woodfish-laravel-scout-elastic/health.svg)

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

###  Alternatives

[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[matchish/laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout

7431.6M2](/packages/matchish-laravel-scout-elasticsearch)[mailerlite/laravel-elasticsearch

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

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[zing/laravel-scout-opensearch

Laravel Scout custom engine for OpenSearch

33340.2k](/packages/zing-laravel-scout-opensearch)[baijunyao/laravel-scout-elasticsearch

Elasticsearch Driver for Laravel Scout

8023.7k1](/packages/baijunyao-laravel-scout-elasticsearch)[romanstruk/manticore-scout-engine

Laravel Manticore Scout Engine

4818.1k](/packages/romanstruk-manticore-scout-engine)

PHPackages © 2026

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