brokerexchange / elasticscout
Laravel Scout Driver for Elasticsearch 6 and 7
Requires
- elasticsearch/elasticsearch: ^6.0|^7.0
- laravel/scout: ^7.0
- v10.1.0
- 10.0.x-dev
- v10.0.0
- v9.2.1
- v9.2.0
- v9.1.0
- 9.0.x-dev
- v9.0.2
- v9.0.1
- v9.0.0
- 8.0.x-dev
- v8.0.0
- 7.0.x-dev
- v7.0.1
- v7.0.0
- 6.0.x-dev
- v6.0.12
- v6.0.11
- v6.0.10
- v6.0.9
- v6.0.8
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- 5.0.x-dev
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.0.2
- v3.0.1
- v3.0.0
This package is auto-updated.
Last update: 2024-09-17 01:06:59 UTC
README
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' ] ] ] ], ], ]; }