# Why isn't search\_analyzer supported for numeric field mapping?

**URL:** <https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677>\
**Category:** Elasticsearch\
**Created:** [April 26, 2019, 3:33pm UTC](https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677 "2019-04-26T15:33:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdmcalee](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jdmcalee](https://discuss.elastic.co/u/jdmcalee)\
**Post date:** [April 26, 2019, 3:33pm UTC](https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677/1 "2019-04-26T15:33:41Z")

</div>

I understand that numeric fields are not analyzed at index time. What I was hoping to do was to use a custom analyzer at query time, always, on a numeric phone number field to strip out all non-digit characters using a char\_filter.

I can, in fact, do this by specifying the analyzer in my query, and it works as expected: "123-456-7890" matches 1234567890. However, I don't want to have to ensure that's done everywhere anyone queries the field. Additionally, that doesn't help me when I do a multi\_match query, for example.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [April 29, 2019, 8:50am UTC](https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677/2 "2019-04-29T08:50:51Z")

</div>

Hi Justin,  
Numeric fields are typically reserved for representing _quantities_ that are optimised for range queries (money, byte sizes etc).  
A telephone number is a number but as a form of [identifier is perhaps best indexed as a keyword field](https://www.elastic.co/guide/en/elasticsearch/reference/7.0/tune-for-search-speed.html#_consider_mapping_identifiers_as_literal_keyword_literal) - I doubt you'll ever need to do range queries on these numbers. Keyword fields can have a [normalizer](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-normalizers.html) to treat them.

---

<div class="post-metadata">

**Author:** ![jdmcalee](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jdmcalee](https://discuss.elastic.co/u/jdmcalee)\
**Post date:** [April 29, 2019, 2:05pm UTC](https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677/3 "2019-04-29T14:05:39Z")

</div>

Thanks, you're probably right about the type. I actually did play around with making it a keyword, and it did work as desired on ingest. But, it's the query behavior that's actually my primary concern here, and keywords don't allow you to specify a search\_analyzer, either.

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [April 29, 2019, 2:24pm UTC](https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677/4 "2019-04-29T14:24:44Z")

</div>

Don't you just let the index and search time use the same normalization approach? i.e.

```
DELETE test
PUT test
{
  "settings": {
	"analysis": {
	  "char_filter": {
		"strip-hyphens": {
		  "type": "mapping",
		  "mappings": [
			"- => "
		  ]
		}
	  },
	  "normalizer": {
		"my_normalizer": {
		  "type": "custom",
		  "char_filter": ["strip-hyphens"]
		}
	  }
	}
  },
  "mappings": {
	"properties": {
	  "foo": {
		"type": "keyword",
		"normalizer": "my_normalizer"
	  }
	}
  }
}
POST test/_doc/1
{
  "foo": "123-456"
}
GET test/_search
{
  "size":0,
  "aggs":{
	"terms":{
	  "terms":{
		"field":"foo"
	  }
	}
  }
}

GET test/_search?q=123-456
GET test/_search?q=123-654
```

---

<div class="post-metadata">

**Author:** ![jdmcalee](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jdmcalee](https://discuss.elastic.co/u/jdmcalee)\
**Post date:** [April 29, 2019, 7:28pm UTC](https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677/5 "2019-04-29T19:28:37Z")

</div>

I thought so, but I will go back and set it up again using your example for guidance. Thanks.

---

<div class="post-metadata">

**Author:** ![jdmcalee](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@jdmcalee](https://discuss.elastic.co/u/jdmcalee)\
**Post date:** [April 30, 2019, 5:30pm UTC](https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677/6 "2019-04-30T17:30:08Z")

</div>

I must have done something incorrectly before. This setup is working as I want now. Thanks for the help.

---

<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 28, 2019, 5:30pm UTC](https://discuss.elastic.co/t/why-isnt-search-analyzer-supported-for-numeric-field-mapping/178677/7 "2019-05-28T17:30:08Z")

</div>

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