Elasticsearch version (7.8
):
OS version (Windows 10
):
Along with ScriptScore function, Highlight function does not work properly. If we search two words only first word gets higlighted or last word doesn't display highlighted:
Eg. Doc content- this is a boy
On searching - this is
Output content shows only 'this' as highlighted
var searchResponse = await elasticClient.SearchAsync<Document>(body => body
.Index(Settings.Index + "-*")
.Query(qx =>
qx.ScriptScore(fx => fx
.Query(qt =>
qt.Bool
(bb => bb.Must(q =>
q.MatchPhrasePrefix(m => m.Field(f => f.Content).Query(req.SearchText))) // q.Terms(c => c.Field(p => p.Tags).Terms(words))
)
)
.Script(w => w.Source("String gmtString = params.searchdate;ZonedDateTime zdt = ZonedDateTime.parse(gmtString,DateTimeFormatter.RFC_1123_DATE_TIME);ZonedDateTime zdt2 =ZonedDateTime.of(doc['date'].value.year,doc['date'].value.monthOfYear,doc['date'].value.dayOfMonth,doc['date'].value.hourOfDay,doc['date'].value.minuteOfHour,doc['date'].value.secondOfMinute, 0, ZoneId.of('Z')); if (zdt2.toInstant().toEpochMilli()==zdt.toInstant().toEpochMilli()){return 100;}else{return _score;} ").Params(par)))
).Highlight(h => h.Fields(
fs => fs
.Field(p => p.Content)
.NumberOfFragments(0),
fs => fs
.Field(p => p.Attachment.Content).NumberOfFragments(0).Type(HighlighterType.Unified)
).PreTags("<b>").PostTags("</b>")));
Please suggest any solution