# Query string with highlighting slow and high cpu usage

**URL:** https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790
**Category:** Elasticsearch
**Created:** [March 13, 2018, 6:20pm UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790 "2018-03-13T18:20:49Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![imranazad](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imranazad](https://discuss.elastic.co/u/imranazad)
#### Post date: [March 13, 2018, 6:20pm UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/1 "2018-03-13T18:20:49Z")

</div>

I have the following query:

GET /test/\_search?human=true  
{  
"profile": true,  
"\_source": "title",  
"from":0,  
"size":250,  
"query":{  
"bool":{  
"must":[  
{  
"query\_string":{  
"query":"VITAL SIGNS COMPUTER",  
"default\_operator":"AND",  
"analyzer":"standard",  
"allow\_leading\_wildcard":false,  
"analyze\_wildcard":true,  
"fields":[  
"content.plain"  
]  
}  
}  
]  
}  
},  
"highlight":{  
"pre\_tags":[  
""  
],  
"post\_tags":[  
""  
],  
"order":"score",  
"fields":{  
"content.plain":{  
"fragment\_size":150,  
"no\_match\_size":150,  
"number\_of\_fragments": 1  
}  
}  
}  
}

It's taking approx 1944 miliseconds for a size of 250 documents, if I remove the highlighter from the query I'm getting 977, that's 967 extra milliseconds for the highlighter which tells me something is causing it to run slow. I'm using the FVH highlighter, here is the output from the hot threads which also seems to indicate it's the highlighter.

> <https://gist.github.com/imranazad/40c734d61be2c31a555bd8b4d69d346d>

With the CPU usage being high could it simply mean that we need more CPU power?

---

<div class="post-metadata">

### Author: ![imranazad](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imranazad](https://discuss.elastic.co/u/imranazad)
#### Post date: [March 14, 2018, 10:01am UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/2 "2018-03-14T10:01:27Z")

</div>

I've observed something interesting. Why is it that when I set the default query to OR the speed is a lot quicker! Shouldn't the OR clause make it slower?

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [March 14, 2018, 10:14am UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/3 "2018-03-14T10:14:21Z")

</div>

The hot threads suggest time is spent decompressing the document. So I suspect that maybe with AND you are getting larger top hits on average than if you run with OR?

---

<div class="post-metadata">

### Author: ![imranazad](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imranazad](https://discuss.elastic.co/u/imranazad)
#### Post date: [March 14, 2018, 10:32am UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/4 "2018-03-14T10:32:07Z")

</div>

@jpountz Ah I see, any suggestions or tips on how I can improve the speed?

---

<div class="post-metadata">

### Author: ![imranazad](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imranazad](https://discuss.elastic.co/u/imranazad)
#### Post date: [March 14, 2018, 10:32am UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/5 "2018-03-14T10:32:36Z")

</div>

> [@jpountz](#):
>
> decom

Also regarding decompressing, is there more I can read about that?

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [March 14, 2018, 10:36am UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/6 "2018-03-14T10:36:32Z")

</div>

How large are your documents? Also do you really need to highlight 250 documents?

---

<div class="post-metadata">

### Author: ![imranazad](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imranazad](https://discuss.elastic.co/u/imranazad)
#### Post date: [March 14, 2018, 1:31pm UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/7 "2018-03-14T13:31:24Z")

</div>

They are quite large, we index content from PDFs in a lot of cases more than 1MB. It's not absolutely necessary. By default we offer the user 10 results per page but they do have the option of selecting a maximum of 250.

---

<div class="post-metadata">

### Author: ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)
#### Post date: [March 14, 2018, 1:49pm UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/8 "2018-03-14T13:49:01Z")

</div>

I don't think there is much to optimize then, the slowness is mostly due to the fact that documents are quite large.

---

<div class="post-metadata">

### Author: ![imranazad](https://avatars.discourse-cdn.com/v4/letter/i/c2a13f/32.png) [@imranazad](https://discuss.elastic.co/u/imranazad)
#### Post date: [March 14, 2018, 3:17pm UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/9 "2018-03-14T15:17:15Z")

</div>

Thanks Adrien, I had suspected that was the case.

---

<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: [April 11, 2018, 3:17pm UTC](https://discuss.elastic.co/t/query-string-with-highlighting-slow-and-high-cpu-usage/123790/10 "2018-04-11T15:17:36Z")

</div>

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