Home > Article > Backend Development > Why can't highlighted data be returned using elasticsearch-php laravel?
<code> namespace App\Http\Controllers\Search; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use Elasticsearch\Client; class Index extends Controller { protected $client; public function __construct(Client $client) { $this->client = $client; } public function search_test(Request $request,$filter='list'){ $word = trim($request->input('word')); $s=is_null($request->input('s'))?10:trim($request->input('s'));//一页多少条 $f=is_null($request->input('f'))?1:trim($request->input('f'));//当前页数 $fr=($f-1)*$s;//当前页从第一条记录开始 $params=[ 'index' => 's_index', 'type' => 's_type', 'body' => [ 'query' => [ 'bool' => [ 'should' => [ [ 'match' => [ 'title' => $word ] ], [ 'match' => [ 'description' => $word ] ], ] ] ] ,'from'=>$fr, 'size'=>$s ,'highlight'=>[ 'fields'=>[ 'title'=>[] ] ] ] ]; $response = $this->client->search($params); echo "<pre class="brush:php;toolbar:false">"; var_dump($response); echo ""; } }
The query results can all be returned, but there is no highlight data. Please help me! ! !
<code> namespace App\Http\Controllers\Search; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Controllers\Controller; use Elasticsearch\Client; class Index extends Controller { protected $client; public function __construct(Client $client) { $this->client = $client; } public function search_test(Request $request,$filter='list'){ $word = trim($request->input('word')); $s=is_null($request->input('s'))?10:trim($request->input('s'));//一页多少条 $f=is_null($request->input('f'))?1:trim($request->input('f'));//当前页数 $fr=($f-1)*$s;//当前页从第一条记录开始 $params=[ 'index' => 's_index', 'type' => 's_type', 'body' => [ 'query' => [ 'bool' => [ 'should' => [ [ 'match' => [ 'title' => $word ] ], [ 'match' => [ 'description' => $word ] ], ] ] ] ,'from'=>$fr, 'size'=>$s ,'highlight'=>[ 'fields'=>[ 'title'=>[] ] ] ] ]; $response = $this->client->search($params); echo "<pre class="brush:php;toolbar:false">"; var_dump($response); echo ""; } }
The query results can all be returned, but there is no highlight data. Please help me! ! !
I haven’t done a search service yet. I feel that the highlighted data should be processed in the controller.