brokerexchange/elasticscout

Laravel Scout Driver for Elasticsearch 5.x
794 17
Install
composer require brokerexchange/elasticscout
Latest Version:v10.1.0
License:MIT
Last Updated:Jan 8, 2025
Links: GitHub  ·  Packagist
Maintainer: Artistan

Latest Stable Version Latest Unstable Version Total Downloads License composer.lock

ElasticScout

A Laravel Scout Driver for Elasticsearch 6

Overview

ElasticScout is a Laravel Scout Elasticsearch 6 compatible engine. It makes critical changes to the old Elasticseach Scout Engine, as well as adds new functionality.

The ElasticScout engine includes an Elasticsearch Query Builder which can be used to create elaborate custom queries and aggregations, allowing full use of Elasticsearch within the Laravel/Scout Paradigm.

License

ElasticScout is released under the MIT Open Source License, https://opensource.org/licenses/MIT

Copyright

ElasticScout © Broker Exchange Network 2018

Installation

  • Run composer require command composer require brokerexchange/elasticscout
  • Configure Elasticsearch Host (default: localhost:9200)
   ELASTICSEARCH_HOST='elastic1.host.com:9200,elastic2.host.com:9200'
  • Add trait to desired model
   use ElasticScout\Searchable;

Usage

   //create search/query object
   $search = $article->search()
       ->boolean()
       ->should(DSL::match('title',$request->input('query')))
       ->should(DSL::match('body',$request->input('query')))
       ->highlight(['body','title'])
       ->filter(DSL::term('published', 1))
       ->aggregate(Agg::terms('categories', 'category.name'));
       
   //fire the search
   $articles = $search->paginate();
       
   //retrieve aggregation results
   $categories = $search->aggregation('categories');
   
   //retrieve highlight results for title field of first result article
   $firstArticleTitleHighlights = $articles->first()->highlight('title');
   

Mappings

You may set a custom mapping by simply defining a "mapping" method on your model.

   public function mappings()
   {
       return [
           $this->searchableType() => [
               'properties' => [
                   'name' => [
                       'type' => 'text',
                       'fields' => [
                           'keyword' => [
                               'type' => 'keyword',
                           ],
                           'autocomplete' => [
                               'type' => 'text',
                               'analyzer' => 'autocomplete',
                               'search_analyzer' => 'autocomplete_search',
                           ],
                       ],
                   ],
               ]
           ]
       ]
   }

Settings

You may create custom settings and analyzers by creating a "settings" method on the model.

   public function settings()
   {
     return [
         'index' => [
             'analysis' => [
                 'analyzer' => [
                     'autocomplete' => [
                         'tokenizer' => 'autocomplete',
                         'filter' => [
                             'lowercase',
                         ],
                     ],
                     'autocomplete_search' => [
                         'tokenizer' => 'lowercase',
                     ],
                 ],
                 'tokenizer' => [
                     'autocomplete' => [
                         'type' => 'edge_ngram',
                         'min_gram' => 1,
                         'max_gram' => 15,
                         'token_chars' => [
                             'letter'
                         ]
                     ]
                 ]
             ],
         ],
     ];
   }

Related Packages

matchish/laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout

1,855,340 742
jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

758,877 399
lunarphp/scout-database-engine

Laravel Scout engine to allow full searching in MySQL and PostgreSQL.

51,087 5
baijunyao/laravel-scout-elasticsearch

Elasticsearch Driver for Laravel Scout

23,936 79
iverberk/larasearch

Elasticsearch enabled Eloquent models

15,552 222

Version History

Version Released License
v10.1.0 MIT
v10.0.0 MIT
v9.2.1 MIT
v9.2.0 MIT
v9.1.0 MIT