I am trying to add search function to my website, using Elasticsearch + Laravel
The package I use can be found here: https://github.com/cviebrock/laravel-elasticsearch
So far I am able to get everything work except highlight. Here is my PHP code:
$params = [
'index' => 'my_index',
'type' => 'web_page',
'body' => [
'query' => [
'bool' => [
'must' => [
[
'match' => [ 'combined' => $keywords ]
],
[
'match' => [ 'status' => 1 ],
]
]
]
],
'highlight' => [
'pre_tags' => '<em>',
'post_tags' => '</em>',
'fields' => [
'combined' => new \stdClass()
]
],
]
];
try {
$results = Elasticsearch::search($params);
} catch (Exception $e) {
var_dump($e->getMessage());
}
dd($results);
The results I get is like the following:
array:4 [▼
"took" => 250
"timed_out" => false
"_shards" => array:3 [▶]
"hits" => array:3 [▼
"total" => 2
"max_score" => 0.8117509
"hits" => array:2 [▼
0 => array:5 [▶]
1 => array:5 [▼
"_index" => "my_index"
"_type" => "web_page"
"_id" => "wp_2"
"_score" => 0.4709723
"_source" => array:7 [▶]
]
]
]
]
As you may see, I am missing 'highlight' field which is supposed to come after "_source".
I did follow instructions described in the following page:
Checked several related questions here, but still cannot figure out what I did wrong.