2016-11-07 11 views
1

私は弾性検索-phpで私の結果を強調しようとしています。知識とGoogleで検索してみましたが、同じ質問はセンスで完璧に働いていません。ある意味では、私のクエリは私が必要なものを引き起こす正確な取得上記のクエリと弾性検索の結果を強調表示する

GET /bank/account/_search 
{ 
"query" : { 
    "match_phrase" : { 
     "address" : "mill" 
    } 
}, 
"highlight": { 
    "pre_tags" : ["<tag1>"], 
    "post_tags" : ["</tag1>"], 
    "fields" : { 
     "address" : {} 
    } 
} 
} 

で、これは私は私が強調された結果を得るわけではないのPHPを使用して、同じクエリを試してみました

highlight": { 
      "address": [ 
       "990 <tag1>Mill</tag1> Road" 
      ] 
     } 

を得た結果は、私の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で結果をエンコードすると結果がエンコードされます。

私の解決策は、

"highlight": { 
     "address": [ 
     "817 Campus </span>Road</span>" 
     ] 
    } 
です
関連する問題