2017-08-09 34 views
0

我目前正在爲AngularJS使用Elasticsearch的前端。搜索查詢工作得很好,希望從高亮度。Elasticsearch與AngularJS的高亮度

在我service.js我已經把我的搜索查詢,看起來像:

client.search({ 
      "index": "index_name", 
      "type": "index_type", 
      "body": { 
       "size": 10, 
       "from": offset, 
       "query": { 
        "query_string": { 
         "query": query 
        } 
       }, 
       "highlight" : { 
        "fields" : { 
         "*" : {} 
        } 
       } 
      } 
}).then(function(result) {...} 

我檢查了JSON在我的Chrome,但沒有現場亮點(因爲它應該是)

在Kibana我測試了此查詢強調:

GET /_search { 
    "query" : { 
     "match": { "message": "test" } 
    }, 
    "highlight" : { 
     "fields" : { 
      "*" : {} 
     } 
    } 
} 

,我得到的結果+ hightlighting

任何建議,感謝

回答

0

答案其實很簡單:

 client.search({ 
     index: CALACA_CONFIGS.index_name, 
     type: CALACA_CONFIGS.type, 
     body: { 
      size: CALACA_CONFIGS.size, 
      from: offset, 
      query: { 
       query_string: { 
        query: query 
       } 
      }, 
      highlight : { 
      require_field_match: false, <-- added this line 
       fields : { 
        "*" : {fragment_size: 10, number_of_fragments: 0} 
       } 
      } 
     } 
    }).then(function(result) { .. }