Explorer: Import OK but "Undefined array key hits" when search

Hi, I’m using you package, thanks a lot.

I have a App\Models\Questions, with the following code:

namespace App\Models;

use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use JeroenG\Explorer\Application\Explored;
use Laravel\Scout\Searchable;

class Question extends Model implements Explored
{
    use HasFactory, Searchable;

    /**
     * Get the name of the index associated with the model.
     *
     * @return string
     */
    public function searchableAs()
    {
        return 'questions_index';
    }

    public function mappableAs(): array
    {
        return [
            'external_uid',
            'title',
            'index_rubrique',
            'index_analyse',
            'question_texte',
            'reponse_texte',
            'question_parution_jo',
            'reponse_parution_jo',
        ];
    }
}

I made a php artisan scout:import "App\Models\Question" and it seems to go well:

Imported [App\Models\Question] models up to ID: 500
Imported [App\Models\Question] models up to ID: 1000
Imported [App\Models\Question] models up to ID: 1500
Imported [App\Models\Question] models up to ID: 2000
Imported [App\Models\Question] models up to ID: 2500
Imported [App\Models\Question] models up to ID: 3000
Imported [App\Models\Question] models up to ID: 3500
Imported [App\Models\Question] models up to ID: 4000
Imported [App\Models\Question] models up to ID: 4500
Imported [App\Models\Question] models up to ID: 5000
(...)
Imported [App\Models\Question] models up to ID: 92729
All [App\Models\Question] records have been imported.

But, I can’t see anything in my elastic server (I am using Elastron to browse, and I can’t see my questions_index). Moreover, when I execute php artisan elastic:search "App\Models\Question" ministre:

Starting to search for ministre

In Results.php line 41:
  Undefined array key "hits"

Do you know what happen, or what I did wrong?

Thanks for your help.


Edit:

Here is my config/explorer.php:

declare(strict_types=1);

return [
    /*
     * There are different options for the connection. Since Explorer uses the Elasticsearch PHP SDK
     * under the hood, all the host configuration options of the SDK are applicable here. See
     * https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/configuration.html
     */
    'connection' => [
        'host'   => env('ELASTICSEARCH_HOST', 'localhost'),
        'port'   => env('ELASTICSEARCH_PORT', '9200'),
        'scheme' => env('ELASTICSEARCH_SCHEME', 'https'),
        'auth' => [
            'username' => env('ELASTICSEARCH_USER', ''),
            'password'   => env('ELASTICSEARCH_PASS', ''),
        ],
    ],


    /**
     * An index may be defined on an Eloquent model or inline below. A more in depth explanation
     * of the mapping possibilities can be found in the documentation of Explorer's repository.
     */
    'indexes' => [
        // \App\Models\Post::class
        \App\Models\Question::class,
    ],

    /**
     * You may opt to keep the old indices after the alias is pointed to a new index.
     * A model is only using index aliases if it implements the Aliased interface.
     */
    'prune_old_aliases' => true,
];

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (18 by maintainers)

Most upvoted comments

I can also create my own provider, what I’ve done 😉

But I will try a PR, you are right 😃