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

**URL:** <https://discuss.elastic.co/t/what-is-the-maximum-allowed-length-for-any-search-string-with-wildcard/371581>\
**Category:** Elasticsearch\
**Created:** [December 6, 2024, 9:19am UTC](https://discuss.elastic.co/t/what-is-the-maximum-allowed-length-for-any-search-string-with-wildcard/371581 "2024-12-06T09:19:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![priyankaMS](https://avatars.discourse-cdn.com/v4/letter/p/59ef9b/32.png) [@priyankaMS](https://discuss.elastic.co/u/priyankaMS)\
**Post date:** [December 6, 2024, 9:19am UTC](https://discuss.elastic.co/t/what-is-the-maximum-allowed-length-for-any-search-string-with-wildcard/371581/1 "2024-12-06T09:19:22Z")

</div>

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

---

<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:** [December 6, 2024, 10:03am UTC](https://discuss.elastic.co/t/what-is-the-maximum-allowed-length-for-any-search-string-with-wildcard/371581/2 "2024-12-06T10:03:20Z")

</div>

This will depend on the mapping of your field. If it is mapped as [keyword](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html#keyword-field-type) 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](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html#wildcard-field-type) 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.
