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

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

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

A Laravel Scout driver for Elasticsearch with developer-friendly syntax.

v1.0.6(6mo ago)23971MITPHPPHP ^8.1

Since Oct 15Pushed 6mo agoCompare

[ Source](https://github.com/abrbit/Laravel-Scout-Elasticsearch)[ Packagist](https://packagist.org/packages/abrbit/laravel-scout-elasticsearch)[ RSS](/packages/abrbit-laravel-scout-elasticsearch/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (2)Versions (8)Used By (0)

🧠 Abrbit Laravel Scout Elasticsearch Driver
===========================================

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

**A developer-friendly Laravel Scout driver for Elasticsearch — built for distributed, scalable, and clean search experiences.**
Crafted with ❤️ by the [Abrbit](https://abrbit.com) team.

---

🚀 Features
----------

[](#-features)

✅ Plug-and-play with Laravel Scout
✅ Uses official Elasticsearch REST API
✅ Auto-maps documents &amp; IDs for distributed clusters
✅ Supports multi-field search (e.g., `title` + `description`)
✅ Fully configurable via `config/services.php`
✅ Developer-friendly syntax — clean and minimal

---

📦 Installation
--------------

[](#-installation)

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

Then register your search service endpoint and credentials in `.env`:

```
SEARCH_URL=https://search.services.abrbit.com
SEARCH_TOKEN=your-api-token
```

---

⚙️ Configuration
----------------

[](#️-configuration)

In your `config/scout.php`, set the driver to `abrbit`:

```
'driver' => 'abrbit',
```

And in `config/services.php`, add:

```
'search' => [
    'url' => env('SEARCH_URL', 'https://example.com'),
    'token' => env('SEARCH_TOKEN'),
],
```

---

🧩 Usage
-------

[](#-usage)

You can use Laravel Scout’s native methods directly:

```
use App\Models\Song;

// Paginate results
$songs = Song::search('عشق')->paginate(20);

// Get paginated raw source data
$songs = Song::search('عشق')->searchSource();
```

1. Get Eloquent Models (get())
------------------------------

[](#1-get-eloquent-models-get)

This is the standard Scout method. It returns an Eloquent Collection of your models, hydrated from the database based on the IDs returned from the search.

```
use App\Models\Song;

// Returns a Collection of Song models
$songs = Song::search('عشق')->get();

// Paginate results
$songs = Song::search('عشق')->paginate(20);
```

2. Get Raw Source Data (getSource())
------------------------------------

[](#2-get-raw-source-data-getsource)

This is the recommended method for APIs or when you don't need full Eloquent models. It returns a clean array containing only the \_source data directly from Elasticsearch, avoiding any database queries and providing excellent performance.

```
// Returns a clean array of the data stored in Elasticsearch
$songs = Song::search('شام')->getSource();

/*
Example Output:
[
    [
        "id" => 1,
        "title" => "شام غریبان",
        "description" => "..."
    ],
    [
        "id" => 2,
        "title" => "شام مهتاب",
        "description" => "..."
    ]
]
*/
```

3. Get Paginated Raw Source Data (searchSource())
-------------------------------------------------

[](#3-get-paginated-raw-source-data-searchsource)

This method is similar to `getSource()`, but it supports pagination and is optimized for partial and short-term searches (e.g., 2 characters). It returns a paginated array of source data.

```
// Returns a paginated array of the data stored in Elasticsearch
$songs = Song::search('شام')->searchSource();

// You can also specify the page and number of items per page
$songs = Song::search('شام')->searchSource($perPage = 15, $page = 2);

/*
Example Output:
[
    'data' => [
        [
            "id" => 1,
            "title" => "شام غریبان",
            "description" => "..."
        ],
        [
            "id" => 2,
            "title" => "شام مهتاب",
            "description" => "..."
        ]
    ],
    'total' => 100,
    'per_page' => 15,
    'current_page' => 2,
]
*/
```

4. Get the Raw Elasticsearch Response (raw())
---------------------------------------------

[](#4-get-the-raw-elasticsearch-response-raw)

This method returns the entire, unprocessed JSON response from Elasticsearch. It is useful for debugging or when you need access to metadata like took, \_shards, or max\_score.

```
// Returns the complete, raw response from the search engine
$rawResponse = Song::search('شام')->raw();
```

Your Eloquent model only needs to implement the `Searchable` trait:

```
use Laravel\Scout\Searchable;
use Illuminate\Database\Eloquent\Model;

class Song extends Model
{
    use Searchable;

    protected $fillable = ['title', 'description'];

    public function toSearchableArray()
    {
        return [
            'id' => $this->getKey(),
            'title' => $this->title,
            'description' => $this->description,
        ];
    }
}
```

---

🔍 Example Query
---------------

[](#-example-query)

Here’s what an example query looks like under the hood:

```
{
  "from": 0,
  "size": 20,
  "query": {
    "multi_match": {
      "fields": ["title", "description"],
      "query": "شام"
    }
  }
}
```

---

🧠 How It Works
--------------

[](#-how-it-works)

`AbrbitSearchEngine` is a custom Laravel Scout engine that:

- Sends search requests to your Elasticsearch instance.
- Handles `_id` assignment automatically by Elasticsearch.
- Supports distributed, multi-tenant indexes like `tenant_songs` or `user_posts`.
- Maps `_source` data back into Eloquent models seamlessly.

Example search response:

```
{
  "id": "Swv5oJkBk5ZOaUeK3x_O",
  "title": "شام غریبان",
  "description": "نوحه زیبای حاج محمود کریمی",
  "score": 6.6
}
```

---

🧰 Developer Notes
-----------------

[](#-developer-notes)

- Designed for **SaaS and multi-tenant** applications.
- Compatible with any REST-compatible Elasticsearch cluster (v8+ recommended).
- Works perfectly with Laravel Scout’s indexing pipeline.

---

🧑‍💻 Contributing
----------------

[](#‍-contributing)

We welcome contributions!
Feel free to open issues or submit pull requests.

---

⚖️ License
----------

[](#️-license)

Released under the [MIT License](LICENSE).

---

🌐 About Abrbit
--------------

[](#-about-abrbit)

Abrbit provides modern cloud infrastructure and SaaS services —
from DNS &amp; mail hosting to AI, storage, and classroom platforms.

> 💡 Visit us at [abrbit.com](https://abrbit.com)

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance67

Regular maintenance activity

Popularity17

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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 ~11 days

Total

7

Last Release

192d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/65efe9d0d593fc2fd49de315015f32d2cde3027f41b4ce1170c35c5ccf6bdd98?d=identicon)[vchakoshy](/maintainers/vchakoshy)

---

Top Contributors

[![hamedrajabpour1](https://avatars.githubusercontent.com/u/47815775?v=4)](https://github.com/hamedrajabpour1 "hamedrajabpour1 (16 commits)")[![vchakoshy](https://avatars.githubusercontent.com/u/578538?v=4)](https://github.com/vchakoshy "vchakoshy (6 commits)")[![amirdm81](https://avatars.githubusercontent.com/u/30548895?v=4)](https://github.com/amirdm81 "amirdm81 (1 commits)")[![hamedrajabpour](https://avatars.githubusercontent.com/u/225726774?v=4)](https://github.com/hamedrajabpour "hamedrajabpour (1 commits)")

### Embed Badge

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

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

###  Alternatives

[algolia/scout-extended

Scout Extended extends Laravel Scout adding algolia-specific features

4186.6M6](/packages/algolia-scout-extended)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

399654.3k](/packages/jeroen-g-explorer)[rapidez/core

Rapidez Core

1822.4k65](/packages/rapidez-core)[romanstruk/manticore-scout-engine

Laravel Manticore Scout Engine

4820.2k](/packages/romanstruk-manticore-scout-engine)[namoshek/laravel-scout-database

A generic Laravel Scout driver which performs full-text search on indexed model data using an SQL database as storage backend. Indexed data is stored in normalized form, allowing efficient search.

1969.6k](/packages/namoshek-laravel-scout-database)

PHPackages © 2026

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