Download the PHP package mailerlite/laravel-elasticsearch without Composer
On this page you can find all versions of the php package mailerlite/laravel-elasticsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mailerlite/laravel-elasticsearch
More information about mailerlite/laravel-elasticsearch
Files in mailerlite/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/mailerlite/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.
- Laravel-Elasticsearch
- 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 mailerlite/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):
If you are logging in via API keys, you will need to fill in these 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!
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 thanks to Colin Viebrock and is released under the MailerLite
Copyright (c) 2023 MailerLite
All versions of laravel-elasticsearch with dependencies
ext-json Version *
elasticsearch/elasticsearch Version ^7.11
guzzlehttp/psr7 Version ^1.7|^2.0
illuminate/contracts Version ^7.0|^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^7.0|^8.0|^9.0|^10.0|^11.0
psr/http-message Version ^1.0|^2.0