# Analyzer to deal with padded 0s?

**URL:** <https://discuss.elastic.co/t/analyzer-to-deal-with-padded-0s/2593>\
**Category:** Elasticsearch\
**Created:** [June 12, 2015, 6:11pm UTC](https://discuss.elastic.co/t/analyzer-to-deal-with-padded-0s/2593 "2015-06-12T18:11:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Topper](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Topper](https://discuss.elastic.co/u/Mike_Topper)\
**Post date:** [June 12, 2015, 6:11pm UTC](https://discuss.elastic.co/t/analyzer-to-deal-with-padded-0s/2593/1 "2015-06-12T18:11:58Z")

</div>

Hello,

If I have a field that has the possibility of padded 0's at the beginning.

so values could be for example:

000012  
00X213  
452

Is there an analyzer that I could use that would index/search that field as if the padded 0s dont exist?

so for instance if i index 000012 i could search as '000012' or '12'?

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [June 15, 2015, 7:08am UTC](https://discuss.elastic.co/t/analyzer-to-deal-with-padded-0s/2593/2 "2015-06-15T07:08:39Z")

</div>

A [pattern analyzer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-pattern-analyzer.html) that has a regex to remove the padded zeros at search time and index time will do what you want.

```
{
   "settings":{
	  "analysis":{
		 "analyzer":{
			"padded_zero_removal":{
			   "type":"pattern",
			   "pattern":"^0+(?!$)"
			}
		 }
	    }
      }
}

```

You can use the [Analyze API](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html) to test it, send the term '00000012':

```
curl -XGET 'localhost:9200/{yourIndex}/_analyze?analyzer=padded_zero_removal&pretty=true' -d '00000012'

```

The response.

```
{
  "tokens" : [ {
	"token" : "12",
	"start_offset" : 6,
	"end_offset" : 8,
	"type" : "word",
	"position" : 1
  } ]
}

```

---

<div class="post-metadata">

**Author:** ![Mike\_Topper](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@Mike\_Topper](https://discuss.elastic.co/u/Mike_Topper)\
**Post date:** [June 15, 2015, 7:27pm UTC](https://discuss.elastic.co/t/analyzer-to-deal-with-padded-0s/2593/3 "2015-06-15T19:27:21Z")

</div>

thank you!

---

<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, 12:07am UTC](https://discuss.elastic.co/t/analyzer-to-deal-with-padded-0s/2593/4 "2017-07-06T00:07:21Z")

</div>


