# Query String Query Performance Issue when using ~ operator - ES 1.6

**URL:** https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126
**Category:** Elasticsearch
**Created:** [July 8, 2015, 8:13am UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126 "2015-07-08T08:13:33Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![effoeffi](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@effoeffi](https://discuss.elastic.co/u/effoeffi)
#### Post date: [July 8, 2015, 8:13am UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126/1 "2015-07-08T08:13:33Z")

</div>

Hello,

When running a query like:

```json
POST /my-index/_search
{
  "from" : 0,
  "size" : 5,
  "query" : {
      "query_string" : {
      "fields" : ["field1","field2",...,"fieldn"],
      "query" : "flight~",
      "use_dis_max" : true
    }
  },
  "highlight" : {
    "pre_tags" : ["<span class=\"mark\">"],
    "post_tags" : ["</span>"],
    "order" : "score",
    "encoder" : "html",
    "require_field_match" : true,
    "fields" : {    
      "*" : {}
    }
  }
}

```

_query\_string_ contains n fields (in my case about 40 fields), and _query_ contains ~ operator (in the example flight~), takes about **6 seconds**.  
If I run the same query (flight~), but remove the fields section from _query\_string_ section, it takes **10 milliseconds** (no time).

Why does it happen?  
Is there a solution for this performance penalty (I have to determine specific fields into _query\_string_ in order to solve highlight issue, see below)?

**Background:**  
Using elasticsearch 1.6.  
Run it on index that contains 1000 documents.  
Determine specific fields into _query\_string_ in order to solve follow highlight issue:

> [@Highlight when query contains fields and text - ES 1.6.0](https://discuss.elastic.co/t/highlight-when-query-contains-fields-and-text-es-1-6-0/24311/5):
>
> Wooow, it's working. THANKS! smiley I don't understand why should I determine that I want highlight on text in the search level (and not at highlight section)? Another question, let's say my document looks like this: { "type": "tweet", "fields": { "user" : "jack", "message" : "I'm jack", "comment" : "my first tweet" } } Can I search on fields.\* instead of specific fields, like: {fields: "comment, message", query: "your query"}? I understand that o…

Thanks,  
Effi

---

<div class="post-metadata">

### Author: ![effoeffi](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@effoeffi](https://discuss.elastic.co/u/effoeffi)
#### Post date: [July 13, 2015, 8:26am UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126/2 "2015-07-13T08:26:22Z")

</div>

Sorry, I wrote the times inverted 😮  
Fixed.

---

<div class="post-metadata">

### Author: ![effoeffi](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@effoeffi](https://discuss.elastic.co/u/effoeffi)
#### Post date: [July 15, 2015, 7:57am UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126/3 "2015-07-15T07:57:35Z")

</div>

I opened an issue in [github](https://github.com/elastic/elasticsearch/issues/12201), but it closed saying "Please keep questions on the discuss forum".  
It seems like performance issue, is there a way to understand why elasticsearch thinks different?

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 15, 2015, 8:19am UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126/4 "2015-07-15T08:19:00Z")

</div>

When you remove the `fields` section you are searching the `_all` field, with the `fields` section you are searching 40 separate fields. Searching and highlighting on 40 fields compared with one field will take much longer. The query phase is going to take longer as there are more fields to search over (and giving that you are using a fuzzy operator the query needs to be expanded into the possible combinations on all 40 fields too), but the main time spent here will be on highlighting. Highlighting is an expensive process so asking Elasticsearch to highlight over 40 fields is going to increase the work required a lot.

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 15, 2015, 8:24am UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126/5 "2015-07-15T08:24:45Z")

</div>

There is also [this issue](https://github.com/elastic/elasticsearch/issues/11442) which mentions performance issues when using the combination of fuzzy queries and the plain highlighter. It may be worth looking into enabling a different highlighter for your use case

---

<div class="post-metadata">

### Author: ![effoeffi](https://avatars.discourse-cdn.com/v4/letter/e/e5b9ba/32.png) [@effoeffi](https://discuss.elastic.co/u/effoeffi)
#### Post date: [July 21, 2015, 3:32pm UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126/6 "2015-07-21T15:32:00Z")

</div>

Thanks colings86.

Do you understand why should determine specific fields list in the **query section** in order to have a highlight?  
Why not to define fields in the **highlight section**? Is this highlighter bug?

Do you know a highlighter that handle query that contains fields and text? Will not mix result, like default highlighter when searching on `_all` field.

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [July 22, 2015, 7:22am UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126/7 "2015-07-22T07:22:16Z")

</div>

I'm sorry but I don't follow your question. Could you explain a bit more?

---

<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: [July 6, 2017, 12:00am UTC](https://discuss.elastic.co/t/query-string-query-performance-issue-when-using-operator-es-1-6/25126/8 "2017-07-06T00:00:03Z")

</div>


