0

I use highlighting that is already part of Elasticsearch. It work fine. For example if I have next "words" indexed :

  1. verylongwork that isweryweeylongf
  2. tes!tr%31=!"$:_ae test !"daca214xx

And if I search for -> that .The result is as it folows -> verylongwork that isweryweeylongf . Including the bolding part. But if I search for -> test . The result is -> $:_ae test !" .

So the fragment gests splited/shortened.

It probably has something to do with special characters. When searching I use QueryParser.escape() to escape them.

What could be the problem ?

EDIT: Also if I search for tes the result would be two fragments -> tes!tr and $:_ae test !"

mirzak
  • 1,043
  • 4
  • 15
  • 30

1 Answers1

0

So it would seem that the "problem" was that I had default number of fragments (5) set. In my case it makes no sense since I am searching for shorter strings. So the solution is :

 final HighlightBuilder.Field field = new HighlightBuilder.Field(fieldToHighlight.getName());
        field.preTags("<strong>");
        field.postTags("</strong>");
        field.numOfFragments(0);

Simple as just setting numOfFragments to 0.

mirzak
  • 1,043
  • 4
  • 15
  • 30