rubenSousa
rubenSousa

Reputation: 291

Error nodes is not defined in Typesense Configuration on Laravel

I'm trying to set up Typesense with Laravel Scout in my Laravel application, but I'm encountering the following error when I run php artisan scout:import:

Typesense\Exceptions\ConfigError 

  `nodes` is not defined.

  at vendor/typesense/typesense-php/src/Lib/Configuration.php:121

Here are the relevant parts of my configuration:

    <?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;

class Modello extends Model
{
    use Searchable;
    protected $table = 'modello';
    protected $primaryKey = 'mo_id';

    /**
     * Get the indexable data array for the model.
     *
     * @return array<string, mixed>
     */
    public function toSearchableArray()
    {
        return array_merge($this->toArray(), [
            'id' => (string) $this->mo_id,
            'description' => $this->mo_descrizione,
        ]);
    }
}

This is the scout config

    <?php

use App\Models\User;

return [
    'driver' => env('SCOUT_DRIVER', 'typesense'),

    'prefix' => env('SCOUT_PREFIX', ''),

    'queue' => env('SCOUT_QUEUE', false),

    'after_commit' => false,

    'chunk' => [
        'searchable' => 500,
        'unsearchable' => 500,
    ],

    'soft_delete' => false,

    'identify' => env('SCOUT_IDENTIFY', false),

    'typesense' => [
        'client-settings' => [
            'api_key' => env('TYPESENSE_API_KEY', 'xyz'),
            'nodes' => [
                [
                    'host' => env('TYPESENSE_HOST', 'localhost'),
                    'port' => env('TYPESENSE_PORT', '8108'),
                    'path' => env('TYPESENSE_PATH', ''),
                    'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
                ],
            ],
            'connection_timeout_seconds' => env('TYPESENSE_CONNECTION_TIMEOUT_SECONDS', 2),
            'healthcheck_interval_seconds' => env('TYPESENSE_HEALTHCHECK_INTERVAL_SECONDS', 30),
            'num_retries' => env('TYPESENSE_NUM_RETRIES', 3),
            'retry_interval_seconds' => env('TYPESENSE_RETRY_INTERVAL_SECONDS', 1),
        ],
        'model-settings' => [
            User::class => [
                'collection-schema' => [
                    'fields' => [
                        ['name' => 'name', 'type' => 'string'],
                        ['name' => 'email', 'type' => 'string'],
                        ['name' => 'created_at', 'type' => 'int64'],
                        ['name' => '__soft_deleted', 'type' => 'int32', 'optional' => true],
                    ],
                    'default_sorting_field' => 'created_at',
                ],
                'search-parameters' => [
                    'query_by' => 'name,email',
                ],
            ],
        ],
    ],
];

e infine il file .env

SCOUT_DRIVER=typesense
TYPESENSE_API_KEY=MY_KEY
TYPESENSE_HOST=localhost
TYPESENSE_PORT=8108
TYPESENSE_PROTOCOL=http

I've made sure that my Typesense server is running and accessible. Despite this, I'm still getting the nodes is not defined error. What could be causing this issue and how can I resolve it?

Thank you for your help!

Upvotes: 2

Views: 167

Answers (0)

Related Questions