PHPackages                             torann/elasticquent - 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. torann/elasticquent

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

torann/elasticquent
===================

Maps Laravel Eloquent models to Elasticsearch types.

v1.0.8(9y ago)018MITPHP &gt;=5.5.0

Since Oct 22Compare

[ Source](https://github.com/Torann/Elasticquent)[ Packagist](https://packagist.org/packages/torann/elasticquent)[ Docs](https://github.com/Torann/Elasticquent)[ RSS](/packages/torann-elasticquent/feed)WikiDiscussions Synced today

READMEChangelogDependencies (6)Versions (10)Used By (0)

Elasticquent
============

[](#elasticquent)

[![Patreon donate button](https://camo.githubusercontent.com/f9e075baad95563481d35174d43ef50757281abb6bc795d0f473fad452afa030/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70617472656f6e2d646f6e6174652d79656c6c6f772e737667)](https://www.patreon.com/torann)[![Donate weekly to this project using Gratipay](https://camo.githubusercontent.com/0eeae019980adaa1dc64842cfb01f3d738c688982ea4eb58094047011cb46704/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f67726174697061792d646f6e6174652d79656c6c6f772e737667)](https://gratipay.com/~torann)[![Donate to this project using Flattr](https://camo.githubusercontent.com/d79e412f78041f87e203449041ad81848a8405cf0f3c622c51e3bad0c2a4b599/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f666c617474722d646f6e6174652d79656c6c6f772e737667)](https://flattr.com/profile/torann)[![Donate to this project using Paypal](https://camo.githubusercontent.com/604e3db9c8751116b3f765aad0353ec7ded655bbe8aaacbc38d8c4a6b784b3ed/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f446f6e6174652d50617950616c2d677265656e2e737667)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4CJA2A97NPYVU)

Elasticsearch for Eloquent Laravel Models

Elasticquent makes working with [Elasticsearch](http://www.elasticsearch.org/) and [Eloquent](http://laravel.com/docs/eloquent) models easier by mapping them to Elasticsearch types. You can use the default settings or define how Elasticsearch should index and search your Eloquent models right in the model.

Elasticquent uses the [official Elasticsearch PHP API](https://github.com/elasticsearch/elasticsearch-php). To get started, you should have a basic knowledge of how Elasticsearch works (indexes, types, mappings, etc).

Elasticsearch Requirements
==========================

[](#elasticsearch-requirements)

You must be running *at least* Elasticsearch 1.0. Elasticsearch 0.9 and below *will not work* and are not supported.

Contents
--------

[](#contents)

- [Overview](#overview)
    - [How Elasticquent Works](#how-elasticquent-works)
- [Setup](#setup)
    - [Elasticsearch Configuration](#elasticsearch-configuration)
    - [Indexes and Mapping](#indexes-and-mapping)
    - [Setting a Custom Index Name](#setting-a-custom-index-name)
    - [Setting a Custom Type Name](#setting-a-custom-type-name)
- [Indexing Documents](#indexing-documents)
- [Artisan Commands](#artisan-commands)
- [Searching](#searching)
    - [Search Collections](#search-collections)
    - [Search Collection Documents](#search-collection-documents)
    - [Chunking results from Elastiquent](#chunking-results-from-elastiquent)
    - [Using the Search Collection Outside of Elasticquent](#using-the-search-collection-outside-of-elasticquent)
- [More Options](#more-options)
    - [Document Ids](#document-ids)
    - [Document Data](#document-data)
    - [Using Elasticquent With Custom Collections](#using-elasticquetn-with-custom-collections)
- [Roadmap](#roadmap)

Reporting Issues
----------------

[](#reporting-issues)

If you do find an issue, please feel free to report it with [GitHub's bug tracker](https://github.com/elasticquent/Elasticquent/issues) for this project.

Alternatively, fork the project and make a pull request :)

Overview
--------

[](#overview)

Elasticquent allows you take an Eloquent model and easily index and search its contents in Elasticsearch.

```
    $books = Book::where('id', ' [
    ...
    Elasticquent\ElasticquentServiceProvider::class,
],
```

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;
}
```

Now your Eloquent model has some extra methods that make it easier to index your model's data using Elasticsearch.

### Elasticsearch Configuration

[](#elasticsearch-configuration)

By default, Elasticquent will connect to `localhost:9200` and use `default` as index name, you can change this and the other settings in the configuration file. You can add the `elasticquent.php` config file at `/app/config/elasticquent.php` for Laravel 4, or use the following Artisan command to publish the configuration file into your config directory for Laravel 5:

```
$ php artisan vendor:publish --provider="Elasticquent\ElasticquentServiceProvider"
```

```
