Elasticsearch migrations for Laravel

Overview

Elastic Migrations

Latest Stable Version Total Downloads License Tests Code style Static analysis Donate PayPal

Buy Me A Coffee


Elasticsearch migrations for Laravel allow you to easily modify and share indices schema across the application's environments.

Contents

Compatibility

The current version of Elastic Migrations has been tested with the following configuration:

  • PHP 7.2-8.0
  • Elasticsearch 7.x
  • Laravel 6.x-8.x

Installation

The library can be installed via Composer:

composer require babenkoivan/elastic-migrations

If you want to use Elastic Migrations with Lumen framework check this guide.

Configuration

Elastic Migrations uses babenkoivan/elastic-client as a dependency. If you want to change the default client settings (and I'm pretty sure you do), then you need to create the configuration file first:

php artisan vendor:publish --provider="ElasticClient\ServiceProvider"

You can change Elasticsearch host and other client settings in the config/elastic.client.php file. Please refer to babenkoivan/elastic-client for more details.

If you want to change the migration table name, the default migrations directory or set prefixes for indices and aliases, publish Elastic Migrations settings as well:

php artisan vendor:publish --provider="ElasticMigrations\ServiceProvider"

The published configuration can be found in the config/elastic.migrations.php file.

Finally, don't forget to run Laravel database migrations to create Elastic Migrations table:

php artisan migrate

Writing Migrations

You can effortlessly create a new migration file using an Artisan console command:

php artisan elastic:make:migration create_my_index

This command creates a migration class in the elastic/migrations directory.

Every migration includes two methods: up and down. up is used to alternate the index schema and down is used to revert that action.

You can use ElasticMigrations\Facades\Index facade to perform basic operations over Elasticsearch indices:

Create Index

Create an index with the default settings:

Index::create('my-index');

or use a modifier to configure mapping and settings:

Index::create('my-index', function (Mapping $mapping, Settings $settings) {
    // to add a new field to the mapping use method name as a field type (in Camel Case), 
    // first argument as a field name and optional second argument as additional field parameters  
    $mapping->text('title', ['boost' => 2]);
    $mapping->float('price');

    // you can define a dynamic template as follows
    $mapping->dynamicTemplate('my_template_name', [
        'match_mapping_type' => 'long',
        'mapping' => [
            'type' => 'integer',
        ],
    ]);
    
    // you can also change the index settings 
    $settings->index([
         'number_of_replicas' => 2,
         'refresh_interval' => -1
    ]);
    
    // and analysis configuration
    $settings->analysis([
        'analyzer' => [
            'title' => [
                'type' => 'custom',
                'tokenizer' => 'whitespace'    
            ]
        ]
    ]);
});

There is also an option to create an index only if it doesn't exist:

Index::createIfNotExists('my-index');

Update Mapping

Use the modifier to adjust the mapping:

Index::putMapping('my-index', function (Mapping $mapping) {
    $mapping->text('title', ['boost' => 2]);
    $mapping->float('price');
});

Update Settings

Use the modifier to change the index configuration:

Index::putSettings('my-index', function (Settings $settings) {
    $settings->index([
         'number_of_replicas' => 2,
         'refresh_interval' => -1
    ]);
});

You can update analysis settings only on closed indices. The putSettingsHard method closes the index, updates the configuration and opens the index again:

Index::putSettingsHard('my-index', function (Settings $settings) {
    $settings->analysis([
        'analyzer' => [
            'title' => [
                'type' => 'custom',
                'tokenizer' => 'whitespace'
            ]
        ]
    ]);
});

Drop Index

You can unconditionally delete the index:

Index::drop('my-index');

or delete it only if it exists:

Index::dropIfExists('my-index');

Create Alias

You can create an alias with optional filter query:

Index::putAlias('my-index', 'my-alias', ['term' => ['user_id' => 1]]);

Delete Alias

You can delete an alias by its name:

Index::deleteAlias('my-index', 'my-alias');

More

Finally, you are free to inject Elasticsearch\Client in the migration constructor and execute any supported by client actions.

Running Migrations

You can either run all migrations:

php artisan elastic:migrate

or run a specific one:

php artisan elastic:migrate 2018_12_01_081000_create_my_index

Use the --force option if you want to execute migrations on production environment:

php artisan elastic:migrate --force

Reverting Migrations

You can either revert the last executed migrations:

php artisan elastic:migrate:rollback 

or rollback a specific one:

php artisan elastic:migrate:rollback 2018_12_01_081000_create_my_index

Use the elastic:migrate:reset command if you want to revert all previously migrated files:

php artisan elastic:migrate:reset 

Starting Over

Sometimes you just want to start over, rollback all the changes and apply them again:

php artisan elastic:migrate:refresh

Alternatively you can also drop all existing indices and rerun the migrations:

php artisan elastic:migrate:fresh

Migration Status

You can always check which files have been already migrated and what can be reverted by the elastic:migrate:rollback command (the last batch):

php artisan elastic:migrate:status

Zero Downtime Migration

Changing an index mapping with zero downtime is not a trivial process and might vary from one project to another. Elastic Migrations library doesn't include such feature out of the box, but you can implement it in your project by following this guide.

Troubleshooting

If you see one of the messages below, follow the instructions:

  • Migration table is not yet created - run the php artisan migrate command
  • Migration directory is not yet created - create a migration file using the elastic:make:migration command or create migrations directory manually

In case one of the commands doesn't work as expected, try to publish configuration:

php artisan vendor:publish --provider="ElasticMigrations\ServiceProvider"
Comments
  • Mapper parsing exceptions with date fields

    Mapper parsing exceptions with date fields

    | Software | Version | ------------- | --------------- | PHP | 7.4.15 | Elasticsearch | 7.10.2 | Laravel | 6.20.16

    Hey, first of all, awesome work!

    I'm playing around with the new elastic packages and I'm getting some issues trying to parse date fields with the follow config:

    $mapping->date('created_at', [
              'format' => 'strict_date_optional_time_nanos',
    ]);
    

    It reports a successfull job but debugging the underlying elastic request gives me the following output:

    [2021-02-15 12:36:37] production.DEBUG: {"took":1,"errors":true,"items":[{"index":{"_index":"anoreg_mt_vendas","_type":"_doc","_id":"19","status":400,"error":{"type":"mapper_parsing_exception","reason":"failed to parse field [created_at] of type [date] in document with id '19'. Preview of field's value: '2020-11-16 17:07:36'","caused_by":{"type":"illegal_argument_exception","reason":"failed to parse date field [2020-11-16 17:07:36] with format [strict_date_optional_time_nanos]","caused_by":{"type":"date_time_parse_exception","reason":"Text '2020-11-16 17:07:36' could not be parsed, unparsed text found at index 10"}}}}}]}  
    
    stale 
    opened by rmundel 8
  • Trying to get property 'batch' of non-object in Repositories\MigrationRepository.php:53

    Trying to get property 'batch' of non-object in Repositories\MigrationRepository.php:53

    I have 2 existing indexes in elastic search and i have written another migration for 3rd index then it give me the below error when i am trying to run the "php artisan elastic:migrate"

    Trying to get property 'batch' of non-object in Repositories\MigrationRepository.php:53 When i try to debug it the i found..... $record = $this->table() ->select('batch') ->orderBy('batch', 'desc') ->first(); return isset($record) ? (int)$record->batch : null;

       Here "$record" variable contain the array not the object. I am using mongoDB as primary database 
       Please fix this issue asap and let me know if you need any further information about this issue 
    
    bug stale 
    opened by vishaltomar76 7
  • Question about setting up migration table

    Question about setting up migration table

    Hi I am struggling to understand the mapping a bit. In my event index I have

     Index::create('events', function (Mapping $mapping, Settings $settings) {
                $mapping->search_as_you_type('name');
                $mapping->date('published_at');
                $mapping->integer('rank');
                $mapping->date('closingDate');
                $mapping->text('priceranges');
                $mapping->integer('category_id');
                $mapping->geo_point('location_latlon');
                $mapping->text('shows');
                $mapping->text('genres');
                $mapping->boolean('hasLocation');
            });
    

    However it doesn't work when I try to do search for name. I am using the same database and have your old elasticsearch plugin on one server and the new one locally. So on the old one when I use

    $event = Event::search($request->keywords)
                 ->rule(EventSearchRule::class)
                 ->take(5)
                 ->get();
    
    And in EventSearchRule.php 
    
    return [
                'must' => [
                    'multi_match' =>  [
                        "query" =>  $this->builder->query,
                        "type"  =>  'bool_prefix',
                        "fields"    =>  [
                            'name',
                            'name.2gram',
                            'name.3gram'
                        ],
                    ]
                ]
            ];
    

    If I type in 'c' it returns cairn, curiousor, and 3 more. However in the new system when I use that migration above and

    $a = Event::multiMatchSearch()
            ->fields(['name', 'name.2gram','name.3gram'])
            ->query($request->keywords)
            ->execute();
    
            return $a->models();
    

    if I type in 'c' it returns only one C(ovell) In The C(loud). If I type in a full word like 'chaos' it will then find that name and returns that event named chaos.

    Do I need to do $mapping->dynamicTemplate()? If so, how would that setup be for geo_point or search_as_you_type? Thanks so much!!

    opened by chrisgrim 7
  • Zero Downtime Migration

    Zero Downtime Migration

    Hello @babenkoivan ,

    In your old package for scout, you made an incredible work for zero downtime migration. I used it for years and it worked perfectly. The good point was to start writing to new index with an alias with suffix _write while still searching in old index.

    My re indexing is heavy and it can take hours. With the new way you documented on this package, old index continue indexing new incoming documents. So when the import finished, we don't have these documents created by users in the new index.

    I don't know how we can do it the old way (Indexing new documents to the new index while searching in the old, and then switch searching creating a new alias). Do you know if this is possible ?

    feature stale 
    opened by ybert 5
  • Move command constructor args to `handle()`

    Move command constructor args to `handle()`

    Closes https://github.com/babenkoivan/elastic-migrations/issues/30

    I tried to match your code style as best I could when updating the tests, but they may need some adjustment to suit your preferences.

    Let me know if you have any comments/questions/concerns.

    No hard feelings on closure ❤️

    opened by stevebauman 5
  • Add elastic:migration:fresh command

    Add elastic:migration:fresh command

    Purpose

    This PR adds the elastic:migrate:fresh command. It mirrors Laravel's migrate:fresh command, which drops all database tables and re-runs all migrations. In this case, we drop all indicies and re-run migrations.

    Description

    When I'm running my integration tests that use ElasticSearch, I'm unable to use any provided command to drop all of the (non-system) indicies with an empty elastic_migrations table. If I need to drop any index, I have to use a raw command, or insert the migration into the DB table manually and then run elastic:migrate:rollback.

    This would allow us to easily use the below in our integration tests, making sure we have a completely fresh ES instance to work with during each test-case:

    public function setUp(): void
    {
        parent::setUp();
    
        $this->artisan('elastic:migrate:fresh');
    }
    
    public function test_with_clean_indexes()
    {
        // My integration test...
    }
    

    More Info

    The pattern used here:

    $this->indexManager->get('*,-*.*');
    

    Will fetch all non-system indicies (ones that are prefixed with a period), excluding indexes such as Kibana indexes (.kibana, .kibana_task_manager).

    Dependents

    This PR relies on the recently submitted PR here:

    https://github.com/babenkoivan/elastic-adapter/pull/12


    As always, please let me know if you have any issues with the implementation. I'd love to work with you to get this implemented.

    Thanks for your time! ❤️

    opened by stevebauman 5
  • ERROR:

    ERROR: "Target [ElasticMigrations\IndexManagerInterface] is not instantiable" when running "php artisan elastic:migrate" command

    I've installed laravel/scout: 7.2.* babenkoivan/elastic-scout-driver: ^1.2 babenkoivan/elastic-scout-driver-plus: ^1.11 babenkoivan/elastic-migrations: ^1.2 in laravel 5.5.40

    but when running php artisan elastic:migrate command after creatig elastic migration for users, it is giving an error

    Target [ElasticMigrations\IndexManagerInterface] is not instantiable

    can anyone help me fix it?

    opened by Mutahhar 5
  • Error on install

    Error on install

    Hi,

    I'm tying to install your scout elasticsearch packages, but I'm stuck with an error on elastic-migrations :

    composer require babenkoivan/elastic-migrations
    Using version ^1.0 for babenkoivan/elastic-migrations
    ./composer.json has been updated
    Loading composer repositories with package information
    Updating dependencies (including require-dev)
    Package operations: 3 installs, 0 updates, 0 removals
      - Installing babenkoivan/elastic-adapter (v1.0.1) Loading from cache
      - Installing babenkoivan/elastic-client (v1.0.1) Loading from cache
      - Installing babenkoivan/elastic-migrations (v1.0.1) Loading from cache
    Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
    Package guzzlehttp/streams is abandoned, you should avoid using it. No replacement was suggested.
    Package guzzlehttp/ringphp is abandoned, you should avoid using it. No replacement was suggested.
    Writing lock file
    Generating autoload files
    > Illuminate\Foundation\ComposerScripts::postAutoloadDump
    > @php artisan package:discover
    
    In MigrationStorage.php line 24:
    
      rtrim() expects parameter 1 to be string, null given  
                                                            
    
    Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
    

    Looking at the code I guess I'm missing some conf item, 'elastic.migrations.storage_directory', but pretty new to Laravel I don't know how to workaround.

    Thanks

    opened by ssayen 5
  • elastic:migrate clashes with the scout-elasticsearch-driver adapater

    elastic:migrate clashes with the scout-elasticsearch-driver adapater

    Hello, I just installed your package and seems like you are using same signature elastic:migrate for migrating inside https://github.com/babenkoivan/scout-elasticsearch-driver and https://github.com/babenkoivan/elastic-migrations this makes them clash and when installed in parallel it automatically picks the one from driver ...

    Is it possible to namespace commands in this package to some different so it doesn't clash? Thanks!

    opened by MilosMosovsky 5
  • Invalid Argument Exception on `elastic:migrations:fresh`

    Invalid Argument Exception on `elastic:migrations:fresh`

    | Software | Version | ------------- | --------------- | PHP | 8.0.13 | Elasticsearch | 7.15.1 | Laravel | 8.68.1

    Describe the bug I tried to start over my elasticsearch migrations by running php artisan elastic:migrate:fresh. ElasticSearch responds with the following error:

       Elasticsearch\Common\Exceptions\BadRequest400Exception 
    
      {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Wildcard expressions or all indices are not allowed"}],"type":"illegal_argument_exception","reason":"Wildcard expressions or all indices are not allowed"},"status":400}
    
      at vendor/elasticsearch/elasticsearch/src/Elasticsearch/Connections/Connection.php:693
        689▕             $exception = new ScriptLangNotSupportedException($responseBody. $statusCode);
        690▕         } elseif ($statusCode === 408) {
        691▕             $exception = new RequestTimeout408Exception($responseBody, $statusCode);
        692▕         } else {
      ➜ 693▕             $exception = new BadRequest400Exception($responseBody, $statusCode);
        694▕         }
        695▕ 
        696▕         $this->logRequestFail($request, $response, $exception);
        697▕ 
    
          +25 vendor frames 
      26  artisan:37
          Illuminate\Foundation\Console\Kernel::handle()
    

    Current behavior NO Index is being freshly migrated, instead Exception is thrown.

    Expected behavior ALL Indexes should be freshly migrated.

    bug stale 
    opened by chrisribal 4
  • Setting blank `ELASTIC_HOST` causes exception during `composer dump-autoload`

    Setting blank `ELASTIC_HOST` causes exception during `composer dump-autoload`

    | Software | Version | ------------- | --------------- | PHP | 7.4.21 | Elasticsearch | 7.12.1 | Laravel | 8.52.0

    Describe the bug If you set ELASTIC_HOST to a blank string or null, the FreshCommand asks for an instance of IndexManagerInterface, which in turn attempts to create an ElasticSearch client with configuration.

    https://github.com/babenkoivan/elastic-client/blob/9d4eab0ce97c48e60cf63c8fee7a547d41045129/config/elastic.client.php#L5

    This is a problem due to running application tests using <env> supplied by a phpunit.xml file, rather than an actual .env file:

    [2021-07-28 13:46:24] local.ERROR: Could not parse URI: "http://" {"exception":"[object] (Elasticsearch\\Common\\Exceptions\\InvalidArgumentException(code: 0): Could not parse URI: \"http://\" at /app/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php:809)
    [stacktrace]
    #0 /app/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php(768): Elasticsearch\\ClientBuilder->extractURIParts('http://')
    #1 /app/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php(715): Elasticsearch\\ClientBuilder->buildConnectionsFromHosts(Array)
    #2 /app/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php(667): Elasticsearch\\ClientBuilder->buildTransport()
    #3 /app/vendor/elasticsearch/elasticsearch/src/Elasticsearch/ClientBuilder.php(217): Elasticsearch\\ClientBuilder->build()
    #4 /app/vendor/babenkoivan/elastic-client/src/ServiceProvider.php(41): Elasticsearch\\ClientBuilder::fromConfig(Array)
    #5 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(869): ElasticClient\\ServiceProvider::ElasticClient\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
    #6 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(754): Illuminate\\Container\\Container->build(Object(Closure))
    #7 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\\Container\\Container->resolve('Elasticsearch\\\\C...', Array, true)
    #8 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\\Foundation\\Application->resolve('Elasticsearch\\\\C...', Array)
    #9 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\\Container\\Container->make('Elasticsearch\\\\C...', Array)
    #10 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(1027): Illuminate\\Foundation\\Application->make('Elasticsearch\\\\C...')
    #11 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(947): Illuminate\\Container\\Container->resolveClass(Object(ReflectionParameter))
    #12 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(908): Illuminate\\Container\\Container->resolveDependencies(Array)
    #13 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(754): Illuminate\\Container\\Container->build('ElasticAdapter\\\\...')
    #14 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\\Container\\Container->resolve('ElasticAdapter\\\\...', Array, true)
    #15 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\\Foundation\\Application->resolve('ElasticAdapter\\\\...', Array)
    #16 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\\Container\\Container->make('ElasticAdapter\\\\...', Array)
    #17 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(1027): Illuminate\\Foundation\\Application->make('ElasticAdapter\\\\...')
    #18 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(947): Illuminate\\Container\\Container->resolveClass(Object(ReflectionParameter))
    #19 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(908): Illuminate\\Container\\Container->resolveDependencies(Array)
    #20 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(754): Illuminate\\Container\\Container->build('ElasticMigratio...')
    #21 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\\Container\\Container->resolve('ElasticMigratio...', Array, false)
    #22 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(294): Illuminate\\Foundation\\Application->resolve('ElasticMigratio...', Array, false)
    #23 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(869): Illuminate\\Container\\Container->Illuminate\\Container\\{closure}(Object(Illuminate\\Foundation\\Application), Array)
    #24 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(754): Illuminate\\Container\\Container->build(Object(Closure))
    #25 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(841): Illuminate\\Container\\Container->resolve('ElasticMigratio...', Array, true)
    #26 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(692): Illuminate\\Foundation\\Application->resolve('ElasticMigratio...', Array)
    #27 /app/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(826): Illuminate\\Container\\Container->make('ElasticMigratio...', Array)
    #28 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(175): Illuminate\\Foundation\\Application->make('ElasticMigratio...')
    #29 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(124): Illuminate\\Container\\BoundMethod::addDependencyForCallParameter(Object(Illuminate\\Foundation\\Application), Object(ReflectionParameter), Array, Array)
    #30 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Illuminate\\Container\\BoundMethod::getMethodDependencies(Object(Illuminate\\Foundation\\Application), Array, Array)
    #31 /app/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
    #32 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
    #33 /app/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
    #34 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(651): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
    #35 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call(Array)
    #36 /app/vendor/symfony/console/Command/Command.php(299): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
    #37 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
    #38 /app/vendor/symfony/console/Application.php(978): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
    #39 /app/vendor/symfony/console/Application.php(295): Symfony\\Component\\Console\\Application->doRunCommand(Object(ElasticMigrations\\Console\\FreshCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
    #40 /app/vendor/symfony/console/Application.php(167): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
    #41 /app/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
    #42 /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
    #43 /app/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
    #44 {main}
    "} 
    

    Resolution

    Console type-hinted dependencies should be moved to the handle methods so they are only retrieved when the commands are ran, instead of during every single request. Ex:

    Before:

    public function __construct(
        Migrator $migrator,
        MigrationRepository $migrationRepository,
        IndexManagerInterface $indexManager
    ) {
        // ...
    }
    

    After:

    public function handle(
        Migrator $migrator,
        MigrationRepository $migrationRepository,
        IndexManagerInterface $indexManager
    ) {
        // ...
    }
    

    https://laravel.com/docs/8.x/artisan#command-structure

    Note that we are able to request any dependencies we need via the command's handle method. The Laravel service container will automatically inject all dependencies that are type-hinted in this method's signature:

    To Reproduce

    1. Make a fresh Laravel application
    2. Run composer require babenkoivan/elastic-migrations
    3. Remove ELASTIC_HOST default value
    4. Run composer dump-autoload
    bug 
    opened by stevebauman 4
Releases(v3.1.0)
Owner
Ivan Babenko
Ivan Babenko
Maps Laravel Eloquent models to Elasticsearch types

Elasticquent Elasticsearch for Eloquent Laravel Models Elasticquent makes working with Elasticsearch and Eloquent models easier by mapping them to Ela

Elasticquent 1.3k Jan 4, 2023
Elasticsearch driver for Laravel Scout

Elasticsearch driver for Laravel Scout. Contents Compatibility Installation Configuration Basic Usage Advanced Search Migrations Pitfalls Compatibilit

Ivan Babenko 197 Dec 19, 2022
Search among multiple models with ElasticSearch and Laravel Scout

For PHP8 support use php8 branch For Laravel Framework < 6.0.0 use 3.x branch The package provides the perfect starting point to integrate ElasticSear

Sergey Shlyakhov 592 Dec 25, 2022
Laravel 8.* Elasticsearch Eloquent

Elasticsearch Installation composer require etsetra/elasticsearch Create config file $ php artisan vendor:publish --tag="etsetra-elasticsearch-config

Etsetra 2 Jan 14, 2022
Official PHP low-level client for Elasticsearch.

elasticsearch-php Official low-level client for Elasticsearch. Its goal is to provide common ground for all Elasticsearch-related code in PHP; because

elastic 5k Dec 31, 2022
Elastica is a PHP client for elasticsearch

Elastica: elasticsearch PHP Client All documentation for Elastica can be found under Elastica.io. If you have questions, don't hesitate to ask them on

Nicolas Ruflin 2.2k Dec 23, 2022
Store and retrieve objects from Algolia or Elasticsearch

Store and retrieve objects from a search index This is an opinionated Laravel 5.1 package to store and retrieve objects from a search index. Currently

Spatie 440 Dec 30, 2022
Build and execute an Elasticsearch search query using a fluent PHP API

PACKAGE IN DEVELOPMENT, DO NOT USE YET Build and execute ElasticSearch queries using a fluent PHP API This package is a lightweight query builder for

Spatie 94 Dec 14, 2022
This package offers advanced functionality for searching and filtering data in Elasticsearch.

Scout Elasticsearch Driver ?? Introducing a new Elasticsearch ecosystem for Laravel. ?? This package offers advanced functionality for searching and f

Ivan Babenko 1.2k Dec 20, 2022
Official PHP low-level client for Elasticsearch.

elasticsearch-php Official low-level client for Elasticsearch. Its goal is to provide common ground for all Elasticsearch-related code in PHP; because

elastic 5k Jan 1, 2023
This modules provides a Search API Backend for Elasticsearch.

Search API ElasticSearch This modules provides a Search API Backend for Elasticsearch. This module uses the official Elasticsearch PHP Client. Feature

null 1 Jan 20, 2022
Search products, categories, brands or tags with ElasticSearch

ElasticSearch for Shopaholic This plugin allows you to use ElasticSearch as search engine for Shopaholic. Benefits Easy to install, easy to use Opened

Biz-Mark 4 Feb 18, 2022
Query Builder for Elasticsearch

Query Builder for Elasticsearch

wangzhiqiang 5 Mar 2, 2022
[Deprecated] We now recommend using Laravel Scout, see =>

[DEPRECATED] Algolia Search API Client for Laravel Algolia Search is a hosted full-text, numerical, and faceted search engine capable of delivering re

Algolia 240 Nov 25, 2022
A search package for Laravel 5.

Search Package for Laravel 5 This package provides a unified API across a variety of different full text search services. It currently supports driver

Mark Manos 354 Nov 16, 2022
A php trait to search laravel models

Searchable, a search trait for Laravel Searchable is a trait for Laravel 4.2+ and Laravel 5.0 that adds a simple search function to Eloquent Models. S

Nicolás López Jullian 2k Dec 27, 2022
Driver for Laravel Scout search package based on https://github.com/teamtnt/tntsearch

TNTSearch Driver for Laravel Scout - Laravel 5.3 - 8.0 This package makes it easy to add full text search support to your models with Laravel 5.3 to 8

TNT Studio 1k Dec 27, 2022
Laravel Scout provides a driver based solution to searching your Eloquent models.

Introduction Laravel Scout provides a simple, driver-based solution for adding full-text search to your Eloquent models. Once Scout is installed and c

The Laravel Framework 1.3k Dec 31, 2022
Unmaintained: Laravel Searchy makes user driven searching easy with fuzzy search, basic string matching and more to come!

!! UNMAINTAINED !! This package is no longer maintained Please see Issue #117 Here are some links to alternatives that you may be able to use (I do no

Tom Lingham 533 Nov 25, 2022