gtk/laravel-scout-elasticsearch

Elasticsearch driver for Laravel Scout

dev-master 2018-04-16 03:41 UTC

This package is not auto-updated.

Last update: 2024-04-14 03:01:29 UTC


README

This package provides a Elasticsearch driver for Laravel Scout.

Installation

First, install Laravel Scout Elasticsearch via the Composer package manager:

composer require gtk/laravel-scout-elasticsearch

When using the Elasticsearch driver, you should configure your Elasticsearch hosts in your config/scout.php configuration file.

'elasticsearch' => [
    'hosts' => [
        env('ELASTICSEARCH_HOST', 'http://localhost:9200'),
    ],
],

Usage

Default usage can be found on the Laravel Scout documentation.

You may begin searching a model using the search method. The search method accepts a single string that will be used to search your models. You should then chain the get method onto the search query to retrieve the Eloquent models that match the given search query:

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

In addition, the search method accepts an array that will be used as an Elasticsearch raw query to perform an advanced search:

$orders = App\Order::search([
    'query' => [
        'query_string' => [
            'query' => 'Star Trek',
        ],
    ],
])->get();

You can check Elastic document for more information.

License

Laravel Scout Elasticsearch is open-sourced software licensed under the MIT license.