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

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

thomasjsn/laravel-scout-elastic
===============================

Elastic Driver for Laravel Scout

4.0.1(8y ago)1411.5k↓52.9%6[3 issues](https://github.com/thomasjsn/laravel-scout-elastic/issues)[1 PRs](https://github.com/thomasjsn/laravel-scout-elastic/pulls)MITPHPPHP &gt;=5.6.4

Since Sep 29Pushed 6y ago5 watchersCompare

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

READMEChangelog (2)Dependencies (5)Versions (7)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 provides an [Elasticsearch](https://www.elastic.co/products/elasticsearch) driver for Laravel Scout.

Contents
--------

[](#contents)

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

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

[](#installation)

You can install the package via composer:

```
composer require thomasjsn/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,
    ...
    ScoutEngines\Elasticsearch\ElasticsearchProvider::class,
],
```

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

```
php artisan vendor:publish --provider="ScoutEngines\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 Article extends Model
{
    // ...
    public static function mapping() {
        return [
            'location' => [
                'type' => 'geo_point'
            ],
        ];
    }
    // ...
}
```

And then use it in the config file:

```
 'indices' => [

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

The document type, in this example `articles` 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:

```
$articles = Article::search($keywords)
            ->orderBy('id', '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 Article extends Model
{
    // use Searchable;
    use ElasticSearchable;
    // ...
}
```

The package features:

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

```
$articles = Article::elasticSearch('multi_match', $q, [
    'fields' => ['title', 'content', 'tags'],
    '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.

Credits
-------

[](#credits)

- [Erick Tamayo](https://github.com/ericktamayo)
- [Thomas Jensen](https://github.com/thomasjsn)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~61 days

Recently: every ~45 days

Total

6

Last Release

3259d ago

Major Versions

1.0.1 → 2.0.02017-02-01

2.0.0 → 3.0.02017-02-01

3.0.1 → 4.0.02017-08-01

### Community

Maintainers

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

---

Top Contributors

[![ErickTamayo](https://avatars.githubusercontent.com/u/4788817?v=4)](https://github.com/ErickTamayo "ErickTamayo (21 commits)")[![thomasjsn](https://avatars.githubusercontent.com/u/6061006?v=4)](https://github.com/thomasjsn "thomasjsn (16 commits)")[![bbashy](https://avatars.githubusercontent.com/u/1149200?v=4)](https://github.com/bbashy "bbashy (2 commits)")[![kkomelin](https://avatars.githubusercontent.com/u/755066?v=4)](https://github.com/kkomelin "kkomelin (2 commits)")[![shibby](https://avatars.githubusercontent.com/u/291643?v=4)](https://github.com/shibby "shibby (2 commits)")[![pvanhemmen](https://avatars.githubusercontent.com/u/715022?v=4)](https://github.com/pvanhemmen "pvanhemmen (1 commits)")[![tillkruss](https://avatars.githubusercontent.com/u/665029?v=4)](https://github.com/tillkruss "tillkruss (1 commits)")[![fridzema](https://avatars.githubusercontent.com/u/8180660?v=4)](https://github.com/fridzema "fridzema (1 commits)")[![BrianGreenhill](https://avatars.githubusercontent.com/u/1642339?v=4)](https://github.com/BrianGreenhill "BrianGreenhill (1 commits)")

---

Tags

elasticsearchlaravellaravel-scoutphpscoutlaravelelasticsearchelasticscout

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

399672.8k](/packages/jeroen-g-explorer)

PHPackages © 2026

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