triadev/laravel-elasticsearch-mapping

A service provider for laravel with a fluent elasticsearch mapping builder.

v1.0.0 2019-01-12 20:20 UTC

This package is auto-updated.

Last update: 2024-10-13 11:12:16 UTC


README

A service provider for laravel with a fluent elasticsearch mapping builder.

Software license Travis Coveralls CodeCov

Scrutinizer Code Quality Code Coverage Build Status

Latest stable Latest development Monthly installs Total Downloads

Supported laravel versions

Laravel 5.5 Laravel 5.6 Laravel 5.7

Supported elasticsearch versions

Elasticsearch 6.0 Elasticsearch 6.1 Elasticsearch 6.2 Elasticsearch 6.3 Elasticsearch 6.4

Installation

Composer

composer require triadev/laravel-elasticsearch-mapping

Application

The package is registered through the package discovery of laravel and Composer.

https://laravel.com/docs/5.7/packages

Configuration

The elasticsearch client is generated via the package: LaravelElasticsearchProvider.
You can find the environment variables for the elasticsearch client in the readme of the package.

Usage

This package offers a fluent mapping builder for elasticsearch. The entry point for each mapping build is a facade.

Triadev\Es\Mapping\Facade\ElasticMapping

Build mapping

use Triadev\Es\Mapping\Facade\ElasticMapping;
use Triadev\Es\Mapping\Mapping\Blueprint;

ElasticMapping::map(function (Blueprint $blueprint) {
    // fluent syntax
    $blueprint->keyword('EXAMPLE')->boost(5);

    // attributes array syntax
    $blueprint->keyword('EXAMPLE', [
        'boost' => 5
    ]);

    // settings are used when creating a new index
    $blueprint->settings([
        'index' => [
            'number_of_replicas' => 10,
            'number_of_shards' => 12,
            'refresh_interval' => '30s'
        ]
    ]);
}, INDEX, TYPE);

Create index

If the index does not exist a new index will be created. This also includes the configuration from $blueprint->settings().

Update index

If the index exists an update will be executed.

Reporting Issues

If you do find an issue, please feel free to report it with GitHub's bug tracker for this project.

Alternatively, fork the project and make a pull request. :)

Testing

  1. docker-compose -f docker-compose.yml up
  2. composer test

Contributing

Please see CONTRIBUTING for details.

Credits

Other

Project related links

License

The code for laravel-elasticsearch-mapping is distributed under the terms of the MIT license (see LICENSE).