Skip to content

spiritinlife/elastic-scout-driver-plus

 
 

Repository files navigation

Buy Me A Coffee


Extension for Elastic Scout Driver.

Contents

Features

Elastic Scout Driver Plus supports:

Compatibility

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

  • PHP 7.2-8.0
  • Elasticsearch 7.0-7.10
  • Laravel 6.x-8.x
  • Laravel Scout 7.x-8.x
  • Elastic Scout Driver 1.x

Installation

The library can be installed via Composer:

composer require babenkoivan/elastic-scout-driver-plus

Note, that the library doesn't work without Elastic Scout Driver. If it's not installed yet, please follow the installation steps described here. If you are already using Elastic Scout Driver, I recommend you to update it before installing Elastic Scout Driver Plus:

composer update babenkoivan/elastic-scout-driver

If you want to use Elastic Scout Driver Plus with Lumen framework refer to this guide.

Usage

Elastic Scout Driver Plus comes with a new trait QueryDsl, which you need to add in your model to activate advanced search functionality:

class Book extends Model
{
    use Searchable;
    use QueryDsl;
}

This trait adds a bunch of factory methods in your model: boolSearch(), matchSearch(), rawSearch(), etc. Each method creates a search request builder for specific query type. For example, if you want to make a match query use matchSearch() method:

$searchResult = Book::matchSearch()
    ->field('title')
    ->query('My book')
    ->fuzziness('AUTO')
    ->size(10)
    ->execute();

Choose factory method depending on the query type you wish to perform:

If there is no method for the query type you need, you can use rawSearch():

$searchResult = Book::rawSearch()
    ->query(['match' => ['title' => 'The Book']])
    ->execute();

It is important to know, that all search request builders share the same generic methods, which provide such basic functionality as sorting, highlighting, etc. Check the full list of available generic methods and the usage examples here.

Finally, refer to this page to get familiar with $searchResult object, pagination and more.

Custom routing

In case you need custom es routing you can use the trait ShardRouting.

Override the method getRoutingPath to specify a document field that will be used to route the document to a shard. By default getRoutingPath uses getScoutKeyName.

Dot notation is also supported.

class MyModel extends Model
{
    use ShardRouting;

    public function getRoutingPath(): string
    {
        return 'user.id';
    }
}

This will allow for custom routing on index and delete operations.

About

Extension for Elastic Scout Driver

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 98.7%
  • Makefile 1.3%