I was testing something on wikitech and issuing the query `insource:/@covers/` times out as expected and returns partial results, but searching `insource:/@covers/ covers` doesn't time out appropriately and instead returns a query failure. Monitoring the task from elasticsearch tasks api shows it takes ~20 minutes to finish.
The actual regex is expensive because @ apparently matches "any string" in the lucene regex syntax and should have been escaped in my query. Still though the inability of the regex to abort seems concerning.
>>! In T152895#4228575, @dcausse wrote:
> I started to investigate but yes the 20s shard timeout is not reached before the curl request timeout.
> Looking at the stacktrace I failed to see one using the source_regex staying around for long...
> Asking elastic to return 0 results (to disable the fetch phase) the time spent is reasonable (20-30sec) and the timeout is properly triggered:
>
> ```dcausse@elastic1041:~$ time curl -XPOST 'localhost:9200/labswiki_content/page/_search?timeout=20s' -d @q.json
> {"took":33967,"timed_out":true,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":11,"max_score":0.0,"hits":[]},"suggest":{"suggest":[{"text":"covers","offset":0,"length":6,"options":[]}]}}
> real 0m33.989s
> user 0m0.012s
> sys 0m0.004s
> ```
>
> Removing the highlight query and re-enabling the fetch_phase by asking to return 20 docs I get reasonable times as well:
>
> ```
> dcausse@elastic1041:~$ time curl -XPOST 'localhost:9200/labswiki_content/page/_search?timeout=20s' -d @q_no_highlight.json
> {"took":35727,"timed_out":true,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":11,"max_score":18.531656,"hits":[{"_index":"labswiki_content_1521968540","_type":"page","_id":"7559","_score":18.531656,"_source":{"redirect":[{"namespace":0,"title":"Packaging"}],"namespace_text":"","wiki":"labswiki"," [...] estamp":"2016-11-04T01:08:22Z"},"fields":{"text.word_count":[97744]}}]},"suggest":{"suggest":[{"text":"covers","offset":0,"length":6,"options":[]}]}}
> real 0m35.750s
> user 0m0.008s
> sys 0m0.008s
> ```
>
> So the problem is definitely in the highlighter.