Download the PHP package gnahotelsolutions/laravel-elasticsearch without Composer
On this page you can find all versions of the php package gnahotelsolutions/laravel-elasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gnahotelsolutions/laravel-elasticsearch
More information about gnahotelsolutions/laravel-elasticsearch
Files in gnahotelsolutions/laravel-elasticsearch
Package laravel-elasticsearch
Short Description An easy way to use the official PHP ElasticSearch client in your Laravel applications.
License MIT
Homepage https://github.com/gnahotelsolutions/laravel-elasticsearch
Informations about the package laravel-elasticsearch
Laravel-Elasticsearch
An easy way to use the official Elastic Search client in your Laravel or Lumen applications.
⚠️ This Package Will Be Abandoned
Due to several factors, including the fact that I no longer use ES, I will be ceasing development on this package. If you are interested in taking over this project, please reach out to me here or on Twitter: @cviebrock
- Installation and Configuration
- Laravel
- Alternative configuration method via .env file
- Connecting to AWS Elasticsearch Service
- Lumen
- Usage
- Advanced Usage
- Console Commands
- Bugs, Suggestions, Contributions and Support
- Copyright and License
Installation and Configuration
Install the current version of the cviebrock/laravel-elasticsearch
package via composer:
If you are using ElasticSearch version 5, then install version 2 of this package:
Laravel
The package's service provider will automatically register its service provider.
Publish the configuration file:
Alternative configuration method via .env file
After you publish the configuration file as suggested above, you may configure ElasticSearch
by adding the following to your application's .env
file (with appropriate values):
Connecting to AWS Elasticsearch Service
If you are connecting to ElasticSearch instances on Amazon AWS, then you'll also
need to composer require aws/aws-sdk-php:^3.80
and add the following to your
.env
file:
If you have to use another authentication method having custom credentials (i.e. instanceProfile()
),
you have to publish the configuration file and use the aws_credentials:
If you have a job that runs in supervisor, you have to use the Closure. This way the credentials will be renewed at runtime.
If you are using php artisan config:cache
, you cannot have the Closure in your config file, call it like this:
Lumen
If you work with Lumen, please register the service provider and configuration in bootstrap/app.php
:
Manually copy the configuration file to your application.
Usage
The Elasticsearch
facade is just an entry point into the ES client,
so previously you might have used:
You can now replace those last two lines with simply:
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).
Lumen users who wish to use Facades can do so by editing the
bootstrap/app.php
file to include the following:
Lumen users who aren't using facades will need to use dependency injection or the application container in order to get the ES service object:
Of course, dependency injection and the application container work for Laravel applications as well.
Advanced Usage
Because the package is a wrapper around the official Elastic client, you can do pretty much anything with this package. Not only can you perform standard CRUD operations, but you can monitor the health of your Elastic cluster programmatically, back it up, or make changes to it. Some of these operations are done through "namespaced" commands, which this package happily supports.
To grab statistics for an index:
To create and restore snapshots (read the Elastic docs about creating repository paths and plugins first):
To delete whole indices (be careful!):
Please remember that this package is a thin wrapper around a large number of very sophisticated and well-documented Elastic features. Information about those features and the methods and parameters used to call them can be found in the Elastic documentation. Help with using them is available via the Elastic forums and on sites like Stack Overflow.
Console commands
This package also provides some useful console commands.
Check if an index exists:
Create an index:
Delete an index:
Create or update index mapping:
Note: The index mapping file must contain a valid JSON mapping definition as Elasticsearch expects, for example:
Creates an alias:
Remove index from an alias:
Switch index on alias (useful for zero-downtime release of the new index):
Bugs, Suggestions, Contributions and Support
Thanks to everyone who has contributed to this project!
Special thanks to JetBrains for their Open Source License Program ... and the excellent PHPStorm IDE, of course!
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
All versions of laravel-elasticsearch with dependencies
ext-json Version *
elasticsearch/elasticsearch Version ^7.11
guzzlehttp/psr7 Version ^2.0
illuminate/contracts Version ^8.0|^9.0|^10
illuminate/support Version ^8.0|^9.0|^10
psr/http-message Version ^1.0