Skip to content

An easy way to use the official Elastic Search client in your Laravel applications.

License

Notifications You must be signed in to change notification settings

JamesB797/laravel-elasticsearch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel-Elasticsearch

An easy way to use the official Elastic Search client in your Laravel applications.

Build Status Total Downloads Latest Stable Version Latest Stable Version

Installation and Configuration

Install the cviebrock/laravel-elasticsearch package via composer:

composer require cviebrock/laravel-elasticsearch

Add the service provider and facade (config/app.php for Laravel 5 or app/config/app.php for Laravel 4):

'providers' => [
    ...
    Cviebrock\LaravelElasticsearch\ServiceProvider::class, //=> Service provider for Laravel    
]

'aliases' => [
    ...
    'Elasticsearch' => Cviebrock\LaravelElasticsearch\Facade::class,
]

Publish the configuration file. For Laravel 5:

php artisan vendor:publish --provider="Cviebrock\LaravelElasticsearch\ServiceProvider"

In order to make this package also work with Laravel 4, we can't do the standard configuration publishing like most Laravel 4 packages do. You will need to simply copy the configuration file into your application's configuration folder:

cp vendor/cviebrock/laravel-elasticsearch/config/elasticsearch.php app/config/

If you work with Lumen, please register the LumenServiceProvider:

$app->register(Cviebrock\LaravelElasticsearch\LumenServiceProvider::class);

Usage

The Elasticsearch facade is just an entry point into the ES client, so previously you might have used:

$data = [
    'body' => [
        'testField' => 'abc'
    ],
    'index' => 'my_index',
    'type' => 'my_type',
    'id' => 'my_id',
];

$client = ClientBuilder::create()->build();
$return = $client->index($data);

You can now replace those last two lines with simply:

$return = Elasticsearch::index($data);

That will run the command on the default connection. You can run a command on any connection (see the defaultConnection setting and connections array in the configuration file).

$return = Elasticsearch::connection('connectionName')->index($data);

Please be noticed that you should not use Facade in Lumen. So, in Lumen - you should use IoC or get the ElasticSearch service object from the application.

$elasticSearch = $this->app('elasticsearch');

Bugs, Suggestions and Contributions

Thanks to everyone who has contributed to this project!

Please use Github for bugs, comments, suggestions.

  1. Fork the project.
  2. Create your bugfix/feature branch and write your (well-commented) code.
  3. Create unit tests for your code:
    • Run composer install --dev in the root directory to install required testing packages.
    • Add your test methods to laravel-elasticsearch/tests/.
    • Run vendor/bin/phpunit to the new (and all previous) tests and make sure everything passes.
  4. Commit your changes (and your tests) and push to your branch.
  5. Create a new pull request against the master branch.

Copyright and License

Laravel-Elasticsearch was written by Colin Viebrock and released under the MIT License. See the LICENSE file for details.

Copyright 2015 Colin Viebrock

About

An easy way to use the official Elastic Search client in your Laravel applications.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%