# Issues trying to search with ngram tokenizer

**URL:** <https://discuss.elastic.co/t/issues-trying-to-search-with-ngram-tokenizer/269946>\
**Category:** Elasticsearch\
**Created:** [April 12, 2021, 7:55pm UTC](https://discuss.elastic.co/t/issues-trying-to-search-with-ngram-tokenizer/269946 "2021-04-12T19:55:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nealdan0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nealdan0/32/86952_2.png) [@nealdan0](https://discuss.elastic.co/u/nealdan0)\
**Post date:** [April 12, 2021, 7:55pm UTC](https://discuss.elastic.co/t/issues-trying-to-search-with-ngram-tokenizer/269946/1 "2021-04-12T19:55:44Z")

</div>

Hi, Recently we upgraded our version of elastic search to 7.10. Since then I've had issues querying with an ngram tokenizer from the java api. Specifically, searching for a text value only returns results if using as phrase\_prefix query type. So, for example a query for 'abcd' will return results for 'abcdefg', as expected. But a search for 'bcdefg' will return no results.

I can work around it, reluctantly, with wild card queries. However I also have a need to search for non-alphanumeric characters, like -, %, / etc. I have not been able to make wild card queries work with those characters.

**Analyzer**

{  
"max\_ngram\_diff": "7",  
"analysis": {  
"analyzer": {  
"rp\_analyzer": {  
"type": "custom",  
"tokenizer": "rp\_tokenizer",  
"filter": [  
"lowercase"  
]  
}  
},  
"tokenizer": {  
"rp\_tokenizer": {  
"type": "ngram",  
"min\_gram": 3,  
"max\_gram": 10,  
"token\_chars": [  
"letter",  
"digit",  
"punctuation",  
"symbol",  
"custom"  
],  
"custom\_token\_chars":":+-\_/%\*?"  
}  
}  
}  
}

\*\*Query \*\*

MultiMatchQueryBuilder multiMatchQueryBuilder = new MultiMatchQueryBuilder(searchText.trim());  
for (String fieldName :searchableFieldNames) {  
multiMatchQueryBuilder.field(fieldName);  
}  
multiMatchQueryBuilder.operator(Operator.OR);  
multiMatchQueryBuilder.slop(5);  
multiMatchQueryBuilder.type(MultiMatchQueryBuilder.Type.PHRASE\_PREFIX);  
return multiMatchQueryBuilder;

**Document set up** (also tried fieldType.Text)

@Document(indexName = "reviewable\_product")  
@Setting(settingPath = "/elasticsearch/settings/ReviewableProductAnalyzer.json")  
public class ReviewableProduct  
@Field(type = FieldType.Keyword, analyzer = "rp\_analyzer", searchAnalyzer="rp\_analyzer") private String reviewableProductId;  
@Field(type=FieldType.Keyword, analyzer="rp\_analyzer" , searchAnalyzer="rp\_analyzer", name="productName") private String productName;

I appreciate any help. Thanks all.

---

<div class="post-metadata">

**Author:** ![nealdan0](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nealdan0/32/86952_2.png) [@nealdan0](https://discuss.elastic.co/u/nealdan0)\
**Post date:** [April 14, 2021, 12:00pm UTC](https://discuss.elastic.co/t/issues-trying-to-search-with-ngram-tokenizer/269946/2 "2021-04-14T12:00:43Z")

</div>

Figured it out. I was not creating the index properly, so the ngrams were never built.

---

<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:** [May 12, 2021, 12:00pm UTC](https://discuss.elastic.co/t/issues-trying-to-search-with-ngram-tokenizer/269946/3 "2021-05-12T12:00:54Z")

</div>

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