# Help me in searching hyphen contains parts

**URL:** <https://discuss.elastic.co/t/help-me-in-searching-hyphen-contains-parts/121476>\
**Category:** Elasticsearch\
**Created:** [February 26, 2018, 11:40am UTC](https://discuss.elastic.co/t/help-me-in-searching-hyphen-contains-parts/121476 "2018-02-26T11:40:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phani\_Nadiminti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phani_nadiminti/32/45381_2.png) [@Phani\_Nadiminti](https://discuss.elastic.co/u/Phani_Nadiminti)\
**Post date:** [February 26, 2018, 11:40am UTC](https://discuss.elastic.co/t/help-me-in-searching-hyphen-contains-parts/121476/1 "2018-02-26T11:40:48Z")

</div>

Hi All,

I am working on Searching parts in elasticsearch I have elasticsearch version 5.1.1 with me.the index has contains partNumbers which has values like 044-1215S etc.. and mostly it contains dots and special characters. I have built the following analyzer for this to support the criteria

PUT /test  
{  
"settings": {  
"number\_of\_shards": 1,  
"analysis": {  
"filter": {  
"ngram\_filter": {  
"type": "edge\_ngram",  
"min\_gram": 2,  
"max\_gram": 20  
}  
},  
"analyzer": {  
"ngram\_analyzer": {  
"type": "custom",  
"tokenizer": "standard",  
"filter": [  
"lowercase",  
"ngram\_filter"  
]  
}  
}  
}  
},  
"mappings": {  
"p1":{  
"properties": {  
"partNumber":{  
"type": "text",  
"analyzer": "ngram\_analyzer",  
"search\_analyzer": "standard"  
}  
}  
}  
}  
}

- All my partial matches working.
- but term queries not working with hyphen it is considering at all when i checked analyzer .

can a term query will work on this ? is there any special analyzers which can work with all most of the special characters that lucene allowed.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 26, 2018, 8:42pm UTC](https://discuss.elastic.co/t/help-me-in-searching-hyphen-contains-parts/121476/2 "2018-02-26T20:42:32Z")

</div>

> [@Phani\_Nadiminti](#):
>
> can a term query will work on this ?

A `term` query _can_ work with this, but a `term` query input does not undergo analysis, so the search query input will be querying against input that has been analyzed at index time with the `ngram_analyzer`.

What perhaps you may want to do is [map `partNumber` as a `multi_field`](https://www.elastic.co/guide/en/elasticsearch/reference/current/multi-fields.html) where one field uses the `ngram_analyzer` to support partial matches, and another field is [mapped as a `keyword` type](https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html), to support verbatim matches.

---

<div class="post-metadata">

**Author:** ![Phani\_Nadiminti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/phani_nadiminti/32/45381_2.png) [@Phani\_Nadiminti](https://discuss.elastic.co/u/Phani_Nadiminti)\
**Post date:** [February 28, 2018, 6:25am UTC](https://discuss.elastic.co/t/help-me-in-searching-hyphen-contains-parts/121476/3 "2018-02-28T06:25:01Z")

</div>

Hi ,

Thank you for the suggestions yes this way i will try . and one more doubt is there any flexibility to search words like (hyphen contained parts ) 45-5 in part 45589 **45-5** 63 can we form tokenize or methods to make the above search please advice.

---

<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:** [March 28, 2018, 6:25am UTC](https://discuss.elastic.co/t/help-me-in-searching-hyphen-contains-parts/121476/4 "2018-03-28T06:25:36Z")

</div>

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