【发布时间】:2016-12-30 10:42:53
【问题描述】:
我在 content 中有一个 HTML 字符串,例如:
"content": "<h3><a href=\"http://blog.local/page/%D8%A2%D8%B2%D8%A7%D8%AF\">The Matrix has you </a></h3>follow the white rabbit."
我使用"fragment_size" : 150 来控制高亮片段的字符大小,但它返回一个带有损坏的 HTML 标签的子字符串:
"highlight": {
"content": [
"/%D8%A2%D8%B2%D8%A7%D8%AF">The <em>Matrix</em> has"
]
}
如何在基于 JSON 的查询 DSL 中修复它?
{
"query": {
"filtered": {
"query": {
"multi_match": {
"query": "matrix",
"fields": ["title","content"]
}
},
"filter": {
"term": { "content_type": "page" }
}
}
},
"highlight" : {
"order" : "score",
"fields" : {
"content" : {"fragment_size" : 150, "number_of_fragments" : 3}
}
}
}
这是一个示例响应:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.98773545,
"hits": [
{
"_index": "myindex",
"_type": "post",
"_id": "101",
"_score": 0.024953224,
"_source": {
"ID": 101,
"content_type": "page",
"date": "1999-02-18 14:32:21",
"title": "Wake up, Neo",
"content": "<h3><a href=\"http://blog.local/page/%D8%A2%D8%B2%D8%A7%D8%AF\">The Matrix has you </a></h3>follow the white rabbit."
},
"highlight": {
"content": [
"/%D8%A2%D8%B2%D8%A7%D8%AF">the <em>matrix</em> has"
]
}
}
]
}
}
【问题讨论】:
标签: html elasticsearch tags highlight querydsl