# Pattern\_replace Token Filter

**URL:** <https://discuss.elastic.co/t/pattern-replace-token-filter/10846>\
**Category:** Elasticsearch\
**Created:** [February 21, 2013, 6:05pm UTC](https://discuss.elastic.co/t/pattern-replace-token-filter/10846 "2013-02-21T18:05:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asafreedman](https://avatars.discourse-cdn.com/v4/letter/a/ac8455/32.png) [@asafreedman](https://discuss.elastic.co/u/asafreedman)\
**Post date:** [February 21, 2013, 6:05pm UTC](https://discuss.elastic.co/t/pattern-replace-token-filter/10846/1 "2013-02-21T18:05:10Z")

</div>

I think I'm having some problem understanding how the pattern\_replace token filter works.

What I am trying to do is replace dashes and other non-digit characters in a string before it gets put into elasticsearch. So, that way a person can search on a number regardless of the way it was put in the interface. Nothing is being replaced.

Here is my setting and mapping

"settings" : {  
"analysis" : {  
"filter" : {  
"phone\_number\_cleaner": {  
"type": "pattern\_replace",  
"pattern": "\D",  
"replacement": ""  
}  
},  
"analyzer" : {  
"whitespace\_delimited\_pattern" : {  
"type" : "pattern",  
"pattern" : "\s+"  
},  
"phone\_nondig\_filter": {  
"filter": ["phone\_number\_cleaner"],  
"type": "custom",  
"tokenizer": "standard"  
}  
}  
}  
}

Mapping:

"contact\_search" : {  
"properties" : {  
"state.tags" : {"type" : "string", "store":"yes", "index\_analyzer":"standard"},  
"state.firstname" : {"type":"string","store":"yes", "index\_analyzer":"whitespace\_delimited\_pattern"},  
"state.lastname" : {"type":"string","store":"yes", "index\_analyzer":"whitespace\_delimited\_pattern"},  
"state.comm.COMP" : {"type":"nested","store":"yes", "index\_analyzer":"standard"},  
"state.comm.PHONE" : {  
"fields" : {  
"phonevalue": {  
"type":"string",  
"store":"yes",  
"index\_analyzer":"phone\_nondig\_filter"  
},  
"phonelabel": {  
"type":"string",  
"store":"yes",  
"index\_analyzer":"standard"  
}  
},  
"type": "multi\_field"  
}  
}  
}

---

<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, 2:50am UTC](https://discuss.elastic.co/t/pattern-replace-token-filter/10846/2 "2017-07-06T02:50:13Z")

</div>


