[英]Highlight in Elasticsearch
This is my elasticsearch query:这是我的 elasticsearch 查询:
GET indexname/_search
{
"fields": ["_id", "url","T"],
"query" : {
"bool": {"should": [
{"simple_query_string": {
"query": "white",
"fields": ["T", "content"]
}}
]}
},
"highlight" : {
"pre_tags": ["<b>"],
"post_tags": ["</b>"],
"fields" : {
"content" : {"fragment_size" : 150, "number_of_fragments" : 1}
}
}
}
My elasticsearch query is searching for white in the fields "T" and "content", and I am highlighting the field "content" and inserting a pre and post tag b(bold).我的 elasticsearch 查询在字段“T”和“内容”中搜索白色,我突出显示字段“内容”并插入前后标记 b(粗体)。 This is the result of my query
这是我查询的结果
"hits": {
"total": 922,
"max_score": 2.369757,
"hits": [
{
"_index": "indexname",
"_type": "Searchtype",
"_id": "http://www.example.com/de/unternehmenssuche-white-paper",
"_score": 2.369757,
"fields": {
"T": [
"White Paper Unternehmenssuche"
],
"url": [
"http://www.example.com/de/unternehmenssuche-white-paper"
]
},
"highlight": {
"content": [
"/Anwendungsbeispiele Ressourcen Blog <b>White</b> Papers in Deutsche Downloads Wiki Unternehmen Vorstellung der Search Executive"
]
}
}
....
...
I want my highlight result to look like this我希望我的突出显示结果看起来像这样
"highlight": {
"content": [
"<b>...</b> /Anwendungsbeispiele Ressourcen Blog <b>White</b> Papers in Deutsche Downloads Wiki Unternehmen Vorstellung der Search Executive <b>...</b>"
]
}
I want to add <b>...</b>
before and after the highlight content.我想在突出显示内容前后添加
<b>...</b>
。 What should I add in my elasticsearch query to make results look like this?我应该在我的 elasticsearch 查询中添加什么以使结果看起来像这样?
As I stated in the comments I don't think this can be done in Elasticsearch.正如我在评论中所说,我认为这不能在 Elasticsearch 中完成。 A highlighter just highlights the terms it matched and does no further postprocessing (And I found no evidence in the docs for Elasticsearch 2.3 that you could make it able to do so).
荧光笔只是突出显示它匹配的术语,不做进一步的后处理(我在Elasticsearch 2.3的文档中没有发现你可以让它这样做的证据)。
Anyway, my logical approach would be to add the <b>...</b>
tags when you're rendering the HTML code.无论如何,我的逻辑方法是在呈现 HTML 代码时添加
<b>...</b>
标签。
{{ foreach hit in hits }}
<b>...</b> hit[content] <b>...</b>
{{ endfor }}
Something like this, just modify it to suit your template.像这样的东西,只需修改它以适合您的模板。
Use pre_tags
and post_tags
for this purpose.为此使用
pre_tags
和post_tags
。 see configuring tags 请参阅配置标签
GET /_search
{
"query" : {
"match": { "user": "kimchy" }
},
"highlight" : {
"pre_tags" : ["<b>"],
"post_tags" : ["</b>"],
"fields" : {
"content" : {}
}
}
}
Pre-Tags and Post-Tags will do in this regard. Pre-Tags 和 Post-Tags 将在这方面做到这一点。
Visit https://programs.wiki/wiki/elasticsearch-search-search-highlight-tag-customization.html for more customization.访问https://programs.wiki/wiki/elasticsearch-search-search-highlight-tag-customization.html以获得更多定制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.