# Elasticsearch simple query string and highlighter leads to timeout

**URL:** <https://discuss.elastic.co/t/elasticsearch-simple-query-string-and-highlighter-leads-to-timeout/273897>\
**Category:** Elasticsearch\
**Created:** [May 25, 2021, 6:45am UTC](https://discuss.elastic.co/t/elasticsearch-simple-query-string-and-highlighter-leads-to-timeout/273897 "2021-05-25T06:45:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![schubec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/schubec/32/82658_2.png) [@schubec](https://discuss.elastic.co/u/schubec)\
**Post date:** [May 25, 2021, 6:45am UTC](https://discuss.elastic.co/t/elasticsearch-simple-query-string-and-highlighter-leads-to-timeout/273897/1 "2021-05-25T06:45:56Z")

</div>

Hi!

I am facing a strange problem with Elasticsearch:

I have this query which results in a timeout because it takes more than 60 seconds:

```auto
GET /website/_search
{
  "query": {
    "simple_query_string": {
      "query": "mbs regex replace all",
      "fields": ["content_primary"],
        "default_operator": "and"
    }
  },
  "highlight": {
    "fields": {
      "content_primary": {}
    }
    ,"fragment_size" : 200
  }
}

```

There are 3 options to make the query work:

- Remove the highlight
- Change the default\_operator to "OR"
- Remove the word "all" from the query term

If I remove the highlighter, the query finishes within 9 milliseconds.  
If I search for "mbs regex replace" (without the word "all" and with highlight enabled and operator AND) it finishes within 166 milliseconds.  
If I change the query operator to OR (with highlight enabled) it finishes within 11 milliseconds.

But for my application, I need all three parameters exactly like specified, because the query "mbs regex replace all" is coming from the user, I need the highlighter for the frontend and I need the operator to be AND, so the search works like the user expect it.

What is wrong here?

The index has 96743 documents.  
Elasticsearch v7.11.2 hosted on [cloud.elastic.co](http://cloud.elastic.co)

Edit: this is the mapping:

```auto

PUT /website
{
  "settings": {
    "analysis": {
      "filter" : {
        "custom_synonym" : {
          "type" : "synonym",
          "lenient": true,
          "synonyms": ["FM => FileMaker", "DDR => Datenbank Design Report", "DB => Datenbank", "TO, Table Occurence => Tabellenauftreten"]
        },
        "german_stemming": {
          "type": "stemmer",
          "language": "german"
        },
        "german_stopping": {
          "type": "stop",
          "stopwords": "_german_"
        }
      },
      "analyzer": {
        "custom_german_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": ["lowercase", "asciifolding", "custom_synonym"]
        }
      }
    }
  },  
    "mappings" : {
      "properties" : {
        "authors" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "classifications" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "content_primary" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            },
            "german" : {
              "type": "text",
              "analyzer": "custom_german_analyzer"
            }
          }
        },
        "date" : {
          "type" : "date"
        },
        "description" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "domain" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "keywords" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "language" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "properties" : {
          "properties" : {
            "Plugin Komponente" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "osversion" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "softwareversion" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        },
        "source" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "title" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            },
            "german" : {
              "type": "text",
              "analyzer": "custom_german_analyzer"
            }
          }
        },
        "url" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "urlToImagePreview" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
}

```

PS: Disclaimer: I also asked here but nobody answered: [Elasticsearch simple query string and highlighter leads to timeout - Stack Overflow](https://stackoverflow.com/questions/67658255/elasticsearch-simple-query-string-and-highlighter-leads-to-timeout)

Thank you!

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [May 25, 2021, 7:29am UTC](https://discuss.elastic.co/t/elasticsearch-simple-query-string-and-highlighter-leads-to-timeout/273897/2 "2021-05-25T07:29:59Z")

</div>

How large is the `content_primary` field on average? Have you tried using a [different highlkighter](https://www.elastic.co/guide/en/elasticsearch/reference/7.12/highlighting.html) or tune the settings?

---

<div class="post-metadata">

**Author:** ![schubec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/schubec/32/82658_2.png) [@schubec](https://discuss.elastic.co/u/schubec)\
**Post date:** [May 25, 2021, 8:42am UTC](https://discuss.elastic.co/t/elasticsearch-simple-query-string-and-highlighter-leads-to-timeout/273897/3 "2021-05-25T08:42:11Z")

</div>

Thank you for your questions, which lead into the right direction.  
The average document has about 400 words. But with my query `mbs regex replace all` and the `AND` operator, it returned 5 documents wich had each 200 KB in size and the default highlighter `unified` took like 12 seconds for each of these documents. The `plain` highlighter takes 178 milliseconds for the whole result.

So first I will get rid of these super long documents and also I think I will change to the `plain` highlighter, but I have to check what the means in my UI.

Thank you for asking the right questions!

---

<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 22, 2021, 8:42am UTC](https://discuss.elastic.co/t/elasticsearch-simple-query-string-and-highlighter-leads-to-timeout/273897/4 "2021-06-22T08:42:59Z")

</div>

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