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

ActiveLibrary

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

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

v1.0.6(4mo ago)2389↓100%1MITPHPPHP ^8.1

Since Oct 15Pushed 4mo 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 1mo 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

41

—

FairBetter than 89% of packages

Maintenance74

Regular maintenance activity

Popularity20

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

146d 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

[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[romanstruk/manticore-scout-engine

Laravel Manticore Scout Engine

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

Rapidez Core

1820.7k53](/packages/rapidez-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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