2016-11-07 186 views
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 
            ) 

          ) 

回答

1

我得到了上述问题的答案,我发送参数的形式JSON和JSON编码的结果,当我编码JSON的结果在那个pre标签突出显示查询。

我的解决办法是

"highlight": { 
     "address": [ 
     "817 Campus </span>Road</span>" 
     ] 
    }