Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model not being imported #198

Open
iamkaarp opened this issue May 22, 2023 · 9 comments
Open

Model not being imported #198

iamkaarp opened this issue May 22, 2023 · 9 comments

Comments

@iamkaarp
Copy link

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
Copy link

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
Copy link

eual8 commented Sep 27, 2023

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
Copy link
Owner

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
Copy link

boss554 commented Feb 29, 2024

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
Copy link

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

@Jeroen-G
Copy link
Owner

Jeroen-G commented Mar 8, 2024

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

@joelatgrayv
Copy link

joelatgrayv commented Jul 12, 2024

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
Copy link
Owner

@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().

@AmirVahedix
Copy link

I had the same issue and the reason was that I forgot a simple thing:
when I defined the toSearchableArray() method, I just mentioned the field names and forgot to set the values.
it should be like this:

    public function toSearchableArray()
    {
        return [
            'id' => $this->id,
            'title' => $this->title,
            'body' => $this->body,
            'created_at' => $this->created_at
        ];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants