PHPackages                             mailerlite/laravel-elasticsearch - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. mailerlite/laravel-elasticsearch

ActiveLibrary[Search &amp; Filtering](/categories/search)

mailerlite/laravel-elasticsearch
================================

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

12.0.0(1mo ago)935628.9k↓29.7%190[1 issues](https://github.com/mailerlite/laravel-elasticsearch/issues)2MITPHPPHP ^8.2CI passing

Since May 28Pushed 2w ago28 watchersCompare

[ Source](https://github.com/mailerlite/laravel-elasticsearch)[ Packagist](https://packagist.org/packages/mailerlite/laravel-elasticsearch)[ Docs](https://github.com/mailerlite/laravel-elasticsearch)[ GitHub Sponsors](https://github.com/mailerlite)[ RSS](/packages/mailerlite-laravel-elasticsearch/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (7)Dependencies (34)Versions (64)Used By (2)

Laravel-Elasticsearch
=====================

[](#laravel-elasticsearch)

An easy way to use the [official Elastic Search client](https://github.com/elastic/elasticsearch-php) in your Laravel applications.

[![Build Status](https://github.com/mailerlite/laravel-elasticsearch/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/mailerlite/laravel-elasticsearch/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/df49774e7cf8fb82a2b8e7632ed8ade37ea49b17f2a477804fa4f94b654a14cb/68747470733a2f2f706f7365722e707567782e6f72672f6d61696c65726c6974652f6c61726176656c2d656c61737469637365617263682f646f776e6c6f6164732e706e67)](https://packagist.org/packages/mailerlite/laravel-elasticsearch)[![Latest Stable Version](https://camo.githubusercontent.com/b36fb5089ba6edb5f390aae83de71f78af06591fe0eff2df8a323af986cc64bc/68747470733a2f2f706f7365722e707567782e6f72672f6d61696c65726c6974652f6c61726176656c2d656c61737469637365617263682f762f737461626c652e706e67)](https://packagist.org/packages/mailerlite/laravel-elasticsearch)[![License](https://camo.githubusercontent.com/c805da922dbf83b3763446ecb6e765484002fe5171948a477c4df3579535508a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d61696c65726c6974652f6c61726176656c2d656c6173746963736561726368)](LICENSE.md)

- [Laravel-Elasticsearch](#laravel-elasticsearch)
    - [Requirements](#requirements)
    - [Installation](#installation)
    - [Configuration](#configuration)
        - [Alternative configuration method via .env file](#alternative-configuration-method-via-env-file)
        - [Connecting to AWS Elasticsearch Service](#connecting-to-aws-elasticsearch-service)
        - [Security and TLS (Elasticsearch 8.x)](#security-and-tls-elasticsearch-8x)
    - [Usage](#usage)
    - [Advanced Usage](#advanced-usage)
    - [Console commands](#console-commands)
    - [Bugs, Suggestions, Contributions and Support](#bugs-suggestions-contributions-and-support)
    - [Copyright and License](#copyright-and-license)

Requirements
------------

[](#requirements)

- PHP `8.2` or higher (Laravel `13` requires PHP `8.3`)
- Laravel `11`, `12` or `13`
- An Elasticsearch `8.x` cluster

Installation
------------

[](#installation)

Install the current version of the `mailerlite/laravel-elasticsearch` package via composer:

```
composer require mailerlite/laravel-elasticsearch
```

This version of the package targets **Elasticsearch 8.x**. If you are running an older version of Elasticsearch, install the matching major version of this package:

ElasticsearchPackage version8.x`^12`7.x`^11`For example, to use Elasticsearch 7, install version `^11`. Its documentation lives on the [`11.x` branch](https://github.com/mailerlite/laravel-elasticsearch/tree/11.x):

```
composer require mailerlite/laravel-elasticsearch:^11
```

Note

**Upgrading from Elasticsearch 7?** Version 12 moves to the Elasticsearch 8.x client, which introduces breaking changes (new namespace, response objects and removed configuration options). See [UPGRADING.md](UPGRADING.md) for the full migration guide.

Configuration
-------------

[](#configuration)

The package's service provider is registered automatically.

Publish the configuration file:

```
php artisan vendor:publish --provider="MailerLite\LaravelElasticsearch\ServiceProvider"
```

### Alternative configuration method via .env 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):

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

If you are logging in via API keys, you will need to fill in these values:

```
ELASTICSEARCH_API_ID=
ELASTICSEARCH_API_KEY=
```

### Connecting to AWS Elasticsearch Service

[](#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:

```
AWS_ELASTICSEARCH_ENABLED=true
AWS_REGION=...
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
```

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**:

```
