{"id":15501610,"url":"https://github.com/babenkoivan/elastic-scout-driver","last_synced_at":"2025-05-16T04:00:19.074Z","repository":{"id":37509170,"uuid":"236170899","full_name":"babenkoivan/elastic-scout-driver","owner":"babenkoivan","description":"Elasticsearch driver for Laravel Scout","archived":false,"fork":false,"pushed_at":"2024-06-18T07:09:10.000Z","size":3933,"stargazers_count":266,"open_issues_count":0,"forks_count":32,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-08T14:06:36.351Z","etag":null,"topics":["driver","elastic","elasticsearch","laravel","php","scout"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/babenkoivan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"ivanbabenko","custom":["https://paypal.me/babenkoi"]}},"created_at":"2020-01-25T13:01:37.000Z","updated_at":"2025-03-26T10:38:08.000Z","dependencies_parsed_at":"2024-06-18T08:29:44.417Z","dependency_job_id":"54553bd0-5e44-4d1c-9d3b-4faa96b2bb48","html_url":"https://github.com/babenkoivan/elastic-scout-driver","commit_stats":{"total_commits":105,"total_committers":5,"mean_commits":21.0,"dds":0.03809523809523807,"last_synced_commit":"f3791521fb3216850335f491a1461a16738125cd"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Felastic-scout-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Felastic-scout-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Felastic-scout-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/babenkoivan%2Felastic-scout-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/babenkoivan","download_url":"https://codeload.github.com/babenkoivan/elastic-scout-driver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464890,"owners_count":22075570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["driver","elastic","elasticsearch","laravel","php","scout"],"created_at":"2024-10-02T09:05:01.633Z","updated_at":"2025-05-16T04:00:18.920Z","avatar_url":"https://github.com/babenkoivan.png","language":"PHP","funding_links":["https://ko-fi.com/ivanbabenko","https://paypal.me/babenkoi"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg width=\"400px\" src=\"logo.gif\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://packagist.org/packages/babenkoivan/elastic-scout-driver\"\u003e\u003cimg src=\"https://poser.pugx.org/babenkoivan/elastic-scout-driver/v/stable\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/babenkoivan/elastic-scout-driver\"\u003e\u003cimg src=\"https://poser.pugx.org/babenkoivan/elastic-scout-driver/downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/babenkoivan/elastic-scout-driver\"\u003e\u003cimg src=\"https://poser.pugx.org/babenkoivan/elastic-scout-driver/license\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/babenkoivan/elastic-scout-driver-plus/actions?query=workflow%3ATests\"\u003e\u003cimg src=\"https://github.com/babenkoivan/elastic-scout-driver-plus/workflows/Tests/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/babenkoivan/elastic-scout-driver/actions?query=workflow%3A%22Code+style%22\"\u003e\u003cimg src=\"https://github.com/babenkoivan/elastic-scout-driver/workflows/Code%20style/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/babenkoivan/elastic-scout-driver/actions?query=workflow%3A%22Static+analysis%22\"\u003e\u003cimg src=\"https://github.com/babenkoivan/elastic-scout-driver/workflows/Static%20analysis/badge.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://paypal.me/babenkoi\"\u003e\u003cimg src=\"https://img.shields.io/badge/donate-paypal-blue\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://ko-fi.com/ivanbabenko\" target=\"_blank\"\u003e\u003cimg src=\"https://ko-fi.com/img/githubbutton_sm.svg\" alt=\"Support the project!\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\nElasticsearch driver for Laravel Scout.\n\n## Contents\n\n* [Compatibility](#compatibility)\n* [Installation](#installation) \n* [Configuration](#configuration)\n* [Basic Usage](#basic-usage)\n* [Advanced Search](#advanced-search)\n* [Migrations](#migrations)\n* [Pitfalls](#pitfalls)\n\n## Compatibility\n\nThe current version of Elastic Scout Driver has been tested with the following configuration:\n\n* PHP 8.2\n* Elasticsearch 8.x\n* Laravel 11.x\n* Laravel Scout 10.x\n\nIf your project uses older Laravel (or PHP) version check [the previous major version](https://github.com/babenkoivan/elastic-scout-driver/tree/v3.1.0#compatibility) of the package.\n\n## Installation\n\nThe library can be installed via Composer:\n\n```bash\ncomposer require babenkoivan/elastic-scout-driver\n```\n\n**Note**, that this library is just a driver for Laravel Scout, don't forget to install it beforehand:\n```bash\ncomposer require laravel/scout\n``` \n\nAfter Scout has been installed, publish its configuration file using:\n\n```bash\nphp artisan vendor:publish --provider=\"Laravel\\Scout\\ScoutServiceProvider\"\n```\n\nThen, change the `driver` option in the `config/scout.php` file to `elastic`:\n\n```php\n// config/scout.php\n\n'driver' =\u003e env('SCOUT_DRIVER', 'elastic'),\n```\n\nIf you want to use Elastic Scout Driver with [Lumen framework](https://lumen.laravel.com/) check [this guide](https://github.com/babenkoivan/elastic-scout-driver/wiki/Lumen-Installation).\n\n## Configuration\n\nElastic Scout Driver uses [babenkoivan/elastic-client](https://github.com/babenkoivan/elastic-client) as a dependency.\nTo change the client settings you need to publish the configuration file first:\n\n```bash\nphp artisan vendor:publish --provider=\"Elastic\\Client\\ServiceProvider\"\n```\n\nIn the newly created `config/elastic.client.php` file you can define the default connection name using configuration hashes. \nPlease, refer to the [elastic-client documentation](https://github.com/babenkoivan/elastic-client) for more details.\n\nElastic Scout Driver itself has only one configuration option at the moment - `refresh_documents`. \nIf it's set to `true` (`false` by default) documents are indexed immediately, which might be handy for testing.   \n\nYou can configure `refresh_documents` in the `config/elastic.scout_driver.php` file after publishing it with the following command:\n\n```bash\nphp artisan vendor:publish --provider=\"Elastic\\ScoutDriver\\ServiceProvider\"\n``` \n\nAt last, do not forget, that with Scout you can configure the searchable data, the model id and the index name.\nCheck [the official Scout documentation](https://laravel.com/docs/master/scout#configuration) for more details.\n\n\u003e Note, that the `_id` field can't be part of the searchable data, so make sure the field is excluded or renamed \n\u003e in the `toSearchableArray` method in case you are using MongoDB as the database.\n\n## Basic usage\n\nElastic driver uses Elasticsearch [query string](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html)\nwrapped in a [bool query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html) \nunder the hood. It means that you can use [mini-language syntax](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax)\nwhen searching a model:\n\n```php\n$orders = App\\Order::search('title:(Star OR Trek)')-\u003eget();\n```\n\nWhen the query string is omitted, the [match all query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html) \nis used:\n```php\n$orders = App\\Order::search()-\u003ewhere('user_id', 1)-\u003eget();\n``` \n\nPlease refer to [the official Laravel Scout documentation](https://laravel.com/docs/master/scout)\nfor more details and usage examples.\n\n## Advanced Search\n\nIn case the basic search doesn't cover your project needs check [Elastic Scout Driver Plus](https://github.com/babenkoivan/elastic-scout-driver-plus),\nwhich extends standard Scout search capabilities by introducing advanced query builders. These builders give you \npossibility to use compound queries, custom filters and sorting, highlights and more.\n\n## Migrations\n\nIf you are looking for a way to control Elasticsearch index schema programmatically check [Elastic Migrations](https://github.com/babenkoivan/elastic-migrations).\nElastic Migrations allow you to modify application's index schema and share it across multiple environments with the same ease, \nthat gives you Laravel database migrations.\n\n## Pitfalls\n\nThere are few things, which are slightly different from other Scout drivers:\n* As you probably know, Scout only indexes fields, which are returned by the `toSearchableArray` method. \nElastic driver indexes a model even when `toSearchableArray` returns an empty array. You can change this behaviour by \noverwriting the `shouldBeSearchable` method of your model:\n```php\npublic function shouldBeSearchable()\n{\n    return count($this-\u003etoSearchableArray()) \u003e 0;\n}\n```\n* Raw search returns an instance of `SearchResult` class (see [Elastic Adapter](https://github.com/babenkoivan/elastic-adapter#search)):\n```php\n$searchResult = App\\Order::search('Star Trek')-\u003eraw();\n``` \n* To be compatible with other drivers and to not expose internal implementation of the engine, Elastic driver ignores callback\nparameter of the `search` method:\n```php\nApp\\Order::search('Star Trek', function () {\n    // this will not be triggered\n})-\u003eget()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabenkoivan%2Felastic-scout-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbabenkoivan%2Felastic-scout-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbabenkoivan%2Felastic-scout-driver/lists"}