I added highlighting into my Elasticsearch queries, however, it appears to be highlighting on fields that I don't think it should.
This is my query:
{
"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"
]
}
}
]
}
}
}
And here is a line on my server that adds the highlighting:
desc.Highlight(h => h.PreTags("<span class=\"highlighter\">").PostTags("</span>").OnFields(ff => ff.OnField("entityName"), fff => fff.OnField("friendlyUrl"), x => x.OnField("sentBy")));
This query should find any documents that matches the Wildcard john*
and the Regexp .*
on the keywords
field (I need to check for keywords != ""
). The problem is when the results come back, the highlighter response comes back and highlights everything in the documents.
It's as if the regexp is ignoring the fact that I told it to only look at the keywords
field and is instead matching on all fields. I would expect the highlighter to only highlight the keywords
field if it matches .*
, but it is not...
What am I doing wrong?