2017-02-26 66 views
0

當我嘗試在查詢中匹配一個字段時,所有內容都可以正常使用highlighting in elasticsearch彈性搜索中的多重匹配和突出顯示

當我嘗試使用:

$params = [ 
'index' => 'my_index', 
'type' => 'articles', 
'body' => [ 
    'from' => '0', 
    'size' => '10', 
    'query' => [ 
     'bool' => [ 
      'must' => [ 
       'match' => [ 'content' => 'what I want to search' ] 
       ] 
      ] 
    ], 
    'highlight' => [ 
     'pre_tags' => ['<mark>'], 
     'post_tags' => ['</mark>'], 
     'fields' => [ 
      'content' => [ 'fragment_size' => 150, 'number_of_fragments' => 3 ] 
     ] 
    ], 
] 

]。

一切正常,但是當我嘗試捕捉多個字段時,我的搜索正常工作,但突出顯示消失。

'match' => [ 'content' => 'what I want to search' ], 
'match' => [ 'type' => 1 ] 

你知道如何實現功能突出,當我想在兩個不同領域的應用搜索有兩個不同的查詢?

+0

你找到一個解決的辦法? – Bildsoe

回答

0

試試這個:

$params = [ 
    'index' => 'my_index', 
    'type' => 'articles', 
    'body' => [ 
     'from' => '0', 
     'size' => '10', 
     'query' => [ 
      'bool' => [ 
      'must' => [ 
       'match' => [ 'content' => 'what I want to search' ] 
       ] 
      ], 
       'filter' => ['type' => 1] 
     ] 
      ] ], 
    'highlight' => [ 
     'pre_tags' => ['<mark>'], 
     'post_tags' => ['</mark>'], 
     'fields' => [ 
      'content' => [ 'fragment_size' => 150, 'number_of_fragments' => 3 ] 
     ] 
    ], 
] 
相關問題