PHPackages                             aloko/elasticquent5 - 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. aloko/elasticquent5

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

aloko/elasticquent5
===================

Access Elasticsearch types through Laravel 5 eloquently

v0.1(10y ago)2120.3k3[1 issues](https://github.com/mustafaaloko/elasticquent5/issues)MITPHPPHP &gt;=5.5.9

Since Nov 1Pushed 10y ago6 watchersCompare

[ Source](https://github.com/mustafaaloko/elasticquent5)[ Packagist](https://packagist.org/packages/aloko/elasticquent5)[ Docs](https://github.com/mustafaaloko/elasticquent5)[ RSS](/packages/aloko-elasticquent5/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

Elasticquent - Laravel 5
========================

[](#elasticquent---laravel-5)

*Elasticsearch for Eloquent Laravel 5 Models*

**Note:** Aloko\\Elasticquent5 is a built on top of [adamfairholm/Elasticquent](https://github.com/adamfairholm/Elasticquent) which was built for Laravel 4.x. As the author of [that package](https://github.com/adamfairholm/Elasticquent), didn't merge the pull requests for changes to be compatible with Laravel 5. I decided to publish this one.

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). This is meant for use with Elasticsearch 1.x.

Contents
--------

[](#contents)

- [Overview](#overview)
    - [How Elasticquent Works](#how-elasticquent-works)
- [Setup](#setup)
    - [Step 1 - Installation](#step1)
    - [Step 2 - Adding the Service Provider](#step2)
    - [Step 3 - Publishing the Config File](#step3)
    - [Final Step - Adding it to models](#final)
- [Next Steps](#next-steps)
    - [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)
- [Searching](#searching)
    - [Search Collections](#search-collections)
    - [Search Collection Documents](#search-collection-documents)
    - [Using the Search Collection Outside Elasticq uent](#using-the-search-collection-outside-wlasticquent)
- [More Options](#more-options)
    - [Document Ids](#document-ids)
    - [Document Data](#document-data)
    - [Using Elasticquent With Custom Collections](#using-elasticquent-with-custom-collections)
- [Roadmap](#roadmap)

Overview
--------

[](#overview)

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

```
$books = Book::where('id', ' array(
        'type' => 'string',
        'analyzer' => 'standard'
    )
);
```

If you'd like to setup a model's type mapping based on your mapping properties, you can use:

```
Book::putMapping($ignoreConflicts = true);

```

To delete a mapping:

```
Book::deleteMapping();

```

To rebuild (delete and re-add, useful when you make important changes to your mapping) a mapping:

```
Book::rebuildMapping();

```

You can also get the type mapping and check if it exists.

```
Book::mappingExists();
Book::getMapping();

```

### Setting a Custom Index Name

[](#setting-a-custom-index-name)

Elastiquent will use `default` as your index name, but you can set a custom index name by editing **config/elasticquent.php** config file::

```
