nodtem66 / elasticquent
Maps Laravel Eloquent models to Elasticsearch types with cviebrock/laravel-elasticsearch
Requires
- php: ^7.0
- cviebrock/laravel-elasticsearch: ^3.4
- illuminate/config: ~4.2|^5
- illuminate/database: ~4.2|^5
- nesbot/carbon: ~1.0
Requires (Dev)
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ~4.2|~5.0
README
Forked from original: elasticquent/elasticquent with cviebrock/laravel-elasticsearch to support the AWS
Elasticsearch Requirements
You must be running at least Elasticsearch 6.0. Otherwies, you have to custom the dependency cviebrock/laravel-elasticsearch
.
API Documentation
For Eloquent model: elasticquent/elasticquent For Elasticsearch client: cviebrock/laravel-elasticsearch
Overview
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(); });
Installation
- 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']);