https://github.com/brokerexchange/elasticscout
Laravel Scout Driver for Elasticsearch
https://github.com/brokerexchange/elasticscout
elasticsearch elasticsearch-query-dsl laravel-scout php query-builder
Last synced: about 1 year ago
JSON representation
Laravel Scout Driver for Elasticsearch
- Host: GitHub
- URL: https://github.com/brokerexchange/elasticscout
- Owner: BrokerExchange
- License: mit
- Created: 2016-11-03T12:11:11.000Z (over 9 years ago)
- Default Branch: 10.0
- Last Pushed: 2025-01-08T22:24:37.000Z (over 1 year ago)
- Last Synced: 2025-06-24T04:09:35.477Z (about 1 year ago)
- Topics: elasticsearch, elasticsearch-query-dsl, laravel-scout, php, query-builder
- Language: PHP
- Homepage:
- Size: 99.6 KB
- Stars: 17
- Watchers: 6
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
[](https://packagist.org/packages/brokerexchange/elasticscout)
[](https://packagist.org/packages/brokerexchange/elasticscout)
[](https://packagist.org/packages/brokerexchange/elasticscout)
[](https://packagist.org/packages/brokerexchange/elasticscout)
[](https://packagist.org/packages/brokerexchange/elasticscout)
# ElasticScout
A [Laravel Scout](https://github.com/laravel/scout) Driver for Elasticsearch 6
## Overview
ElasticScout is a [Laravel Scout](https://github.com/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,
## Copyright
ElasticScout © Broker Exchange Network 2018
## Installation
* Run composer require command
`composer require brokerexchange/elasticscout`
* Configure Elasticsearch Host (default: localhost:9200)
```env
ELASTICSEARCH_HOST='elastic1.host.com:9200,elastic2.host.com:9200'
```
* Add trait to desired model
```php
use ElasticScout\Searchable;
```
## Usage
```php
//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.
```php
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.
```php
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'
]
]
]
],
],
];
}
```