PHPackages                             pomirleanu/eloquent-elastic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pomirleanu/eloquent-elastic

ActiveProject[Database &amp; ORM](/categories/database)

pomirleanu/eloquent-elastic
===========================

Provides Elasticsearch indexing and managing functionality for Laravel Eloquent Models.

2.6(8y ago)4156MITPHPPHP &gt;=5.6.4

Since Aug 27Pushed 8y ago1 watchersCompare

[ Source](https://github.com/pomirleanu/eloquent-elastic)[ Packagist](https://packagist.org/packages/pomirleanu/eloquent-elastic)[ RSS](/packages/pomirleanu-eloquent-elastic/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (7)Versions (10)Used By (0)

Elodex - **Elo**quent In**dex**ing Library
==========================================

[](#elodex---eloquent-indexing-library)

[![Latest Stable Version](https://camo.githubusercontent.com/dc4537ed1c1b5fdef0757fd465c80fd4f44769e72684d3febe97ff3d7565fe4d/68747470733a2f2f706f7365722e707567782e6f72672f656c6f6465782f656c6f6465782f762f737461626c65)](https://packagist.org/packages/elodex/elodex)[![Build Status Master-Branch](https://camo.githubusercontent.com/64df006f4eeeed3aa200fe606923a1e8373428954e5f456f6736751d8c1f69fc/68747470733a2f2f7472617669732d63692e6f72672f456c6f6465782f456c6f6465782e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Elodex/Elodex)[![StyleCI](https://camo.githubusercontent.com/b914d10e457561690cabbd1bcb812404cda3cc9ed590d9d3ef80c03e80413017/68747470733a2f2f7374796c6563692e696f2f7265706f732f35363236323930362f736869656c64)](https://styleci.io/repos/56262906)[![Total Downloads](https://camo.githubusercontent.com/6a21daf372caba34dbcdccc37435ea8ec28b45dd0ebff0152f9d57b9d738ad17/68747470733a2f2f706f7365722e707567782e6f72672f656c6f6465782f656c6f6465782f646f776e6c6f616473)](https://packagist.org/packages/elodex/elodex)[![License](https://camo.githubusercontent.com/a643c45b9c4908e1b741876bb5c3039a56397dee0373890239174c1953e6a305/68747470733a2f2f706f7365722e707567782e6f72672f656c6f6465782f656c6f6465782f6c6963656e7365)](https://packagist.org/packages/elodex/elodex)

Development branch: [![Build Status Develop-Branch](https://camo.githubusercontent.com/b79fb8a93ca7c2b78a6cd2424201717397c66bce8957afc9a72a7bf7b6e1acbb/68747470733a2f2f7472617669732d63692e6f72672f456c6f6465782f456c6f6465782e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/Elodex/Elodex)

*Elodex* provides an easy way to implement synchronization of your [Laravel Eloquent](https://laravel.com/docs/5.2/eloquent "Laravel Eloquent") models with an [Elasticsearch](https://www.elastic.co/guide/ "Elasticsearch Docs") index.

Your Eloquent database will remain your main data source while you can use the full capacity of Elasticsearch for any index based search on your models.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Branching Model](#branching-model)
- [Installation](#installation)
- [Laravel Integration](#laravel-integration)
    - [Configuration](#configuration)
    - [Extending your Eloquent Model Classes](#extending-your-eloquent-model-classes)
- [Index Repositories](#index-repositories)
- [Elasticsearch Client](#elasticsearch-client)
- [Caching](#caching)
- [Documentation](#documentation)
- [Changelog](#changelog)
- [License](#license)

Requirements
------------

[](#requirements)

Elodex requires Elasticsearch 2.0 or higher, PHP v5.6+ and Laravel 5.1+.

Besides the technical requirements you should have a profound knowledge of Eloquent and you should be familiar with the basic [Elasticsearch terms](https://www.elastic.co/guide/en/elasticsearch/reference/current/glossary.html "Elasticsearch Glossary of terms") and how Elasticsearch works in general.

Branching Model
---------------

[](#branching-model)

This project uses the [Gitflow branching model](http://nvie.com/posts/a-successful-git-branching-model/ "Gitflow Branching model"):

- the **master** branch contains the latest **stable** version
- the **develop** branch contains the latest **unstable** development version
- all stable versions are tagged using semantic versioning

Installation
------------

[](#installation)

Elodex can be directly added to your project via Composer:

```
$ composer require "elodex/elodex=~2.0"
```

Or you can manually add the required entry to your composer.json file in the `require` section :

```
"require": {
  "elodex/elodex": "~2.0"
}
```

Laravel Integration
-------------------

[](#laravel-integration)

To integrate Elodex into your Laravel application you first need to add the `IndexServiceProvider` to the list of service providers in the application configuration.

This can be done by editing the `app.php` file in the `config` folder. Search for the `providers` section and add a new entry:

```
  /*
    |--------------------------------------------------------------------------
    | Autoloaded Service Providers
    |--------------------------------------------------------------------------
    |
  */
  'providers' => [
    ...
    \Elodex\IndexServiceProvider::class,
  ],
```

### Configuration

[](#configuration)

Even though Elodex does ship with a default configuration which should work for standard Elasticsearch installations you usually want to specify your own settings. You can do so by publishing the standard config file to your application:

```
$ php artisan vendor:publish --provider="Elodex\IndexServiceProvider"
```

This will copy a standard config to `config/elodex.php`. Make sure your Elasticsearch host configuration is correct and that you specify a default index name for your application which will be used for all your indexed Eloquent models by default.

```
  /*
    |--------------------------------------------------------------------------
    | Default Index Name
    |--------------------------------------------------------------------------
    |
  */
  'default_index' => 'my_app_index',
```

### Extending your Eloquent Model Classes

[](#extending-your-eloquent-model-classes)

There are two possibilities to add indexing capabilities to your Eloquent model classes.

#### 1. Using the IndexedModel Trait

[](#1-using-the-indexedmodel-trait)

To add the basic indexing functionality to your existing Eloquent models you can include the `IndexedModel` trait which automatically implements the needed `Contracts\IndexedModel` interface for you.

```
