PHPackages                             haridarshan/opensearch-scout-driver - 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. haridarshan/opensearch-scout-driver

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

haridarshan/opensearch-scout-driver
===================================

OpenSearch driver for Laravel Scout

v1.0.0(2y ago)03.8k↓25%1MITPHPPHP ^7.4 || ^8.0

Since Mar 9Pushed 2y agoCompare

[ Source](https://github.com/haridarshan/opensearch-scout-driver)[ Packagist](https://packagist.org/packages/haridarshan/opensearch-scout-driver)[ RSS](/packages/haridarshan-opensearch-scout-driver/feed)WikiDiscussions master Synced 1mo ago

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

OpenSearch Scout Driver
=======================

[](#opensearch-scout-driver)

---

OpenSearch driver for Laravel Scout.

Contents
--------

[](#contents)

- [Compatibility](#compatibility)
- [Installation](#installation)
- [Configuration](#configuration)
- [Basic Usage](#basic-usage)
- [Advanced Search](#advanced-search)
- [Migrations](#migrations)
- [Pitfalls](#pitfalls)

Compatibility
-------------

[](#compatibility)

The current version of OpenSearch Scout Driver has been tested with the following configuration:

- PHP 7.4-8.x
- OpenSearch 2.x
- Laravel 7.x-10.x
- Laravel Scout 7.x-10.x

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

[](#installation)

The library can be installed via Composer:

```
composer require haridarshan/opensearch-scout-driver
```

**Note**, that this library is just a driver for Laravel Scout, don't forget to install it beforehand:

```
composer require laravel/scout
```

After Scout has been installed, publish its configuration file using:

```
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
```

Then, change the `driver` option in the `config/scout.php` file to `opensearch`:

```
// config/scout.php

'driver' => env('SCOUT_DRIVER', 'opensearch'),
```

If you want to use OpenSearch Scout Driver with [Lumen framework](https://lumen.laravel.com/) check [this guide](https://github.com/haridarshan/opensearch-scout-driver/wiki/Lumen-Installation).

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

[](#configuration)

OpenSearch Scout Driver uses [haridarshan/opensearch-client](https://github.com/haridarshan/opensearch-client) as a dependency. To change the client settings you need to publish the configuration file first:

```
php artisan vendor:publish --provider="OpenSearch\Laravel\Client\ServiceProvider"
```

In the newly created `config/opensearch.client.php` file you can define the default connection name using configuration hashes. Please, refer to the [opensearch-client documentation](https://github.com/haridarshan/opensearch-client) for more details.

OpenSearch Scout Driver itself has only one configuration option at the moment - `refresh_documents`. If it's set to `true` (`false` by default) documents are indexed immediately, which might be handy for testing.

You can configure `refresh_documents` in the `config/opensearch.scout_driver.php` file after publishing it with the following command:

```
php artisan vendor:publish --provider="OpenSearch\ScoutDriver\ServiceProvider"
```

At last, do not forget, that with Scout you can configure the searchable data, the model id and the index name. Check [the official Scout documentation](https://laravel.com/docs/master/scout#configuration) for more details.

> Note, that the `_id` field can't be part of the searchable data, so make sure the field is excluded or renamed in the `toSearchableArray` method in case you are using MongoDB as the database.

Basic usage
-----------

[](#basic-usage)

OpenSearch driver uses OpenSearch [query string](https://opensearch.org/docs/latest/query-dsl/full-text/query-string/)wrapped in a [bool query](https://opensearch.org/docs/latest/query-dsl/compound/bool/)under the hood. It means that you can use [mini-language syntax](https://opensearch.org/docs/latest/query-dsl/full-text/query-string/#query-string-syntax)when searching a model:

```
$orders = App\Order::search('title:(Star OR Trek)')->get();
```

When the query string is omitted, the [match all query](https://opensearch.org/docs/latest/query-dsl/match-all/)is used:

```
$orders = App\Order::search()->where('user_id', 1)->get();
```

Please refer to [the official Laravel Scout documentation](https://laravel.com/docs/master/scout)for more details and usage examples.

Advanced Search
---------------

[](#advanced-search)

In case the basic search doesn't cover your project needs check [OpenSearch Scout Driver Plus](https://github.com/haridarshan/opensearch-scout-driver-plus), which extends standard Scout search capabilities by introducing advanced query builders. These builders give you possibility to use compound queries, custom filters and sorting, highlights and more.

Migrations
----------

[](#migrations)

If you are looking for a way to control OpenSearch index schema programmatically check [OpenSearch Migrations](https://github.com/haridarshan/opensearch-migrations). OpenSearch Migrations allow you to modify application's index schema and share it across multiple environments with the same ease, that gives you Laravel database migrations.

Pitfalls
--------

[](#pitfalls)

There are few things, which are slightly different from other Scout drivers:

- As you probably know, Scout only indexes fields, which are returned by the `toSearchableArray` method. OpenSearch driver indexes a model even when `toSearchableArray` returns an empty array. You can change this behaviour by overwriting the `shouldBeSearchable` method of your model:

```
public function shouldBeSearchable()
{
    return count($this->toSearchableArray()) > 0;
}
```

- Raw search returns an instance of `SearchResult` class (see [OpenSearch Adapter](https://github.com/haridarshan/opensearch-adapter#search)):

```
$searchResult = App\Order::search('Star Trek')->raw();
```

- To be compatible with other drivers and to not expose internal implementation of the engine, OpenSearch driver ignores callback parameter of the `search` method:

```
App\Order::search('Star Trek', function () {
    // this will not be triggered
})->get()
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90% 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

800d ago

### Community

Maintainers

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

---

Top Contributors

[![babenkoivan](https://avatars.githubusercontent.com/u/25812954?v=4)](https://github.com/babenkoivan "babenkoivan (99 commits)")[![haridarshan](https://avatars.githubusercontent.com/u/1327607?v=4)](https://github.com/haridarshan "haridarshan (7 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (1 commits)")[![spiritinlife](https://avatars.githubusercontent.com/u/6434983?v=4)](https://github.com/spiritinlife "spiritinlife (1 commits)")[![stevebauman](https://avatars.githubusercontent.com/u/6421846?v=4)](https://github.com/stevebauman "stevebauman (1 commits)")[![wbridgett](https://avatars.githubusercontent.com/u/7139214?v=4)](https://github.com/wbridgett "wbridgett (1 commits)")

---

Tags

phplaravelopensearchdriverscout

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/haridarshan-opensearch-scout-driver/health.svg)

```
[![Health](https://phpackages.com/badges/haridarshan-opensearch-scout-driver/health.svg)](https://phpackages.com/packages/haridarshan-opensearch-scout-driver)
```

###  Alternatives

[babenkoivan/elastic-scout-driver

Elasticsearch driver for Laravel Scout

2773.8M5](/packages/babenkoivan-elastic-scout-driver)[babenkoivan/elastic-scout-driver-plus

Extension for Elastic Scout Driver

2862.8M1](/packages/babenkoivan-elastic-scout-driver-plus)[romangrinev/laravel-opensearch-engine

Custom Laravel Scout OpenSearch Engine

1319.8k](/packages/romangrinev-laravel-opensearch-engine)

PHPackages © 2026

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