# nGram and wildcards

**URL:** <https://discuss.elastic.co/t/ngram-and-wildcards/9225>\
**Category:** Elasticsearch\
**Created:** [October 3, 2012, 1:14pm UTC](https://discuss.elastic.co/t/ngram-and-wildcards/9225 "2012-10-03T13:14:06Z")\
**Posts on this page:** 5\
**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, 1:14pm UTC](https://discuss.elastic.co/t/ngram-and-wildcards/9225/1 "2012-10-03T13:14:06Z")

</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:** ![MyHeadHurts](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MyHeadHurts](https://discuss.elastic.co/u/MyHeadHurts)\
**Post date:** [October 3, 2012, 2:20pm UTC](https://discuss.elastic.co/t/ngram-and-wildcards/9225/2 "2012-10-03T14:20:28Z")

</div>

If this is not possible, is there a way to simulate a query as if we were  
using the "?" wildcard character?

On Wednesday, 3 October 2012 15:14:06 UTC+2, My Head Hurts wrote:

> 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:** ![MyHeadHurts](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MyHeadHurts](https://discuss.elastic.co/u/MyHeadHurts)\
**Post date:** [October 3, 2012, 2:21pm UTC](https://discuss.elastic.co/t/ngram-and-wildcards/9225/3 "2012-10-03T14:21:03Z")

</div>

If this is not possible, is there a way to simulate a query as if we were  
using the "?" wildcard character?

On Wednesday, 3 October 2012 15:14:06 UTC+2, My Head Hurts wrote:

> 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:** ![MyHeadHurts](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@MyHeadHurts](https://discuss.elastic.co/u/MyHeadHurts)\
**Post date:** [October 3, 2012, 2:21pm UTC](https://discuss.elastic.co/t/ngram-and-wildcards/9225/4 "2012-10-03T14:21:21Z")

</div>

If this is not possible, is there a way to simulate a query as if we were  
using the "?" wildcard character?

--

---

<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:10am UTC](https://discuss.elastic.co/t/ngram-and-wildcards/9225/5 "2017-07-06T03:10:22Z")

</div>


