# nGrams and Wildcards

**URL:** <https://discuss.elastic.co/t/ngrams-and-wildcards/9224>\
**Category:** Elasticsearch\
**Created:** [October 3, 2012, 12:32pm UTC](https://discuss.elastic.co/t/ngrams-and-wildcards/9224 "2012-10-03T12:32:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MyHeadHurts](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MyHeadHurts](https://discuss.elastic.co/u/MyHeadHurts)\
**Post date:** [October 3, 2012, 12:32pm UTC](https://discuss.elastic.co/t/ngrams-and-wildcards/9224/1 "2012-10-03T12:32:54Z")

</div>

I am having trouble searching with wildcards when indexing data using nGram?

For example:

If I index data using the following index settings:

_index:  
analysis:  
analyzer:  
default:  
type: standard  
stopwords: none_

I am able to search something like **"b?t"** and receive search results for **"but"** and **"bat"** etc...

However, should I change the index settings to use nGram for partial word matching, like follows:

_index:  
analysis:  
analyzer:  
default:  
type: custom  
tokenizer: nGramTokenizer  
filter: [lowercase,stopWordsFilter]  
tokenizer:  
nGramTokenizer:  
type: nGram  
min\_gram: 1  
max\_gram: 2  
stopWordsFilter:  
type: stop  
stopwords: none_

Then partial word matching works, ie. searching **"bu"** will return **"but"** and **"bug"** etc... but wildcards no longer seem to be supported...so if I search **"b?t"** then there are **no matching hits**.

Is there a way that I can use wildcards and nGram together?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 8, 2012, 9:00am UTC](https://discuss.elastic.co/t/ngrams-and-wildcards/9224/2 "2012-10-08T09:00:45Z")

</div>

Can multifield feature help you?  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)  
[http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)  
You can index your field with different analyzers.

HTH  
David

Le 3 octobre 2012 à 14:32, MyHeadHurts [mathieson10@gmail.com](mailto:mathieson10@gmail.com) a écrit :

> I am having trouble searching with wildcards when indexing data using nGram?
> 
> For example:
> 
> If I index data using the following index settings:
> 
> /index:  
> analysis:  
> analyzer:  
> default:  
> type: standard  
> stopwords: _none_/
> 
> I am able to search something like _"b?t"_ and receive search results for  
> _"but"_ and _"bat"_ etc...
> 
> However, should I change the index settings to use nGram for partial word  
> matching, like follows:
> 
> /index:  
> analysis:  
> analyzer:  
> default:  
> type: custom  
> tokenizer: nGramTokenizer  
> filter: [lowercase,stopWordsFilter]  
> tokenizer:  
> nGramTokenizer:  
> type: nGram  
> min\_gram: 1  
> max\_gram: 2  
> stopWordsFilter:  
> type: stop  
> stopwords: _none_/
> 
> Then partial word matching works, ie. searching _"bu"_ will return _"but"_  
> and _"bug"_ etc... but wildcards no longer seem to be supported...so if I  
> search _"b?t"_ then there are _no matching hits_.
> 
> Is there a way that I can use wildcards and nGram together?
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/nGrams-and-Wildcards-tp4023453.html](http://elasticsearch-users.115913.n3.nabble.com/nGrams-and-Wildcards-tp4023453.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<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:** [July 6, 2017, 3:09am UTC](https://discuss.elastic.co/t/ngrams-and-wildcards/9224/3 "2017-07-06T03:09:47Z")

</div>


