Forked from original: elasticquent/elasticquent with cviebrock/laravel-elasticsearch to support the AWS
You must be running at least Elasticsearch 6.0. Otherwies, you have to custom the dependency cviebrock/laravel-elasticsearch
.
For Eloquent model: elasticquent/elasticquent For Elasticsearch client: cviebrock/laravel-elasticsearch
Elasticquent allows you take an Eloquent model and easily index and search its contents in Elasticsearch.
$books = Book::where('id', '<', 200)->get();
$books->addToIndex();
When you search, instead of getting a plain array of search results, you instead get an Eloquent collection with some special Elasticsearch functionality.
$books = Book::search('Moby Dick');
echo $books->totalHits();
Plus, you can still use all the Eloquent collection functionality:
$books = $books->filter(function ($book) {
return $book->hasISBN();
});
- Install the current version via composer:
composer require nodtem66/elasticquent
Based on cviebrock/laravel-elasticsearch document, The package's service provider will automatically register its service provider.
- Publish the configuration file:
php artisan vendor:publish --provider="Cviebrock\LaravelElasticsearch\ServiceProvider"
- Then add the Elasticquent trait to any Eloquent model that you want to be able to index in Elasticsearch:
use Elasticquent\ElasticquentTrait;
class Book extends Eloquent
{
use ElasticquentTrait;
}
Basic Elasticsearch client usage
use Elasticquent\Elasticsearch;
Elasticsearch::indices()->create(['index'=>'default_index']);