# Map, analyze and search phone number

**URL:** <https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088>\
**Category:** Elasticsearch\
**Created:** [August 8, 2011, 8:13pm UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088 "2011-08-08T20:13:37Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sindre\_Sorhus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sindre_sorhus/32/3138_2.png) [@Sindre\_Sorhus](https://discuss.elastic.co/u/Sindre_Sorhus)\
**Post date:** [August 8, 2011, 8:13pm UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/1 "2011-08-08T20:13:37Z")

</div>

What is the best way to map, analyze and search a field with a phone number?

I have phone numbers in various formats.  
+47 23546798  
+47 23 54 67 98  
+47 235 46 798  
+4723546798  
23546798

I need to be able to search for "23546798" or "2354" and find all the phone  
numbers above. What kind of analyzers should I use?

Any thought's about ES having a built-in phone number field?

---

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [August 9, 2011, 7:03am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/2 "2011-08-09T07:03:45Z")

</div>

Hi,

This is essentially a search for an arbitrary substring. You can use  
n-grams for that.

## Otis

Sematext is hiring Search Engineers -- [Jobs](http://sematext.com/about/jobs.html)

On Aug 8, 4:13 pm, Sindre Sorhus [sindresor...@gmail.com](mailto:sindresor...@gmail.com) wrote:

> What is the best way to map, analyze and search a field with a phone number?
> 
> I have phone numbers in various formats.  
> +47 23546798  
> +47 23 54 67 98  
> +47 235 46 798  
> +4723546798  
> 23546798
> 
> I need to be able to search for "23546798" or "2354" and find all the phone  
> numbers above. What kind of analyzers should I use?
> 
> Any thought's about ES having a built-in phone number field?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 9, 2011, 9:08am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/3 "2011-08-09T09:08:53Z")

</div>

There was another thread where we talked a bit about having a specific phone  
number field, that would know about different phone number formats and index  
it in a form that would help make it more searchable (possibly as numeric  
field..., really depends on the type of search needed to be executed). It  
gets complicated when it comes to internalization and the like, and might  
not fit all cases, but we can try and start with something and see how it  
goes...

On Mon, Aug 8, 2011 at 11:13 PM, Sindre Sorhus [sindresorhus@gmail.com](mailto:sindresorhus@gmail.com)wrote:

> What is the best way to map, analyze and search a field with a phone  
> number?
> 
> I have phone numbers in various formats.  
> +47 23546798  
> +47 23 54 67 98  
> +47 235 46 798  
> +4723546798  
> 23546798
> 
> I need to be able to search for "23546798" or "2354" and find all the phone  
> numbers above. What kind of analyzers should I use?
> 
> Any thought's about ES having a built-in phone number field?

---

<div class="post-metadata">

**Author:** ![yark](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yark/32/3148_2.png) [@yark](https://discuss.elastic.co/u/yark)\
**Post date:** [August 9, 2011, 9:17am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/4 "2011-08-09T09:17:25Z")

</div>

Is just a new analyzer solve the problem?

We need analyzer, which able to ignore all not number chars and treat rest of chars as a separated chars, isn’t it?  
So than query of different parts of number as a "phrase" will match.

9 серп. 2011, в 12:08, Shay Banon написал(а):

> There was another thread where we talked a bit about having a specific phone number field, that would know about different phone number formats and index it in a form that would help make it more searchable (possibly as numeric field..., really depends on the type of search needed to be executed). It gets complicated when it comes to internalization and the like, and might not fit all cases, but we can try and start with something and see how it goes...
> 
> On Mon, Aug 8, 2011 at 11:13 PM, Sindre Sorhus [sindresorhus@gmail.com](mailto:sindresorhus@gmail.com) wrote:  
> What is the best way to map, analyze and search a field with a phone number?
> 
> I have phone numbers in various formats.  
> +47 23546798  
> +47 23 54 67 98  
> +47 235 46 798  
> +4723546798  
> 23546798
> 
> I need to be able to search for "23546798" or "2354" and find all the phone numbers above. What kind of analyzers should I use?
> 
> Any thought's about ES having a built-in phone number field?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 9, 2011, 9:19am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/5 "2011-08-09T09:19:42Z")

</div>

It depends since format of phone number can very. Also, it would be nice to  
have an option to "extract" phone numbers from text.

2011/8/9 Yaroslav [th-net@ya.ru](mailto:th-net@ya.ru)

> Is just a new analyzer solve the problem?
> 
> We need analyzer, which able to ignore all not number chars and treat rest  
> of chars as a separated chars, isn’t it?  
> So than query of different parts of number as a "phrase" will match.
> 
> 9 серп. 2011, в 12:08, Shay Banon написал(а):
> 
> There was another thread where we talked a bit about having a specific  
> phone number field, that would know about different phone number formats and  
> index it in a form that would help make it more searchable (possibly as  
> numeric field..., really depends on the type of search needed to be  
> executed). It gets complicated when it comes to internalization and the  
> like, and might not fit all cases, but we can try and start with something  
> and see how it goes...
> 
> On Mon, Aug 8, 2011 at 11:13 PM, Sindre Sorhus [sindresorhus@gmail.com](mailto:sindresorhus@gmail.com)wrote:
> 
> > What is the best way to map, analyze and search a field with a phone  
> > number?
> > 
> > I have phone numbers in various formats.  
> > +47 23546798  
> > +47 23 54 67 98  
> > +47 235 46 798  
> > +4723546798  
> > 23546798
> > 
> > I need to be able to search for "23546798" or "2354" and find all the  
> > phone numbers above. What kind of analyzers should I use?
> > 
> > Any thought's about ES having a built-in phone number field?

---

<div class="post-metadata">

**Author:** ![karmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karmi/32/44951_2.png) [@karmi](https://discuss.elastic.co/u/karmi)\
**Post date:** [August 9, 2011, 1:08pm UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/6 "2011-08-09T13:08:06Z")

</div>

Couldn't regex based analyzer be used for extracting phone numbers? I  
guess it would be a bit more lightweight then n-grams?

Karel

On Aug 9, 9:03 am, Otis Gospodnetic [otis.gospodne...@gmail.com](mailto:otis.gospodne...@gmail.com)  
wrote:

> Hi,
> 
> This is essentially a search for an arbitrary substring. You can use  
> n-grams for that.
> 
> ## Otis
> 
> Sematext is hiring Search Engineers --[Jobs - Sematext](http://sematext.com/about/jobs.html)
> 
> On Aug 8, 4:13 pm, Sindre Sorhus [sindresor...@gmail.com](mailto:sindresor...@gmail.com) wrote:
> 
> > What is the best way to map, analyze and search a field with a phone number?
> 
> > I have phone numbers in various formats.  
> > +47 23546798  
> > +47 23 54 67 98  
> > +47 235 46 798  
> > +4723546798  
> > 23546798
> 
> > I need to be able to search for "23546798" or "2354" and find all the phone  
> > numbers above. What kind of analyzers should I use?
> 
> > Any thought's about ES having a built-in phone number field?

---

<div class="post-metadata">

**Author:** ![Sindre\_Sorhus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sindre_sorhus/32/3138_2.png) [@Sindre\_Sorhus](https://discuss.elastic.co/u/Sindre_Sorhus)\
**Post date:** [August 10, 2011, 7:29am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/7 "2011-08-10T07:29:43Z")

</div>

That would be really useful. Not having to parse the phone numbers myself,  
and having them easily searchable.

---

<div class="post-metadata">

**Author:** ![Sindre\_Sorhus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sindre_sorhus/32/3138_2.png) [@Sindre\_Sorhus](https://discuss.elastic.co/u/Sindre_Sorhus)\
**Post date:** [August 10, 2011, 7:31am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/8 "2011-08-10T07:31:34Z")

</div>

Something like the iOS data detectors. This could work on more than phone  
number, dates, locations, ... but it depends on how big you want to make it.

---

<div class="post-metadata">

**Author:** ![Sindre\_Sorhus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sindre_sorhus/32/3138_2.png) [@Sindre\_Sorhus](https://discuss.elastic.co/u/Sindre_Sorhus)\
**Post date:** [August 10, 2011, 7:37am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/9 "2011-08-10T07:37:51Z")

</div>

How would that work with phone numbers with whitespace? What should I set on  
the min-max grams?

---

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [August 10, 2011, 5:01pm UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/10 "2011-08-10T17:01:11Z")

</div>

I haven't followed this thread closely, but it looks like there are 2  
separate things here:

1. phone number detection/extraction
2. phone number tokenization and search

Can't 1. be handled with something like GATE or any other NER tool?  
After 1. is done, isn't searching arbitrary phone number substrings  
just a matter of n-gramming?

## Otis

Sematext in hiring Search Engineers -- [Jobs](http://sematext.com/about/jobs.html)

On Aug 10, 3:37 am, Sindre Sorhus [sindresor...@gmail.com](mailto:sindresor...@gmail.com) wrote:

> How would that work with phone numbers with whitespace? What should I set on  
> the min-max grams?

---

<div class="post-metadata">

**Author:** ![Sindre\_Sorhus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sindre_sorhus/32/3138_2.png) [@Sindre\_Sorhus](https://discuss.elastic.co/u/Sindre_Sorhus)\
**Post date:** [August 15, 2011, 2:14pm UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/11 "2011-08-15T14:14:46Z")

</div>

Should I file a bug on github for it?

---

<div class="post-metadata">

**Author:** ![David\_Sachs](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@David\_Sachs](https://discuss.elastic.co/u/David_Sachs)\
**Post date:** [August 17, 2011, 9:04pm UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/12 "2011-08-17T21:04:30Z")

</div>

Perhaps you could use/integrate [http://code.google.com/p/libphonenumber/](http://code.google.com/p/libphonenumber/),  
Google's library for phone number parsing in a variety of locales/formats.  
It's Apache-licensed as well.

David

---

<div class="post-metadata">

**Author:** ![Sindre\_Sorhus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sindre_sorhus/32/3138_2.png) [@Sindre\_Sorhus](https://discuss.elastic.co/u/Sindre_Sorhus)\
**Post date:** [August 18, 2011, 7:27am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/13 "2011-08-18T07:27:21Z")

</div>

Yes, I know, that's what I ended up using. But still, it would be very  
convenient with a "phonenumber" type in ES.

---

<div class="post-metadata">

**Author:** ![Sindre\_Sorhus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sindre_sorhus/32/3138_2.png) [@Sindre\_Sorhus](https://discuss.elastic.co/u/Sindre_Sorhus)\
**Post date:** [August 18, 2011, 11:53am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/14 "2011-08-18T11:53:39Z")

</div>

Old discussion  
here: [http://groups.google.com/a/elasticsearch.com/group/users/browse\_thread/thread/459046042558bfeb](http://groups.google.com/a/elasticsearch.com/group/users/browse_thread/thread/459046042558bfeb)

---

<div class="post-metadata">

**Author:** ![Sindre\_Sorhus](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sindre_sorhus/32/3138_2.png) [@Sindre\_Sorhus](https://discuss.elastic.co/u/Sindre_Sorhus)\
**Post date:** [August 19, 2011, 3:14pm UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/15 "2011-08-19T15:14:55Z")

</div>

I tried using nGrams, but I can't get it to work.

I have a number saved in ES as a string like this "48121245", but when I  
search for "481 21 245", it doesn't find anything.

What am I doing wrong?

settings: [https://gist.github.com/1157005](https://gist.github.com/1157005)  
mapping: [https://gist.github.com/1157027](https://gist.github.com/1157027)

---

<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, 3:56am UTC](https://discuss.elastic.co/t/map-analyze-and-search-phone-number/5088/16 "2017-07-06T03:56:32Z")

</div>


