# Unified Highlighter is too slow

**URL:** <https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814>\
**Category:** Elasticsearch\
**Created:** [May 30, 2018, 8:06am UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814 "2018-05-30T08:06:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![aslamy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aslamy1/32/26607_2.png) [@aslamy1](https://discuss.elastic.co/u/aslamy1)\
**Post date:** [May 30, 2018, 8:06am UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/1 "2018-05-30T08:06:42Z")

</div>

Hi !

When I use Unified Highlighter it takes about 20-22 sec to retrieve the result but when I change it to fvh highlighter it takes about 2-3 sec.  
Why does elasticsearch recommend unified highlighter and has it as default highlighter . Performence is too bad.

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [May 30, 2018, 8:42am UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/2 "2018-05-30T08:42:40Z")

</div>

Can you provide a small recreation with your mapping, the query that is slow with the unified highlighter and a sample document ? The unified highlighter uses the term vectors when they are activated on the field so it is not expected to be 10x slower than the `fvh`.

---

<div class="post-metadata">

**Author:** ![aslamy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aslamy1/32/26607_2.png) [@aslamy1](https://discuss.elastic.co/u/aslamy1)\
**Post date:** [May 30, 2018, 8:58am UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/3 "2018-05-30T08:58:06Z")

</div>

Hi !  
I'm not allowed to share the company's code. But everything are exact the same in my test. Fields are indexed with "term\_vector": "with\_positions\_offsets".

The only thing I change is "type": "unified" to "type": "fvh" .  
When I search after one or two tokens both almost has same performance but when tokens increases,  
the more tokens the slower it will be.

5 tokens takes about 20-22 sec on unified highlighter but 2-3 sec on fvt highlighter

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [May 30, 2018, 10:51am UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/4 "2018-05-30T10:51:57Z")

</div>

Can you at least share the query that you used ? How many fields and documents are highlighted and what is the average size of the documents ?

---

<div class="post-metadata">

**Author:** ![aslamy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aslamy1/32/26607_2.png) [@aslamy1](https://discuss.elastic.co/u/aslamy1)\
**Post date:** [May 30, 2018, 11:36am UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/5 "2018-05-30T11:36:01Z")

</div>

> Can you at least share the query that you used ? How many fields and documents are highlighted and what is the average size of the documents ?

Index has 15683 documents and 1.5 GB big.  
At index time we do copy 5 fields into one filed called "content".

```
{
    	"from": 0,
    	"size": 10,
    	"sort": [],
    	"highlight": {
    		"pre_tags": [
    			"<strong>"
    		],
    		"post_tags": [
    			"</strong>"
    		],
    		"fields": {
    			"document.title": {
    				"no_match_size": 512,
    				"number_of_fragments": 0,
    				"type": "unified"
    			},
    			"content": {
    				"fragment_size": 130,
    				"no_match_size": 256,
    				"number_of_fragments": 2,
    				"type": "unified"
    			}
    		}
    	},
    	"query": {
    		"bool": {
    			"must": [{
    				"multi_match": {
    					"query": "word",
    					"operator": "and",
    					"fields": [
    						"document.title^5",
    						"content"
    					]
    				}
    			}]
    		}
    	}
    }

```

---

<div class="post-metadata">

**Author:** ![aslamy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aslamy1/32/26607_2.png) [@aslamy1](https://discuss.elastic.co/u/aslamy1)\
**Post date:** [May 30, 2018, 2:14pm UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/6 "2018-05-30T14:14:02Z")

</div>

@jimczi very important discovery:  
When I remove "operator": "and" from multi\_match query the response time instead of 20-22 sec is 819 millisec 🙀

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [May 30, 2018, 2:21pm UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/7 "2018-05-30T14:21:08Z")

</div>

The highlighting works only on the top documents (in your example the top 10 documents since you set `size` to 10) so changing the operator should not impact this phase. However the document that will be returned in the top 10 documents are going to be different so I suspect that you have a very big document (or several) that makes the highlighting slower when you use the query with the `and` operator. Can you check the size of the document in both cases ?

---

<div class="post-metadata">

**Author:** ![aslamy1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aslamy1/32/26607_2.png) [@aslamy1](https://discuss.elastic.co/u/aslamy1)\
**Post date:** [May 30, 2018, 2:38pm UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/8 "2018-05-30T14:38:36Z")

</div>

@jimczi I think you are right.  
When "operator": "and" is set, the size of finded documents are 80mb and when it not set the size is 2mb.  
Do you have any suggestion to solve this problem?

fvh highlighter has better Performance on 80mb data than Unified Highlighter

---

<div class="post-metadata">

**Author:** ![jimczi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jimczi/32/47985_2.png) [@jimczi](https://discuss.elastic.co/u/jimczi)\
**Post date:** [May 30, 2018, 2:49pm UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/9 "2018-05-30T14:49:13Z")

</div>

We didn't test this extreme case so I'll need to investigate a bit. I'll do some test on my side and will come back here in a bit. Thanks for reporting.

---

<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:** [June 27, 2018, 2:49pm UTC](https://discuss.elastic.co/t/unified-highlighter-is-too-slow/133814/10 "2018-06-27T14:49:23Z")

</div>

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