nodtem66/elasticquent

Maps Laravel Eloquent models to Elasticsearch types with cviebrock/laravel-elasticsearch

v1.0.6.1 2019-02-25 22:58 UTC

This package is auto-updated.

Last update: 2024-03-26 10:19:43 UTC


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']);