GithubHelp home page GithubHelp logo

tomkita / laravel-elasticsearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mailerlite/laravel-elasticsearch

0.0 2.0 0.0 58 KB

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

License: MIT License

PHP 100.00%

laravel-elasticsearch's Introduction

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

laravel-elasticsearch's People

Contributors

ahmedash95 avatar bburr avatar bmartel avatar cviebrock avatar james-brown-upfeat avatar khoatran avatar pavel-pepper avatar xian13 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.