jenya's avatar
Level 2

Laravel Redisearch indexing problem

Hello everyone. I want to use Laravel Redisearch driver for Scout in my project. I have Ubuntu 18.04 with Redis server and full-text search extension for it. ( works fine from Redis CLI, I checked). Also I installed ethanhann/Laravel-RediSearch package and counfigure scout_driver variable in .env and in config/scout.php. When I want to import my model for indexing using scout:import command, error ocures: The field is not a property in the index. id My model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Search_test extends Model
{
   use Searchable;
 
    protected $primaryKey ='id';
    protected $table='Search_test';
    protected $connection = 'pgsql';

   public function toSearchableArray()
    {
      $array =  [
            'id'      => $this->id,
            'name'    => $this->name,
            'value' => $this->value
        ];
//There are only 3 fields :id, name and value
        return $array;
    }
    public function searchableAs()
    {
        return 'search_test_index';
    }
    
}

Please help. Thanks!

0 likes
3 replies
munazzil's avatar

I think that you don't need this is in your Model.

'id' => $this->id,

 public function toSearchableArray($id)
{
  $array =  [
     
        'name'    => $this->name,
        'value' => $this->value
    ];
//There are only 3 fields :id, name and value
        return $array;
    }
1 like
jenya's avatar
Level 2

@munazzil , thank you for a answer!

Edit: It works if I use array_only helper

 public function toSearchableArray()
    {
 
           return array_only($this->toArray(), [ 'name', 'value']);
    }
  

but it works once, if I want to import another model with the same stucture , error ocures The field is not a property in the index. id

Please or to participate in this conversation.