试试搜索一下吧

在6.0.0以后,使用custom field代替_all,但如何解决高亮问题?大家在全文搜索时是如何高亮的?

Elasticsearch | 作者 tygcs | 发布于2018年10月24日 | 阅读数:1917

_all文档:https://www.elastic.co/guide/e ... .html

这里功能上可以被代替,搜索是没有问题的,但是搜索完了如何高亮呢?
不知道大家在全文搜索时是如何高亮的?
已邀请:

rochy - rochy_he

赞同来自:

搜索的时候设置高亮字段即可,例如你的自定义字段叫 my_all;
那你搜索的时候搜索 my_all 字段,高亮设置 my_all 字段即可;
搜索结果里面,可以看到 highlight 节点,里面就包含了高亮结果
可以参考下面官方案例
GET twitter/_search
{
"query" : {
"match_phrase": { "message": "number 1" }
},
"highlight" : {
"fields" : {
"message" : {
"type": "plain",
"fragment_size" : 15,
"number_of_fragments" : 3,
"fragmenter": "simple"
}
}
}
}

{
...
"hits": {
"total": 1,
"max_score": 1.601195,
"hits": [
{
"_index": "twitter",
"_type": "_doc",
"_id": "1",
"_score": 1.601195,
"_source": {
"user": "test",
"message": "some message with the number 1",
"date": "2009-11-15T14:12:12",
"likes": 1
},
"highlight": {
"message": [
" with the <em>number</em>",
" <em>1</em>"
]
}
}
]
}
}

要回复问题请先登录注册