# Very slow queries stop words and synonyms after upgrade to 6.7.0 from 6.2.3

**URL:** <https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254>\
**Category:** Elasticsearch\
**Created:** [December 2, 2019, 10:42pm UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254 "2019-12-02T22:42:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bayers51](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@bayers51](https://discuss.elastic.co/u/bayers51)\
**Post date:** [December 2, 2019, 10:42pm UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254/1 "2019-12-02T22:42:01Z")

</div>

Removing the stop word or synonym, the query is fast. Removing the stop word, removes spanNear([SpanGap(:1), from the query.

ES version 6.7.

"took" : 9913,

(Note: artificial intelligence has a synonym to ai as well)  
GET csdev\_data/\_search  
{  
"query": {  
"match\_phrase": {  
"bookText\_en": "introduction to artificial intelligence"  
}  
}  
}

```
"description" : "+spanNear([bookText_en:introduct, spanOr([spanNear([SpanGap(:1), bookText_en:ai], 0, true), spanNear([SpanGap(:1), bookText_en:artifici, bookText_en:intellig], 0, true)])], 0, true) #DocValuesFieldExistsQuery [field=_primary_term]",

```

Without stop word, also ES 6.7

"took" : 21,

GET csdev\_data/\_search  
{  
"query": {  
"match\_phrase": {  
"bookText\_en": "introduction artificial intelligence"  
}  
}  
}

```
"description" : "spanNear([bookText_en:introduct, spanOr([bookText_en:ai, spanNear([bookText_en:artifici, bookText_en:intellig], 0, true)])], 0, true)",
```

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 3, 2019, 10:03am UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254/2 "2019-12-03T10:03:18Z")

</div>

Can you create a small reproduction, where you create an index, a small mapping, index a sample document and the search, so that this can be reproduced locally?

Thank you!

---

<div class="post-metadata">

**Author:** ![bayers51](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@bayers51](https://discuss.elastic.co/u/bayers51)\
**Post date:** [December 3, 2019, 6:49pm UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254/3 "2019-12-03T18:49:11Z")

</div>

I'm having some trouble trying to make a small reproduction of this. The problem is on a field that contains entire contents of a book.

Does it help to show the profile output of the same query against basically the same documents (~30K documents) but one is ES 6.7.0 and the other 6.2.3?

```
GET csdev_data/_search
{
  "size": 0, 
  "profile": "true", 
  "query": {
    "match_phrase": {
      "bookText_en": "introduction to artificial intelligence"
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![bayers51](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@bayers51](https://discuss.elastic.co/u/bayers51)\
**Post date:** [December 3, 2019, 6:56pm UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254/4 "2019-12-03T18:56:05Z")

</div>

ES 6.2.3  
{  
"took": 82,  
"timed\_out": false,  
"\_shards": {  
"total": 3,  
"successful": 3,  
"skipped": 0,  
"failed": 0  
},  
"hits": {  
"total": 4,  
"max\_score": 0,  
"hits":   
},  
"profile": {  
"shards": [  
{  
"id": "[CN8nQzugSmOq5rg6ctlPZg][csint\_data\_v15][0]",  
"searches": [  
{  
"query": [  
{  
"type": "BooleanQuery",  
"description": "+spanNear([bookText\_en:introduct, spanOr([bookText\_en:ai, spanNear([bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true) #DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos": 43309678,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 24,  
"match\_count": 782,  
"create\_weight": 216013,  
"next\_doc": 14802861,  
"match": 24502034,  
"create\_weight\_count": 1,  
"next\_doc\_count": 872,  
"score\_count": 0,  
"build\_scorer": 3787091,  
"advance": 0,  
"advance\_count": 0  
},  
"children": [  
{  
"type": "SpanNearQuery",  
"description": "spanNear([bookText\_en:introduct, spanOr([bookText\_en:ai, spanNear([bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true)",  
"time\_in\_nanos": 38723939,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 28,  
"match\_count": 782,  
"create\_weight": 180961,  
"next\_doc": 14051599,  
"match": 24222115,  
"create\_weight\_count": 1,  
"next\_doc\_count": 872,  
"score\_count": 0,  
"build\_scorer": 267581,  
"advance": 0,  
"advance\_count": 0  
}  
},  
{  
"type": "DocValuesFieldExistsQuery",  
"description": "DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos": 207743,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 12,  
"match\_count": 0,  
"create\_weight": 1179,  
"next\_doc": 0,  
"match": 0,  
"create\_weight\_count": 1,  
"next\_doc\_count": 0,  
"score\_count": 0,  
"build\_scorer": 20376,  
"advance": 185303,  
"advance\_count": 872  
}  
}  
]  
}  
],  
"rewrite\_time": 19856,  
"collector": [  
{  
"name": "CancellableCollector",  
"reason": "search\_cancelled",  
"time\_in\_nanos": 74409,  
"children": [  
{  
"name": "TotalHitCountCollector",  
"reason": "search\_count",  
"time\_in\_nanos": 17104  
}  
]  
}  
]  
}  
],  
"aggregations":   
},  
{  
"id": "[Lapq3tHxRmWfCwrP9ukilw][csint\_data\_v15][2]",  
"searches": [  
{  
"query": [  
{  
"type": "BooleanQuery",  
"description": "+spanNear([bookText\_en:introduct, spanOr([bookText\_en:ai, spanNear([bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true) #DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos": 25566860,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 24,  
"match\_count": 770,  
"create\_weight": 8087160,  
"next\_doc": 10716785,  
"match": 6120972,  
"create\_weight\_count": 1,  
"next\_doc\_count": 773,  
"score\_count": 0,  
"build\_scorer": 640375,  
"advance": 0,  
"advance\_count": 0  
},  
"children": [  
{  
"type": "SpanNearQuery",  
"description": "spanNear([bookText\_en:introduct, spanOr([bookText\_en:ai, spanNear([bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true)",  
"time\_in\_nanos": 24055670,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 27,  
"match\_count": 770,  
"create\_weight": 7992780,  
"next\_doc": 10057005,  
"match": 5813617,  
"create\_weight\_count": 1,  
"next\_doc\_count": 773,  
"score\_count": 0,  
"build\_scorer": 190697,  
"advance": 0,  
"advance\_count": 0  
}  
},  
{  
"type": "DocValuesFieldExistsQuery",  
"description": "DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos": 185859,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 9,  
"match\_count": 0,  
"create\_weight": 1565,  
"next\_doc": 0,  
"match": 0,  
"create\_weight\_count": 1,  
"next\_doc\_count": 0,  
"score\_count": 0,  
"build\_scorer": 14904,  
"advance": 168607,  
"advance\_count": 773  
}  
}  
]  
}  
],  
"rewrite\_time": 21766,  
"collector": [  
{  
"name": "CancellableCollector",  
"reason": "search\_cancelled",  
"time\_in\_nanos": 60706,  
"children": [  
{  
"name": "TotalHitCountCollector",  
"reason": "search\_count",  
"time\_in\_nanos": 26649  
}  
]  
}  
]  
}  
],  
"aggregations":   
},  
{  
"id": "[XLgiMReITxSavM4wd21JLA][csint\_data\_v15][1]",  
"searches": [  
{  
"query": [  
{  
"type": "BooleanQuery",  
"description": "+spanNear([bookText\_en:introduct, spanOr([bookText\_en:ai, spanNear([bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true) #DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos": 77788229,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 25,  
"match\_count": 785,  
"create\_weight": 22249467,  
"next\_doc": 25406443,  
"match": 29165883,  
"create\_weight\_count": 1,  
"next\_doc\_count": 791,  
"score\_count": 0,  
"build\_scorer": 964834,  
"advance": 0,  
"advance\_count": 0  
},  
"children": [  
{  
"type": "SpanNearQuery",  
"description": "spanNear([bookText\_en:introduct, spanOr([bookText\_en:ai, spanNear([bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true)",  
"time\_in\_nanos": 74740193,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 29,  
"match\_count": 785,  
"create\_weight": 22187615,  
"next\_doc": 23760863,  
"match": 28495509,  
"create\_weight\_count": 1,  
"next\_doc\_count": 791,  
"score\_count": 0,  
"build\_scorer": 294600,  
"advance": 0,  
"advance\_count": 0  
}  
},  
{  
"type": "DocValuesFieldExistsQuery",  
"description": "DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos": 551579,  
"breakdown": {  
"score": 0,  
"build\_scorer\_count": 12,  
"match\_count": 0,  
"create\_weight": 3418,  
"next\_doc": 0,  
"match": 0,  
"create\_weight\_count": 1,  
"next\_doc\_count": 0,  
"score\_count": 0,  
"build\_scorer": 27665,  
"advance": 519692,  
"advance\_count": 791  
}  
}  
]  
}  
],  
"rewrite\_time": 18247,  
"collector": [  
{  
"name": "CancellableCollector",  
"reason": "search\_cancelled",  
"time\_in\_nanos": 81169,  
"children": [  
{  
"name": "TotalHitCountCollector",  
"reason": "search\_count",  
"time\_in\_nanos": 22986  
}  
]  
}  
]  
}  
],  
"aggregations":   
}  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![bayers51](https://avatars.discourse-cdn.com/v4/letter/b/3d9bf3/32.png) [@bayers51](https://discuss.elastic.co/u/bayers51)\
**Post date:** [December 3, 2019, 6:56pm UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254/5 "2019-12-03T18:56:30Z")

</div>

ES 6.7.0  
{  
"took" : 9872,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 3,  
"successful" : 3,  
"skipped" : 0,  
"failed" : 0  
},  
"hits" : {  
"total" : 13,  
"max\_score" : 0.0,  
"hits" :   
},  
"profile" : {  
"shards" : [  
{  
"id" : "[PFNuMigHQju3-iCpySBZoQ][csdev\_data\_v15][0]",  
"searches" : [  
{  
"query" : [  
{  
"type" : "BooleanQuery",  
"description" : "+spanNear([bookText\_en:introduct, spanOr([spanNear([SpanGap(:1), bookText\_en:ai], 0, true), spanNear([SpanGap(:1), bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true) #DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos" : 6399032201,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 29,  
"match\_count" : 782,  
"create\_weight" : 7585635,  
"next\_doc" : 2953095988,  
"match" : 3437787305,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 785,  
"score\_count" : 0,  
"build\_scorer" : 561676,  
"advance" : 0,  
"advance\_count" : 0  
},  
"children" : [  
{  
"type" : "SpanNearQuery",  
"description" : "spanNear([bookText\_en:introduct, spanOr([spanNear([SpanGap(:1), bookText\_en:ai], 0, true), spanNear([SpanGap(:1), bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true)",  
"time\_in\_nanos" : 6396366746,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 32,  
"match\_count" : 782,  
"create\_weight" : 7555591,  
"next\_doc" : 2951370890,  
"match" : 3437246149,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 785,  
"score\_count" : 0,  
"build\_scorer" : 192516,  
"advance" : 0,  
"advance\_count" : 0  
}  
},  
{  
"type" : "DocValuesFieldExistsQuery",  
"description" : "DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos" : 277071,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 9,  
"match\_count" : 0,  
"create\_weight" : 835,  
"next\_doc" : 0,  
"match" : 0,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 0,  
"score\_count" : 0,  
"build\_scorer" : 18165,  
"advance" : 257276,  
"advance\_count" : 785  
}  
}  
]  
}  
],  
"rewrite\_time" : 18123,  
"collector" : [  
{  
"name" : "CancellableCollector",  
"reason" : "search\_cancelled",  
"time\_in\_nanos" : 44478,  
"children" : [  
{  
"name" : "TotalHitCountCollector",  
"reason" : "search\_count",  
"time\_in\_nanos" : 14827  
}  
]  
}  
]  
}  
],  
"aggregations" :   
},  
{  
"id" : "[jSy3A2FBQ6GrTSmy1dTDbg][csdev\_data\_v15][1]",  
"searches" : [  
{  
"query" : [  
{  
"type" : "BooleanQuery",  
"description" : "+spanNear([bookText\_en:introduct, spanOr([spanNear([SpanGap(:1), bookText\_en:ai], 0, true), spanNear([SpanGap(:1), bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true) #DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos" : 9611793748,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 42,  
"match\_count" : 785,  
"create\_weight" : 9710004,  
"next\_doc" : 4149982022,  
"match" : 5451568563,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 790,  
"score\_count" : 0,  
"build\_scorer" : 531541,  
"advance" : 0,  
"advance\_count" : 0  
},  
"children" : [  
{  
"type" : "SpanNearQuery",  
"description" : "spanNear([bookText\_en:introduct, spanOr([spanNear([SpanGap(:1), bookText\_en:ai], 0, true), spanNear([SpanGap(:1), bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true)",  
"time\_in\_nanos" : 9609939564,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 45,  
"match\_count" : 785,  
"create\_weight" : 9683597,  
"next\_doc" : 4149041426,  
"match" : 5451038293,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 790,  
"score\_count" : 0,  
"build\_scorer" : 174627,  
"advance" : 0,  
"advance\_count" : 0  
}  
},  
{  
"type" : "DocValuesFieldExistsQuery",  
"description" : "DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos" : 316534,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 9,  
"match\_count" : 0,  
"create\_weight" : 890,  
"next\_doc" : 0,  
"match" : 0,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 0,  
"score\_count" : 0,  
"build\_scorer" : 80752,  
"advance" : 234092,  
"advance\_count" : 790  
}  
}  
]  
}  
],  
"rewrite\_time" : 15634,  
"collector" : [  
{  
"name" : "CancellableCollector",  
"reason" : "search\_cancelled",  
"time\_in\_nanos" : 46242,  
"children" : [  
{  
"name" : "TotalHitCountCollector",  
"reason" : "search\_count",  
"time\_in\_nanos" : 14930  
}  
]  
}  
]  
}  
],  
"aggregations" :   
},  
{  
"id" : "[xNarOaDASjar-h\_g3RNTWg][csdev\_data\_v15][2]",  
"searches" : [  
{  
"query" : [  
{  
"type" : "BooleanQuery",  
"description" : "+spanNear([bookText\_en:introduct, spanOr([spanNear([SpanGap(:1), bookText\_en:ai], 0, true), spanNear([SpanGap(:1), bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true) #DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos" : 10368790260,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 29,  
"match\_count" : 770,  
"create\_weight" : 4821359,  
"next\_doc" : 5039558415,  
"match" : 5320928957,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 771,  
"score\_count" : 0,  
"build\_scorer" : 3479958,  
"advance" : 0,  
"advance\_count" : 0  
},  
"children" : [  
{  
"type" : "SpanNearQuery",  
"description" : "spanNear([bookText\_en:introduct, spanOr([spanNear([SpanGap(:1), bookText\_en:ai], 0, true), spanNear([SpanGap(:1), bookText\_en:artifici, bookText\_en:intellig], 0, true)])], 0, true)",  
"time\_in\_nanos" : 10366796157,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 30,  
"match\_count" : 770,  
"create\_weight" : 4796952,  
"next\_doc" : 5038455998,  
"match" : 5320280183,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 771,  
"score\_count" : 0,  
"build\_scorer" : 3261452,  
"advance" : 0,  
"advance\_count" : 0  
}  
},  
{  
"type" : "DocValuesFieldExistsQuery",  
"description" : "DocValuesFieldExistsQuery [field=\_primary\_term]",  
"time\_in\_nanos" : 275398,  
"breakdown" : {  
"score" : 0,  
"build\_scorer\_count" : 3,  
"match\_count" : 0,  
"create\_weight" : 837,  
"next\_doc" : 0,  
"match" : 0,  
"create\_weight\_count" : 1,  
"next\_doc\_count" : 0,  
"score\_count" : 0,  
"build\_scorer" : 4419,  
"advance" : 269367,  
"advance\_count" : 771  
}  
}  
]  
}  
],  
"rewrite\_time" : 25479,  
"collector" : [  
{  
"name" : "CancellableCollector",  
"reason" : "search\_cancelled",  
"time\_in\_nanos" : 34514,  
"children" : [  
{  
"name" : "TotalHitCountCollector",  
"reason" : "search\_count",  
"time\_in\_nanos" : 10947  
}  
]  
}  
]  
}  
],  
"aggregations" :   
}  
]  
}  
}

---

<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 31, 2019, 6:56pm UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254/6 "2019-12-31T18:56:37Z")

</div>

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

---

<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 31, 2019, 6:56pm UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254/7 "2019-12-31T18:56:39Z")

</div>



---

<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:** [November 4, 2022, 7:35am UTC](https://discuss.elastic.co/t/very-slow-queries-stop-words-and-synonyms-after-upgrade-to-6-7-0-from-6-2-3/210254/8 "2022-11-04T07:35:47Z")

</div>


