Elasticsearch and Laravel scout-elasticsearch-driver return an empty response Elasticsearch and Laravel scout-elasticsearch-driver return an empty response laravel laravel

Elasticsearch and Laravel scout-elasticsearch-driver return an empty response


Solution was to update the UserSearchRule:

<?php declare(strict_types = 1);namespace App\Models\SearchRules;use ScoutElastic\SearchRule;/** * Class UserSearchRule * * @package App\Models\SearchRules */class UserSearchRule extends SearchRule{    /**     * @inheritdoc     */    public function buildQueryPayload()    {        $query = $this->builder->query;        return [            'must'  => [                'multi_match'   => [                    'query'     => $query,                    'fields'    => ['first_name', 'last_name', 'nick_name'],                    'type'      => 'phrase_prefix',                ],            ],        ];    }}


I tried the answer but doesn't work on my end.

If the answer doesnt work, we can do this manually and get the hit results.

   $query = request()->has('q') ? request('q') : '*';   $results = Product::search($query)->raw()['hits'];   $products = collect($results['hits'])->pluck('_source');