babenkoivan / elastic-migrations

Elasticsearch migrations for Laravel
MIT License
189 stars 32 forks source link

Empty indeces and custom migration names #12

Closed chrisgrim closed 3 years ago

chrisgrim commented 3 years ago

Hi! I am very excited to get this working as I was using scout-elasticsearch-driver before and I loved it.

I am using

"babenkoivan/elastic-client": "^1.1",
        "babenkoivan/elastic-migrations": "^1.3",
        "babenkoivan/elastic-scout-driver": "^1.2",
        "babenkoivan/elastic-scout-driver-plus": "^1.12",

and I have created a user index

<?php
declare(strict_types=1);

use ElasticAdapter\Indices\Mapping;
use ElasticAdapter\Indices\Settings;
use ElasticMigrations\Facades\Index;
use ElasticMigrations\MigrationInterface;

final class CreateUsersIndex implements MigrationInterface
{
    /**
     * Run the migration.
     */
    public function up(): void
    {
        Index::create('users', function (Mapping $mapping, Settings $settings) {
            $mapping->text('name');
            $mapping->keyword('email');
        });
    }

    /**
     * Reverse the migration.
     */
    public function down(): void
    {
        Index::dropIfExists('users');
    }
}

I ran the migration and it was created. Then I ran php artisan scout:import "App\Models\User" and it says Imported [App\Models\User] models up to ID: 368

However if I do http://127.0.0.1:9200/create_users_index it shows that there is "no such index [create_users_index]",

Then when I try and do a search

 return  User::boolSearch()
        ->should('match', ['name' => 'Chris'])
        ->minimumShouldMatch(1)
        ->paginate(2);

it returns nothing. I guess I am a bit confused because with scout-elasticsearch-driver I ran php artisan elastic:create-index "App\Models\UserIndexConfigurator"; and then php artisan scout:import "App\Models\User"; and I could see them in the indeces.

chrisgrim commented 3 years ago

Sorry I was too quick. I got it working.