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

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

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

Laravel Scout driver for Elasticsearch with advanced features like zero-downtime reindexing and lazy backfill

v1.0.4(9mo ago)075MITPHPPHP ^8.2

Since Aug 12Pushed 9mo agoCompare

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

READMEChangelogDependencies (4)Versions (6)Used By (0)

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

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

A powerful Laravel Scout driver for Elasticsearch with advanced features like zero-downtime reindexing and lazy backfill.

Features
--------

[](#features)

- **Elasticsearch Integration**: Full integration with Elasticsearch 8.x
- **Zero-Downtime Reindexing**: Update mappings without service interruption
- **Lazy Backfill**: Efficiently add new fields to existing documents
- **Advanced Mapping**: Custom field mapping support
- **Authentication**: Basic authentication and SSL support
- **Artisan Commands**: Built-in commands for common operations

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

[](#installation)

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

Configuration
-------------

[](#configuration)

Add the following to your `.env` file:

```
SCOUT_DRIVER=elasticsearch
ELASTICSEARCH_HOST=https://your-elasticsearch-host:9200
ELASTICSEARCH_USER=elastic
ELASTICSEARCH_PASS=your-password
ELASTICSEARCH_INDEX_PREFIX=laravel_scout
ELASTICSEARCH_SSL_VERIFICATION=false
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

1. **Configure Scout** in `config/scout.php`:

```
'elasticsearch' => [
    'hosts' => [
        env('ELASTICSEARCH_HOST', 'localhost:9200'),
    ],
    'username' => env('ELASTICSEARCH_USER', 'elastic'),
    'password' => env('ELASTICSEARCH_PASS', ''),
    'index_prefix' => env('ELASTICSEARCH_INDEX_PREFIX', 'laravel_scout'),
    'number_of_shards' => env('ELASTICSEARCH_NUMBER_OF_SHARDS', 1),
    'number_of_replicas' => env('ELASTICSEARCH_NUMBER_OF_REPLICAS', 0),
    'ssl_verification' => env('ELASTICSEARCH_SSL_VERIFICATION', false),
],
```

2. **Make your model searchable**:

```
use Laravel\Scout\Searchable;

class Post extends Model
{
    use Searchable;

    public function toSearchableArray()
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'content' => $this->content,
            'misc' => $this->misc ?? 'others',
        ];
    }

    public function getSearchableMapping()
    {
        return [
            'properties' => [
                'id' => ['type' => 'integer'],
                'title' => [
                    'type' => 'text',
                    'analyzer' => 'standard',
                    'fields' => [
                        'keyword' => ['type' => 'keyword']
                    ]
                ],
                'content' => ['type' => 'text'],
                'misc' => [
                    'type' => 'text',
                    'analyzer' => 'standard',
                    'fields' => [
                        'keyword' => ['type' => 'keyword']
                    ]
                ],
            ]
        ];
    }
}
```

### Artisan Commands

[](#artisan-commands)

#### Test Connection

[](#test-connection)

```
php artisan scout:test-elasticsearch
```

#### Create Index

[](#create-index)

```
php artisan scout:index posts
```

#### Import Data

[](#import-data)

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

#### Zero-Downtime Reindex

[](#zero-downtime-reindex)

```
php artisan scout:reindex-zero-downtime "App\Models\Post"
```

#### Lazy Backfill (Add New Fields)

[](#lazy-backfill-add-new-fields)

```
# Add a new field with default value
php artisan scout:lazy-backfill misc --type=text

# Add a keyword field
php artisan scout:lazy-backfill priority --type=keyword

# Force backfill all documents
php artisan scout:lazy-backfill status --type=keyword --force
```

#### Add New Fields and Reindex

[](#add-new-fields-and-reindex)

```
# Add new fields and reindex the model
php artisan scout:add-fields-reindex "App\Models\Post"
```

#### Large Dataset Reindexing

[](#large-dataset-reindexing)

```
# Reindex large datasets with batch processing
php artisan scout:reindex-large-dataset "App\Models\Post" --batch-size=1000
```

#### Seed Large Dataset

[](#seed-large-dataset)

```
# Seed large datasets for testing
php artisan scout:seed-large-dataset "App\Models\Post" --count=10000
```

Advanced Features
-----------------

[](#advanced-features)

### Zero-Downtime Reindexing

[](#zero-downtime-reindexing)

This feature allows you to update Elasticsearch mappings without downtime:

1. Creates a new index with updated mapping
2. Reindexes all data from the old index
3. Switches to the new index seamlessly
4. Maintains the original index name

### Lazy Backfill

[](#lazy-backfill)

Efficiently add new fields to existing documents:

1. Adds the field to the index mapping
2. Uses `update_by_query` to populate existing documents
3. Sets default values for new fields
4. No full reindex required

### Custom Field Types

[](#custom-field-types)

Supported field types:

- `text` - Full-text search with keyword sub-field
- `keyword` - Exact match searches
- `integer` - Numeric searches
- `date` - Date range queries
- `boolean` - Boolean filters
- `float` - Decimal searches

Contributing
------------

[](#contributing)

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests
5. Submit a pull request

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance58

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

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

Every ~0 days

Total

5

Last Release

273d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

searchlaravelelasticsearchdriverscout

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

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