What is the maximum allowed length for any search string with * wildcard?

In my Elasticsearch environment, for different asterisk (*) wildcard positions in string I am getting below error:

ES Exception: [HTTP Status Code: [400]
ORIGINAL_EXCEPTION: [Elasticsearch.Net.ElasticsearchClientException: The remote server returned an error: (400) Bad Request. Call: Status code 400 from: POST/_search?typed_keys=true&routing=. ServerError: Type: search_phase_execution_exception Reason: "all shards failed" ---> System.Net.WebException: The remote server returned an error: (400) Bad Request.

Different wildcard scenarios causing error:

  1. If any word in search string has length more than 1000 and ends with , ex: abc
  2. If any word in search string has length more than 400 and starts with *, ex: *abc
  3. if any word in search string has length more than 300, starts with * and ends with *, ex: abc

Are these string lengths not supported by ES or is it something my elasticsearch setup specific? Any suggestion on how can I fix the issue?
Also I want to know if there is any such search string limit on ES side?

ES version: 8.14

This will depend on the mapping of your field. If it is mapped as keyword the maximum indexed length is by default 256 characters. If you want to handle longer strings and search using wildcard queries I would recommend instead (or in addition map it) as a wildcard field as that is much more efficient and generally offer better performance. Query large keyword fields with wildcard queries is generally the most expensive and ineffective way to query Elasticsearch and will scale and perform badly.