Skip to content

A fork of cviebrock/laravel-elasticsearch that includes AWS ES Authentication

License

Notifications You must be signed in to change notification settings

gstt/laravel-elasticsearch-aws

 
 

Repository files navigation

Laravel-Elasticsearch

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

Build Status Total Downloads Latest Stable Version Latest Stable Version Scrutinizer Code Quality

Installation and Configuration

Install the cviebrock/laravel-elasticsearch package via composer:

composer require cviebrock/laravel-elasticsearch

Laravel

Add the service provider and facade to config/app.php:

'providers' => [
    ...
    Cviebrock\LaravelElasticsearch\ServiceProvider::class,   
]

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

Publish the configuration file:

php artisan vendor:publish --provider="Cviebrock\LaravelElasticsearch\ServiceProvider"
Alternative configuration method via .env file

After you publish the configuration file as suggested above, you may configure Elastic Search by adding the following to laravel .env file

ELASTICSEARCH_HOST=localhost
ELASTICSEARCH_PORT=9200
ELASTICSEARCH_SCHEME=http
ELASTICSEARCH_USER=
ELASTICSEARCH_PASS=

Lumen

If you work with Lumen, please register the LumenServiceProvider in bootstrap/app.php:

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

And manually copy the configuration file to your application.

Note: don't forget to register your elasticsearch.php config in bootstrap/app.php

$app->configure('elasticsearch');

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 reporting bugs, and making comments or suggestions.

See CONTRIBUTING.md for how to contribute changes.

Copyright and License

laravel-elasticsearch was written by Colin Viebrock and is released under the MIT License.

Copyright (c) 2015 Colin Viebrock

About

A fork of cviebrock/laravel-elasticsearch that includes AWS ES Authentication

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%