# Fast vector highlighter (fvh) making searches slower

**URL:** <https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634>\
**Category:** Elasticsearch\
**Created:** [December 1, 2021, 7:33am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634 "2021-12-01T07:33:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pyppe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pyppe/32/3531_2.png) [@Pyppe](https://discuss.elastic.co/u/Pyppe)\
**Post date:** [December 1, 2021, 7:33am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634/1 "2021-12-01T07:33:34Z")

</div>

Hi!

We recently improved our hit highlighting by utilizing `fvh` (Lucene Fast Vector Highlighter). The highlighting is done as follows:

```json
{
  "query": {...},
  "highlight": {
    "fields": {
      "searchableName": {
        "number_of_fragments": 0,
        "type": "fvh",
        "matched_fields": [
          "searchableName",
          "searchableName.exact",
          "searchableName.replace_vowels",
          "searchableName.smart",
          "searchableName.smart.reverse",
          "searchableName.standard_clean",
          "searchableName.standard_clean_reverse"
        ]
      }
    }
  }
}

```

This enables us to combine highlights from multiple fields using different analyzers. Each of the above-mentions fields use `with_posititions_offsets` term vectors (as instructed in [Highlighting | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/highlighting.html)).

However, the problem is, that this seems to have a big impact on performance. We turned off the advanced highlighting on during 1pm-3pm (i.e. hourly time buckets of `13:00` & `14:00`). The percentiles show search durations (Elasticsearch `took` in milliseconds):

```auto
         time_bucket | search_count | percentile_5 | percentile_25 | median | percentile_75 | percentile_95
------------------------------+--------------+--------------+---------------+--------+---------------+---------------
 2021-11-30 11:00:00+00 | 1368 | 19 | 120 | 941 | 1168 | 2176
 2021-11-30 12:00:00+00 | 1134 | 20 | 109 | 1010 | 1189 | 2647
 2021-11-30 13:00:00+00 (off) | 1384 | 13 | 32 | 249 | 306 | 1092
 2021-11-30 14:00:00+00 (off) | 1290 | 13 | 40 | 252 | 304 | 1086
 2021-11-30 15:00:00+00 | 1912 | 16 | 242 | 1105 | 1374 | 6278
 2021-11-30 16:00:00+00 | 1333 | 16 | 123 | 1099 | 1284 | 5315

```

We can clearly see the searches became about three times faster (see 50/75/95 percentiles). Why is that? Each search shows only top 50 hits, so how can the highlighting be so slow? Also, we noticed that the highlighting slows queries even if one particular search would not utilize the `searchableName` fields at all.

We are running Elasticsearch `7.12.1` in a cluster of four 64GB physical servers.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 1, 2021, 8:02am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634/2 "2021-12-01T08:02:49Z")

</div>

> [@Pyppe](#):
>
> The percentiles show search durations (Elasticsearch `took` in milliseconds):

The numbers for fvh are lower so that would mean it’s faster not slower?

---

<div class="post-metadata">

**Author:** ![Pyppe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pyppe/32/3531_2.png) [@Pyppe](https://discuss.elastic.co/u/Pyppe)\
**Post date:** [December 1, 2021, 8:26am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634/3 "2021-12-01T08:26:21Z")

</div>

Sorry, I phrased the question badly (fixed now). So we turned off the FVH to confirm it was the highlighting that's causing the slowness.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 1, 2021, 9:34am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634/4 "2021-12-01T09:34:20Z")

</div>

So the diff we are seeing is between FVH and no highlighting?  
We can obviously expect performance differences there so a better test might be FVH versus another choice of highlighter.

Despite its name, FVH is not always faster. IIRC it relies on pre-computed disk stores of offsets to avoid re-tokenizing document strings. This might help avoid heavy costs of analyzing lengthy texts at query time but the trade-off doesn't always work in your favour. Maybe the costs of retrieving the pre-computed offsets from disk are higher than just re-analyzing short strings for highlighting. We don't know because your benchmarking was FVH vs no highlighting.

I'd suggest trying a different choice of highlighter implementation and benchmarking FVH versus that for a more realistic comparison.

---

<div class="post-metadata">

**Author:** ![Pyppe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pyppe/32/3531_2.png) [@Pyppe](https://discuss.elastic.co/u/Pyppe)\
**Post date:** [December 1, 2021, 9:55am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634/5 "2021-12-01T09:55:18Z")

</div>

It's hard to do meaningful comparison because `fvh` is the only highlighter capable of combining highlights from multiple fields... 🤔

However, I can compare e.g. the following two highlight patterns:

```json
{
  "size": 50,
  "query": { ... },
  // Default highlighter: ~ 1.8s response times
  "highlight": {
    "require_field_match": false,
    "fields": {
      "searchableName.*": {
        "number_of_fragments": 0
      }
    }
  },
  // FVH highlighter: ~ 2.5s response times
  "highlight": {
    "fields": {
      "searchableName": {
        "number_of_fragments": 0,
        "type": "fvh",
        "matched_fields": [
          "searchableName",
          "searchableName.exact",
          "searchableName.replace_vowels",
          "searchableName.smart",
          "searchableName.smart.reverse",
          "searchableName.standard_clean",
          "searchableName.standard_clean_reverse"
        ]
      }
    }
  }
}

```

Where the default highlighter (although unable to combine highlights) gives about 40% faster response times (roughly 1.8s vs 2.5s).

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [December 1, 2021, 10:04am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634/6 "2021-12-01T10:04:40Z")

</div>

This is an [old highlighter benchmarking thread](https://discuss.elastic.co/t/comparing-plain-fvh-and-postings-highlighter-performance/14117) but may still be of interest.

---

<div class="post-metadata">

**Author:** ![Pyppe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pyppe/32/3531_2.png) [@Pyppe](https://discuss.elastic.co/u/Pyppe)\
**Post date:** [December 1, 2021, 10:45am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634/7 "2021-12-01T10:45:04Z")

</div>

We are also working on small fields. Typically few words in each.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 29, 2021, 10:45am UTC](https://discuss.elastic.co/t/fast-vector-highlighter-fvh-making-searches-slower/290634/8 "2021-12-29T10:45:39Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
