matchish / laravel-scout-elasticsearch

Search among multiple models with ElasticSearch and Laravel Scout
MIT License
711 stars 114 forks source link

No data imported after scout:import #83

Open booni3 opened 4 years ago

booni3 commented 4 years ago

I am sure I am just missing something here but just cannot get any data to import into elasticsearch. I am using 7.0.1 with the latest version of your package and have installed into a fresh Laravel install to ensure nothing else was interfering.

Steps To Reproduce

  1. Install fresh version of Laravel (v6.13.1)
  2. Create posts model/migration and seed with 1000 rows.
  3. Install matchish/laravel-scout-elasticsearch, publish config, add service provider.
  4. update config and env as below.
return [
    'host' => env('ELASTICSEARCH_HOST'),
    'indices' => [
        'mappings' => [
            'default' => [
                'properties' => [
                    'id' => [
                        'type' => 'keyword',
                    ]
                ],
            ],
            'posts' => [
                'properties' => [
                    'id' => ['type' => 'keyword'],
                    'name' => ['type' => 'text'],
                ],
            ],
        ],
        'settings' => [
            'default' => [
                'number_of_shards' => 1,
                'number_of_replicas' => 0,
            ],
        ],
    ],
];

image

  1. add searchable to post model as below.
class Post extends Model
{
    use Searchable;

    protected $fillable = [
        'name'
    ];

    public function searchableAs()
    {
        return 'posts';
    }
}
  1. Install elastic search with docker at v7.0.1

  2. php artisan scout:import - this shows me 100% and 6/6 imported. I assume the 6/6 is the rows imported? I have 1000 rows seeded in the database however.

image

  1. Check elasticsearch via Dejavu. I see the mappings were correctly set but it shows no data:

image

booni3 commented 4 years ago

That always happens... work on an issue for hours and post for help and then immediately solve it!

Turns out you need to actually publish the scout service provider. I generally don't publish the configs as most seem to work when left in the vendor. Seems not in this case!

matchish commented 4 years ago

@booni3 Actually you are right at some point, it's better when a package works after composer install without config. In case of Elasticsearch I can't imagine application without customizing config but yes it will be better if the package works without publishing the config.

booni3 commented 4 years ago

@mackhankins - I am glad you partly agree, and thanks for such a fast reply!

But actually in this case my issue was with the Scout config that was not published. I am not sure if its the combination of scout and this package that causes the issue or if scout has just been designed to required the config to be published. Will need to investigate further.

Side note; This is my first experience with elastic search and so far I am impressed. I hope I will be able to contribute at some point to this package!

booni3 commented 4 years ago

I have just upgraded to the latest version and I seem to have the above issue again on Local development. On our AWS server, there is no issue, but locally when running an import or adding new records to the DB we do not see any records within elastic search.

My setup is:

When running an import we get:

I have checked my installation, cleared cache/config etc.

Has anything changed around the service provider issue as above or anything else around local development setup?

matchish commented 4 years ago

Now config from vendor will be merged by default if you publish ElasticSearchServiceProvider. Did you publish elasticsearch provider?

matchish commented 4 years ago

I think maybe it's better to autoload it also by default. And if someone wants to override it, he can do it app service provider.