【发布时间】:2016-09-05 23:51:03
【问题描述】:
我在我的 Elasticsearch 查询中添加了高亮显示,但是,它似乎在我认为不应该的字段上高亮显示。
这是我的查询:
{
"from": 0,
"size": 100,
"sort": [
{
"entityName.raw": {
"order": "asc"
}
}
],
"highlight": {
"pre_tags": [
"<span class=\"highlighter\">"
],
"post_tags": [
"</span>"
],
"fields": {
"entityName": {},
"friendlyUrl": {},
"sentBy": {}
},
"require_field_match": true
},
"query": {"bool":{"must":[{"match":{"_all":{"query":"test","operator":"and"}}}]}},
"filter": {
"bool": {
"must": [
{
"term": {
"serviceId": "0b6d064d-1430-4b04-99f7-c30dc03860fc"
}
},
{
"term": {
"subscriptionId": "a29f30e6-f44b-42cc-82c4-f7cb98cb44ef"
}
},
{
"term": {
"subscriptionType": 0
}
},
{
"terms": {
"entityType": [
"4"
]
}
}
]
}
}
}
这是我服务器上添加突出显示的一行:
desc.Highlight(h => h.PreTags("<span class=\"highlighter\">").PostTags("</span>").OnFields(ff => ff.OnField("entityName"), fff => fff.OnField("friendlyUrl"), x => x.OnField("sentBy")));
此查询应该找到与keywords 字段上的通配符john* 和正则表达式.* 匹配的任何文档(我需要检查keywords != "")。问题是当结果返回时,荧光笔响应返回并突出显示文档中的所有内容。
就好像正则表达式忽略了这样一个事实,即我告诉它只查看keywords 字段,而是匹配所有字段。我希望荧光笔仅在与 .* 匹配时突出显示 keywords 字段,但它不是...
我做错了什么?
【问题讨论】:
标签: elasticsearch