2017-10-05 114 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