Jeroen-G / Explorer

🗺️ Next-gen Elasticsearch driver for Laravel Scout.
https://jeroen-g.github.io/Explorer/
MIT License
365 stars 61 forks source link

Model not being imported #198

Open iamkaarp opened 1 year ago

iamkaarp commented 1 year ago

Hi.

I am running the following commands

  1. php artisan scout:index systems
  2. php artisan scout:import "App\Model\System"

it all says its good and imported

Imported [App\Models\System] models up to ID: 1367267
All [App\Models\System] records have been imported.

Under Index Management in Kibana I have 0 docs on index systems

    public function mappableAs(): array
    {
        $array = [
            'id' => 'keyword',
            'name' => 'text',
            'address' => 'keyword',
            'x' => 'integer',
            'y' => 'integer',
            'z' => 'integer',
            'distance' => 'float',
            'faction_id' => 'integer',
            'economy' => 'keyword',
            'second_economy' => 'keyword',
            'allegiance' => 'keyword',
            'government' => 'keyword',
            'security' => 'keyword',
            'population' => 'long',
            'powers' => 'text',
            'pps' => 'text',
            'updated_at' => 'date',
        ];
        return $array;
    }

    public function toSearchableArray(): array
    {
        return [
            'name' => $this->name,
            'address' => $this->address,
            'x' => $this->x,
            'y' => $this->y,
            'z' => $this->z,
            'distance' => $this->distance,
            'faction_id' => $this->faction_id,
            'economy' => $this->economy,
            'second_economy' => $this->second_economy,
            'allegiance' => $this->allegiance,
            'government' => $this->government,
            'security' => $this->security,
            'population' => $this->population,
            'powers' => $this->powers,
            'pps' => $this->pps,
            'updated_at' => $this->updated_at,
        ];
    }
electronick86 commented 1 year ago

Helo, I have simillar issue and I find hard to diagnose the issue. I found that sometime if the mappableAs() array doen't perfectly match the toSearchableArray() array, the bulk doesn't works... but the job Laravel\Scout\Jobs\MakeSearchable is marked as completed and I don't find a way to see the output of the response ELS during the bulk request.

Any idea?

eual8 commented 1 year ago

I have the same problem with import. In the console the result is successful, but in the elastic logs there are not even requests to add documents.

public function mappableAs(): array
    {
        return [
            'id' => 'keyword',
            'text' => 'text',
            'time_string' => 'keyword',
            'video_id' => 'keyword',
            'is_autogenerated' => 'boolean',
        ];
    }

    public function toSearchableArray(): array
    {
        return [
            'id' => $this->id,
            'text' => $this->text,
            'time_string' => $this->time_string,
            'video_id' => $this->video_id,
            'is_autogenerated' => $this->is_autogenerated,
        ];
    }
Imported [App\Models\Fragment] models up to ID: 118019
All [App\Models\Fragment] records have been imported.
Jeroen-G commented 1 year ago

I'd need more to context to help you, such as the versions of Elastic and Explorer and your explorer config (minus the auth of course)

boss554 commented 7 months ago

Same issue as I import model it's showing successful but when I check kibana it's not showing. And as I am looking for attachment content search like I have Epub book when I search than it's will search on that epub file book. As I check ingest plugin is there in elastic search but I did not find any relevant information so any one have idea than let me know.

maher1337 commented 7 months ago

@Jeroen-G is there a way to eager load a relationship during the import process?

Jeroen-G commented 7 months ago

I don't know! I have a feeling that is more of a Laravel Scout thing then Explorer 🤔

joelatgrayv commented 3 months ago

The Scout docs mention this;:

https://laravel.com/docs/11.x/scout#modifying-the-import-query

If you would like to modify the query that is used to retrieve all of your models for batch importing, you may define a makeAllSearchableUsing method on your model. This is a great place to add any eager relationship loading that may be necessary before importing your models:

use Illuminate\Database\Eloquent\Builder;

/**
 * Modify the query used to retrieve models when making all of the models searchable.
 */
protected function makeAllSearchableUsing(Builder $query): Builder
{
    return $query->with('author');
}

and I do indeed now see the relationship in ES.

@Jeroen-G, for the nested mapping , was that your intended way to get the relationships filled out? Or do you eager load all your models?

I should also note, this seems only one way. It stores it in ES but later when getScoutModelsByIds is called to get fresh data, those nested models aren't used because it pulls fresh data from MySQL. If you are using response Resources, you can lazy load the nested models.

I was able to do the following in my model that implements Searchable to eager load the nested models:

public function getScoutModelsByIds(ExplorerBuilder $builder, array $ids)
{
        $builder->queryCallback = function (EloquentBuilder $query) {
            $query->with($this->getNestedMappings());
        };
        // We override the default behavior of Searchable's implementation
        // That method just does the below. We call it directly because we can't
        // call the overridden trait's method directly
        return $this->queryScoutModelsByIds($builder, $ids)->get();
}
Jeroen-G commented 3 months ago

@Jeroen-G, for the nested mapping , was that your intended way to get the relationships filled out? Or do you eager load all your models?

Nested wasn't necessarily created for relationships, but I assume they could easily be used for them. Maybe in combination with toSearchableArray().