1
我想突出顯示我的結果在彈性搜索-php,我嘗試了很多與我的知識和搜索在谷歌,但沒有運氣,相同的查詢在Sense完美工作。我的感覺查詢使用彈性搜索突出顯示彈性搜索結果-php
GET /bank/account/_search
{
"query" : {
"match_phrase" : {
"address" : "mill"
}
},
"highlight": {
"pre_tags" : ["<tag1>"],
"post_tags" : ["</tag1>"],
"fields" : {
"address" : {}
}
}
}
與上面的查詢,我得到確切的結果我需要什麼,這是我得到
highlight": {
"address": [
"990 <tag1>Mill</tag1> Road"
]
}
我使用PHP我沒有得到突出顯示的結果嘗試了同樣的查詢結果我的PHP查詢
<?php
require 'vendor/autoload.php';
$client=new Elasticsearch\Client();
$indexParams = [
'index' => 'bank',
'type' => 'account',
'body' => [
'query' => [
'match' => [
"address" => "mill"
],
],
'highlight' => [
"pre_tags" => "<tag1>",
"post_tags" => "</tag1>",
'fields' => [
'address' => new \stdClass()
]
],
]
];
$results = $client->search($indexParams);
try {
$response = $client->search($indexParams);
} catch (Exception $e) {
var_dump($e->getMessage());
}
echo '<pre>',print_r($response),'</pre>';
?>
結果我AAM得到的是
[highlight] => Array
(
[address] => Array
(
[0] => 715 Mill Avenue
)
)