Explorer icon indicating copy to clipboard operation
Explorer copied to clipboard

Triggering new doc to get added to index

Open GioValentin opened this issue 3 years ago • 4 comments

is there a special way to continue feeding the index on the model events for saved and updated? It doesn't appear that the package creates a new doc or updates the doc after model manipulation.

I am not sure if I have something misconfigured or not.

GioValentin avatar Jul 25 '22 00:07 GioValentin

I assume you already have the Laravel Scout Searchable trait on your model. That should be enough. If not then there might be a bug in Explorer. If you don't know how to debug it you could try recreating the issue in the demo app for Explorer (https://github.com/Jeroen-G/explorer-demo) or, if possible, share your repository.

Jeroen-G avatar Jul 25 '22 19:07 Jeroen-G

Here is a bit more detail about the project and the implementations so far.

  1. I've implemented my own version of the the ExplorerServiceProvider.php

         `$this->app->bind(ElasticClientFactory::class, function () {
         $client = null;
         if(env('APP_ENV', 'local') != 'local') {
             $client = ClientBuilder::create()
                 ->setElasticCloudId(env('ELASTIC_CLOUD_ID', 'xxxxxx'))
                 ->setApiKey(env('ELASTIC_API_ID', 'xxxxxxx'), env('ELASTIC_API_KEY', 'xxxxxx'));
         } else {
             .... original client setup
         }`
    
  2. I've confirmed that the index does not update after the model is stored or searchable is called directly on the eloquent query in the demo app. I can debug further but I am not too sure if it's in the IndexAdapter or if it's not binding correctly. All of the other functions work perfectly, Flushing, importing, create index, and mapping.

I appreciate any guidance as to how to populate the index after updating or creating a new model.

GioValentin avatar Jul 26 '22 00:07 GioValentin

I believe Scout should call a method (don't know which one) on the Explorer Engine to update the index. If everything else works it probably is a bug in Explorer.

Jeroen-G avatar Jul 26 '22 12:07 Jeroen-G

I just had an issue with updating as well, in my case it was misconfiguration on my part. Scout defaults to the null engine, quite annoying and it defaults to queueing the update calls , while I didn't have any queues configured.

Ensure you have your SCOUT_DRIVER env var set to 'elastic' and set SCOUT_QUEUE to false for debugging.

The update process itself is is handled in the Searchable trait's queueMakeSearchable method (vendor/laravel/scout/src/Searchable.php:55). Here $models->first()->searchableUsing() should be the elastic engine. If it doesn't even hit queueMakeSearchable , look in the ModelObserver's saved method vendor/laravel/scout/src/ModelObserver.php:91, it is responsable for calling the searchable (and thus queueMakeSearchable) on the model when it has been saved.

Hope this helps!

blackshadev avatar Jul 28 '22 17:07 blackshadev