{"id":13609310,"url":"https://github.com/mailerlite/laravel-elasticsearch","last_synced_at":"2025-05-13T21:09:22.912Z","repository":{"id":32650100,"uuid":"36237233","full_name":"mailerlite/laravel-elasticsearch","owner":"mailerlite","description":"An easy way to use the official Elastic Search client in your Laravel applications.","archived":false,"fork":false,"pushed_at":"2025-03-04T08:51:38.000Z","size":222,"stargazers_count":930,"open_issues_count":4,"forks_count":189,"subscribers_count":31,"default_branch":"main","last_synced_at":"2025-04-10T23:57:13.510Z","etag":null,"topics":["elasticsearch","laravel","laravel-elasticsearch","lumen","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mailerlite.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"mailerlite"}},"created_at":"2015-05-25T15:00:08.000Z","updated_at":"2025-04-10T22:47:06.000Z","dependencies_parsed_at":"2024-02-13T15:46:06.948Z","dependency_job_id":"2385cd2d-60e1-48b8-845d-5b55c81cf3a5","html_url":"https://github.com/mailerlite/laravel-elasticsearch","commit_stats":{"total_commits":200,"total_committers":44,"mean_commits":4.545454545454546,"dds":0.49,"last_synced_commit":"eba15222466e9f55a80f7dfdeafa2c99ae53358b"},"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailerlite%2Flaravel-elasticsearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailerlite%2Flaravel-elasticsearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailerlite%2Flaravel-elasticsearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mailerlite%2Flaravel-elasticsearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mailerlite","download_url":"https://codeload.github.com/mailerlite/laravel-elasticsearch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251326707,"owners_count":21571631,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elasticsearch","laravel","laravel-elasticsearch","lumen","php"],"created_at":"2024-08-01T19:01:34.022Z","updated_at":"2025-04-28T14:00:18.656Z","avatar_url":"https://github.com/mailerlite.png","language":"PHP","funding_links":["https://github.com/sponsors/mailerlite"],"categories":["PHP"],"sub_categories":[],"readme":"# Laravel-Elasticsearch\n\nAn easy way to use the [official Elastic Search client](https://github.com/elastic/elasticsearch-php) in your Laravel or Lumen applications.\n\n[![Build Status](https://github.com/mailerlite/laravel-elasticsearch/workflows/tests/badge.svg?branch=master)](https://github.com/mailerlite/laravel-elasticsearch/actions)\n[![Total Downloads](https://poser.pugx.org/mailerlite/laravel-elasticsearch/downloads.png)](https://packagist.org/packages/mailerlite/laravel-elasticsearch)\n[![Latest Stable Version](https://poser.pugx.org/mailerlite/laravel-elasticsearch/v/stable.png)](https://packagist.org/packages/mailerlite/laravel-elasticsearch)\n[![Latest Stable Version](https://poser.pugx.org/mailerlite/laravel-elasticsearch/v/unstable.png)](https://packagist.org/packages/mailerlite/laravel-elasticsearch)\n[![License](https://img.shields.io/packagist/l/mailerlite/laravel-elasticsearch)](LICENSE.md)\n\n\n- [Laravel-Elasticsearch](#laravel-elasticsearch)\n  - [Installation and Configuration](#installation-and-configuration)\n    - [Laravel](#laravel)\n        - [Alternative configuration method via .env file](#alternative-configuration-method-via-env-file)\n        - [Connecting to AWS Elasticsearch Service](#connecting-to-aws-elasticsearch-service)\n    - [Lumen](#lumen)\n  - [Usage](#usage)\n  - [Advanced Usage](#advanced-usage)\n  - [Console commands](#console-commands)\n  - [Bugs, Suggestions, Contributions and Support](#bugs-suggestions-contributions-and-support)\n  - [Copyright and License](#copyright-and-license)\n\n\n\n## Installation and Configuration\n\nInstall the current version of the `mailerlite/laravel-elasticsearch` package via composer:\n\n```sh\ncomposer require mailerlite/laravel-elasticsearch\n```\n\nIf you are using ElasticSearch version 5, then install version 2 of this package:\n\n```sh\ncomposer require mailerlite/laravel-elasticsearch:^2\n```\n\n### Laravel\n\nThe package's service provider will automatically register its service provider.\n\nPublish the configuration file:\n\n```sh\nphp artisan vendor:publish --provider=\"MailerLite\\LaravelElasticsearch\\ServiceProvider\"\n```\n\n##### Alternative configuration method via .env file\n\nAfter you publish the configuration file as suggested above, you may configure ElasticSearch\nby adding the following to your application's `.env` file (with appropriate values):\n\n```ini\nELASTICSEARCH_HOST=localhost\nELASTICSEARCH_PORT=9200\nELASTICSEARCH_SCHEME=http\nELASTICSEARCH_USER=\nELASTICSEARCH_PASS=\n```\n\nIf you are logging in via API keys, you will need to fill in these values:\n\n```ini\nELASTICSEARCH_API_ID=\nELASTICSEARCH_API_KEY=\n```\n\n\n##### Connecting to AWS Elasticsearch Service\n\nIf you are connecting to ElasticSearch instances on Amazon AWS, then you'll also\nneed to `composer require aws/aws-sdk-php:^3.80` and add the following to your\n`.env` file:\n\n```ini\nAWS_ELASTICSEARCH_ENABLED=true\nAWS_REGION=...\nAWS_ACCESS_KEY_ID=...\nAWS_SECRET_ACCESS_KEY=...\n```\n\nIf you have to use another authentication method having custom credentials (i.e. `instanceProfile()`),\nyou have to publish the configuration file and use the **aws_credentials**:\n\n```php\n\u003c?php\n// config/elasticsearch.php\n\n$provider = \\Aws\\Credentials\\CredentialProvider::instanceProfile();\n$memoizedProvider = \\Aws\\Credentials\\CredentialProvider::memoize($provider);\n$credentials = $memoizedProvider()-\u003ewait();\n\n...\n\n'hosts' =\u003e [\n    [\n        'host'            =\u003e env('ELASTICSEARCH_HOST', 'localhost'),\n        // For local development, the default Elasticsearch port is 9200.\n        // If you are connecting to an Elasticsearch instance on AWS, you probably want to set this to null\n        'port'            =\u003e env('ELASTICSEARCH_PORT', 9200),\n        'scheme'          =\u003e env('ELASTICSEARCH_SCHEME', null),\n        'user'            =\u003e env('ELASTICSEARCH_USER', null),\n        'pass'            =\u003e env('ELASTICSEARCH_PASS', null),\n\n        // If you are connecting to an Elasticsearch instance on AWS, you will need these values as well\n        'aws'             =\u003e env('AWS_ELASTICSEARCH_ENABLED', false),\n        'aws_region'      =\u003e env('AWS_REGION', ''),\n        'aws_key'         =\u003e env('AWS_ACCESS_KEY_ID', ''),\n        'aws_secret'      =\u003e env('AWS_SECRET_ACCESS_KEY', '')\n        'aws_credentials' =\u003e $credentials\n    ],\n],\n```\n\nIf you have a job that runs in supervisor, you have to use the Closure.\nThis way the credentials will be renewed at runtime.\n\n```php\n\u003c?php\n// config/elasticsearch.php\n\n$provider = \\Aws\\Credentials\\CredentialProvider::instanceProfile();\n$memoizedProvider = \\Aws\\Credentials\\CredentialProvider::memoize($provider);\n\n...\n\n'hosts' =\u003e [\n    [\n        ...\n        'aws_credentials' =\u003e $memoizedProvider\n    ],\n],\n```\n\nIf you are using `php artisan config:cache`, you cannot have the Closure in your config file, call it like this:\n\n```php\n\u003c?php\n// config/elasticsearch.php\n\n...\n\n'hosts' =\u003e [\n    [\n        ...\n        'aws_credentials' =\u003e [\\Aws\\Credentials\\CredentialProvider::class, 'defaultProvider'],\n    ],\n],\n```\n\n### Lumen\n\nIf you work with Lumen, please register the service provider and configuration in `bootstrap/app.php`:\n\n```php\n$app-\u003eregister(MailerLite\\LaravelElasticsearch\\ServiceProvider::class);\n$app-\u003econfigure('elasticsearch');\n```\n\nManually copy the configuration file to your application.\n\n\n\n## Usage\n\nThe `Elasticsearch` facade is just an entry point into the [ES client](https://github.com/elastic/elasticsearch-php),\nso previously you might have used:\n\n```php\nuse Elasticsearch\\ClientBuilder;\n\n$data = [\n    'body' =\u003e [\n        'testField' =\u003e 'abc'\n    ],\n    'index' =\u003e 'my_index',\n    'type' =\u003e 'my_type',\n    'id' =\u003e 'my_id',\n];\n\n$client = ClientBuilder::create()-\u003ebuild();\n$return = $client-\u003eindex($data);\n```\n\nYou can now replace those last two lines with simply:\n\n```php\nuse Elasticsearch;\n\n$return = Elasticsearch::index($data);\n```\n\nThat will run the command on the default connection.  You can run a command on\nany connection (see the `defaultConnection` setting and `connections` array in\nthe configuration file).\n\n```php\n$return = Elasticsearch::connection('connectionName')-\u003eindex($data);\n```\n\nLumen users who wish to use Facades can do so by editing the\n`bootstrap/app.php` file to include the following:\n\n```php\n$app-\u003ewithFacades(true, [\n    ...\n    MailerLite\\LaravelElasticsearch\\Facade::class =\u003e 'Elasticsearch',\n    ...\n]);\n```\n\nLumen users who aren't using facades will need to use dependency injection\nor the application container in order to get the ES service object:\n\n```php\n// using injection:\npublic function handle(\\Mailerlite\\LaravelElasticsearch\\Manager $elasticsearch)\n{\n    $elasticsearch-\u003eping();\n}\n\n// using application container:\n$elasticSearch = $this-\u003eapp('elasticsearch');\n```\n\nOf course, dependency injection and the application container work\nfor Laravel applications as well.\n\n\n\n## Advanced Usage\n\nBecause the package is a wrapper around the official Elastic client, you can\ndo pretty much anything with this package.  Not only can you perform standard\nCRUD operations, but you can monitor the health of your Elastic cluster programmatically,\nback it up, or make changes to it.  Some of these operations are done through\n\"namespaced\" commands, which this package happily supports.\n\nTo grab statistics for an index:\n\n```php\n$stats = Elasticsearch::indices()-\u003estats(['index' =\u003e 'my_index']);\n$stats = Elasticsearch::nodes()-\u003estats();\n$stats = Elasticsearch::cluster()-\u003estats();\n```\n\nTo create and restore snapshots (read the Elastic docs about creating repository paths and plugins first):\n\n```php\n$response = Elasticsearch::snapshots()-\u003ecreate($params);\n$response = Elasticsearch::snapshots()-\u003erestore($params);\n```\n\nTo delete whole indices (be careful!):\n\n```php\n$response = Elasticsearch::indices()-\u003edelete(['index' =\u003e 'my_index']);\n```\n\nPlease remember that this package is a thin wrapper around a large number of very\nsophisticated and well-documented Elastic features.  Information about those features\nand the methods and parameters used to call them can be found in the\n[Elastic documentation](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html).\nHelp with using them is available via the [Elastic forums](https://discuss.elastic.co/)\nand on sites like [Stack Overflow](https://stackoverflow.com/questions/tagged/elasticsearch).\n\n\n\n## Console commands\n\nThis package also provides some useful console commands.\n\nCheck if an index exists:\n\n```sh\nphp artisan laravel-elasticsearch:utils:index-exists \u003cyour_elasticsearch_index_name\u003e\n```\n\nCreate an index:\n\n```sh\nphp artisan laravel-elasticsearch:utils:index-create \u003cyour_elasticsearch_index_name\u003e\n```\n\nDelete an index:\n\n```sh\nphp artisan laravel-elasticsearch:utils:index-delete \u003cyour_elasticsearch_index_name\u003e\n```\n\nCreate or update index mapping:\n_Note: The index mapping file must contain a valid JSON mapping definition as Elasticsearch expects, for example:_\n\n```json\n{\n    \"body\": {\n        \"_source\": {\n            \"enabled\": true\n        },\n        \"properties\": {\n            \"id\": {\n                \"type\": \"keyword\"\n            },\n            \"property_1\": {\n                \"type\": \"text\"\n            },\n            \"property_2\": {\n                \"type\": \"text\"\n            }\n        }\n    }\n}\n```\n\n```sh\nphp artisan laravel-elasticsearch:utils:index-create-or-update-mapping \u003cyour_elasticsearch_index_name\u003e \u003cjson_mapping_absolute_file_path\u003e\n```\n\nCreates an alias:\n\n```sh\nphp artisan laravel-elasticsearch:utils:alias-create \u003cyour_elasticsearch_index_name\u003e \u003cyour_elasticsearch_alias_name\u003e\n```\n\nRemove index from an alias:\n\n```sh\nphp artisan laravel-elasticsearch:utils:alias-remove-index \u003cyour_elasticsearch_index_name\u003e \u003cyour_elasticsearch_alias_name\u003e\n```\n\nSwitch index on alias (useful for zero-downtime release of the new index):\n\n```sh\nphp artisan laravel-elasticsearch:utils:alias-switch-index \u003cyour_NEW_elasticsearch_index_name\u003e \u003cyour_OLD_elasticsearch_index_name\u003e \u003cyour_elasticsearch_alias_name\u003e\n```\n\n\n\n## Bugs, Suggestions, Contributions and Support\n\nThanks to [everyone](https://github.com/mailerlite/laravel-elasticsearch/graphs/contributors)\nwho has contributed to this project!\n\nPlease use [Github](https://github.com/mailerlite/laravel-elasticsearch) for reporting bugs,\nand making comments or suggestions.\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for how to contribute changes.\n\n\n\n## Copyright and License\n\n[laravel-elasticsearch](https://github.com/mailerlite/laravel-elasticsearch)\nwas written thanks to [Colin Viebrock](http://viebrock.ca) and is released under the\n[MIT License](LICENSE.md). It is being maintained and developed by [MailerLite](https://www.mailerlite.com)\n\nCopyright (c) 2023 MailerLite\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailerlite%2Flaravel-elasticsearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmailerlite%2Flaravel-elasticsearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmailerlite%2Flaravel-elasticsearch/lists"}