2017-10-05 91 views
0

我想突出顯示所有可搜索字段的搜索文本。elasticsearch hightlight查詢所有字段

我用this doc尋求幫助。 突出顯示不起作用,查詢得到正常結果沒有任何突出顯示。 查詢沒有得到突出顯示,我的查詢出了什麼問題?

我的elastisearch版本「5.5.2」

_mapping指數爲: -

{ 
    "products": { 
    "mappings": { 
     "product": { 
     "_all": { 
      "enabled": true 
     }, 
     "properties": { 
      "description": { 
      "type": "text" 
      }, 
      "price": { 
      "type": "long" 
      }, 
      "title": { 
      "type": "text", 
      "boost": 2 
      } 
     } 
     } 
    } 
    } 
} 

我elasticsearch查詢: -

curl -XGET 'localhost:9200/_search?pretty' -H 'Content-Type: application/json' -d' 
{ 
    "query" : { 
     "match": { "_all": "rock clamb" } 
    }, 
    "highlight" : { 
     "pre_tags" : ["<tag1>"], 
     "post_tags" : ["</tag1>"], 
     "fields" : { 
      "_all" : {} 
     } 
    } 
}' 

輸出:

{ 
    "took" : 2, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 6, 
    "successful" : 6, 
    "failed" : 0 
    }, 
"hits" : { 
    "total" : 2, 
    "max_score" : 0.99835247, 
    "hits" : [ 
     { 
     "_index" : "products", 
     "_type" : "product", 
     "_id" : "2", 
     "_score" : 0.99835247, 
     "_source" : { 
      "title" : "Push Clamb Car Holder for Samsung and iPhone", 
      "price" : 3, 
      "description" : "A high quality car holder for smartphones that features a push clamp function Features: Universal car holder Height adjustment pivot Ball shape 360" 
     } 
     }, 
     { 
     "_index" : "products", 
     "_type" : "product", 
     "_id" : "5", 
     "_score" : 0.7741236, 
     "_source" : { 
      "price" : 1, 
      "description" : "This item fits directly to all 3 power boxes (7850 7880 7890)Together in use these clamps are bi-polarEach individual clamb is uni-polar cable include", 
      "title" : "Rimba Luxurous Electrosex clamps Uni-polar (2 pcs) - Naughty" 
     } 
     } 
    ] 
    } 
} 

回答

0

爲了執行突出顯示,該字段的實際內容是必需的。如果有問題的字段被存儲(在映射中存儲設置爲true),它將被使用,否則,實際的_source將被加載並且相關字段將從其中被提取。

_all字段無法從_source中提取,因此只能用於突出顯示映射到的商店是否已將商店設置爲true。參考鏈接https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html#plain-highlighter

相關問題