# How to store email address and username without the part search

**URL:** <https://discuss.elastic.co/t/how-to-store-email-address-and-username-without-the-part-search/9698>\
**Category:** Elasticsearch\
**Created:** [November 13, 2012, 4:35pm UTC](https://discuss.elastic.co/t/how-to-store-email-address-and-username-without-the-part-search/9698 "2012-11-13T16:35:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul\_cdf](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@paul\_cdf](https://discuss.elastic.co/u/paul_cdf)\
**Post date:** [November 13, 2012, 4:35pm UTC](https://discuss.elastic.co/t/how-to-store-email-address-and-username-without-the-part-search/9698/1 "2012-11-13T16:35:37Z")

</div>

Hi,

I'm new to elasticsearch, and am having issues setting up document mapping,  
i have set up multiple indexes, one per language, and have the same  
document mapping set up per index (see below) i'm trying to set it up, so  
the user can search for the username or email address as a whole, and not  
allow them to do a part search of them, how can I achieve this?

Excuse the php :

'id' =\> array('type' =\> 'string', 'store' =\> 'yes', 'index' =\>  
'no', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
'username' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
'not\_analyzed', 'boost' =\> 2.0, 'include\_in\_all' =\> true),  
'email\_address' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
'not\_analyzed', 'boost' =\> 2.0, 'include\_in\_all' =\> true),  
'bio' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
'first\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
'last\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
'company\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
'active' =\> array('type' =\> 'boolean', 'store' =\> 'yes', 'index' =\>  
'no' , 'boost' =\> 1.0, 'include\_in\_all' =\> true),

--

---

<div class="post-metadata">

**Author:** ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)\
**Post date:** [November 13, 2012, 10:47pm UTC](https://discuss.elastic.co/t/how-to-store-email-address-and-username-without-the-part-search/9698/2 "2012-11-13T22:47:38Z")

</div>

Hi Paul,

What problem are you seeing with your mappings?

I see you've marked username and email\_address as not\_analyzed which will  
mean they will be indexed as a single term, which seems to be the behaviour  
you are after. Are you able to share some queries that are not working as  
you'd hoped?

On Wednesday, November 14, 2012 5:35:37 AM UTC+13, paul.cdf wrote:

> Hi,
> 
> I'm new to elasticsearch, and am having issues setting up document  
> mapping, i have set up multiple indexes, one per language, and have the  
> same document mapping set up per index (see below) i'm trying to set it up,  
> so the user can search for the username or email address as a whole, and  
> not allow them to do a part search of them, how can I achieve this?
> 
> Excuse the php :
> 
> 'id' =\> array('type' =\> 'string', 'store' =\> 'yes', 'index' =\>  
> 'no', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> 'username' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> 'not\_analyzed', 'boost' =\> 2.0, 'include\_in\_all' =\> true),  
> 'email\_address' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> 'not\_analyzed', 'boost' =\> 2.0, 'include\_in\_all' =\> true),  
> 'bio' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> 'first\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> 'last\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> 'company\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> 'active' =\> array('type' =\> 'boolean', 'store' =\> 'yes', 'index' =\>  
> 'no' , 'boost' =\> 1.0, 'include\_in\_all' =\> true),

--

---

<div class="post-metadata">

**Author:** ![paul\_cdf](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@paul\_cdf](https://discuss.elastic.co/u/paul_cdf)\
**Post date:** [November 14, 2012, 4:30pm UTC](https://discuss.elastic.co/t/how-to-store-email-address-and-username-without-the-part-search/9698/3 "2012-11-14T16:30:01Z")

</div>

If I do a search on an email address for example [testing@hotmail.com](mailto:testing@hotmail.com) by  
using the query testing\* , it's still found, i dont want it to be able to  
be found unless someone types in the whole email address.

My Mapping is now set up as this

{"person":{"index\_analyzer":"indexAnalyzerEnglish","search\_analyzer":"searchAnalyzerEnglish","\_all":{"auto\_boost":true,"analyzer":"uax\_url\_email"},"properties":{"a":{"type":"boolean","index":"no","store":"yes"},"b":{"type":"string","include\_in\_all":true},"cn":{"type":"string","include\_in\_all":true},"ea":{"type":"string","boost":2.0,"index":"not\_analyzed","include\_in\_all":true},"fn":{"type":"string","include\_in\_all":true},"id":{"type":"string","index":"no","store":"yes","include\_in\_all":true},"ln":{"type":"string","include\_in\_all":true},"un":{"type":"string","boost":2.0,"index":"not\_analyzed","include\_in\_all":true}}}}

And my settings are as follows

{"english":{"settings":{"index.number\_of\_replicas":"1","index.analysis.filter.mySnowballEnglish.language":"English","index.analysis.analyzer.searchAnalyzerEnglish.type":"custom","index.analysis.analyzer.indexAnalyzerEnglish.tokenizer":"standard","index.analysis.analyzer.searchAnalyzerEnglish.tokenizer":"standard","index.analysis.analyzer.uax\_url\_email.tokenizer":"uax\_url\_email","index.analysis.analyzer.uax\_url\_email.filter.2":"stop","index.analysis.analyzer.uax\_url\_email.filter.1":"lowercase","index.analysis.analyzer.uax\_url\_email.filter.0":"standard","index.analysis.analyzer.indexAnalyzerEnglish.type":"custom","index.analysis.filter.mySnowballEnglish.type":"snowball","index.analysis.analyzer.searchAnalyzerEnglish.filter.2":"mySnowballEnglish","index.analysis.analyzer.searchAnalyzerEnglish.filter.1":"lowercase","index.analysis.analyzer.searchAnalyzerEnglish.filter.0":"standard","index.number\_of\_shards":"4","index.analysis.analyzer.indexAnalyzerEnglish.filter.1":"mySnowballEnglish","index.analysis.analyzer.indexAnalyzerEnglish.filter.0":"lowercase","index.version.created":"191199"}}}

is there something wrong with either?

On Tuesday, 13 November 2012 22:47:39 UTC, Chris Male wrote:

> Hi Paul,
> 
> What problem are you seeing with your mappings?
> 
> I see you've marked username and email\_address as not\_analyzed which will  
> mean they will be indexed as a single term, which seems to be the behaviour  
> you are after. Are you able to share some queries that are not working as  
> you'd hoped?
> 
> On Wednesday, November 14, 2012 5:35:37 AM UTC+13, paul.cdf wrote:
> 
> > Hi,
> > 
> > I'm new to elasticsearch, and am having issues setting up document  
> > mapping, i have set up multiple indexes, one per language, and have the  
> > same document mapping set up per index (see below) i'm trying to set it up,  
> > so the user can search for the username or email address as a whole, and  
> > not allow them to do a part search of them, how can I achieve this?
> > 
> > Excuse the php :
> > 
> > 'id' =\> array('type' =\> 'string', 'store' =\> 'yes', 'index' =\>  
> > 'no', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > 'username' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > 'not\_analyzed', 'boost' =\> 2.0, 'include\_in\_all' =\> true),  
> > 'email\_address' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > 'not\_analyzed', 'boost' =\> 2.0, 'include\_in\_all' =\> true),  
> > 'bio' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > 'first\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > 'last\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > 'company\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > 'active' =\> array('type' =\> 'boolean', 'store' =\> 'yes', 'index'  
> > =\> 'no' , 'boost' =\> 1.0, 'include\_in\_all' =\> true),

--

---

<div class="post-metadata">

**Author:** ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)\
**Post date:** [November 15, 2012, 3:29am UTC](https://discuss.elastic.co/t/how-to-store-email-address-and-username-without-the-part-search/9698/4 "2012-11-15T03:29:40Z")

</div>

Hi Paul,

On Thursday, November 15, 2012 5:30:01 AM UTC+13, paul.cdf wrote:

> If I do a search on an email address for example [tes...@hotmail.com](mailto:tes...@hotmail.com)\<javascript:\>by using the query testing\* , it's still found, i dont want it to be able  
> to be found unless someone types in the whole email address.

So you're executing a wildcard query and matching the email address, when  
you only want to match the email address when it's fully typed in? There's  
not much Elasticsearch can do can to help you here. I recommend you  
validate your query at the user input end and prevent any wildcard queries  
from being executed against the email address field.

> My Mapping is now set up as this
> 
> {"person":{"index\_analyzer":"indexAnalyzerEnglish","search\_analyzer":"searchAnalyzerEnglish","\_all":{"auto\_boost":true,"analyzer":"uax\_url\_email"},"properties":{"a":{"type":"boolean","index":"no","store":"yes"},"b":{"type":"string","include\_in\_all":true},"cn":{"type":"string","include\_in\_all":true},"ea":{"type":"string","boost":2.0,"index":"not\_analyzed","include\_in\_all":true},"fn":{"type":"string","include\_in\_all":true},"id":{"type":"string","index":"no","store":"yes","include\_in\_all":true},"ln":{"type":"string","include\_in\_all":true},"un":{"type":"string","boost":2.0,"index":"not\_analyzed","include\_in\_all":true}}}}
> 
> And my settings are as follows
> 
> {"english":{"settings":{"index.number\_of\_replicas":"1","index.analysis.filter.mySnowballEnglish.language":"English","index.analysis.analyzer.searchAnalyzerEnglish.type":"custom","index.analysis.analyzer.indexAnalyzerEnglish.tokenizer":"standard","index.analysis.analyzer.searchAnalyzerEnglish.tokenizer":"standard","index.analysis.analyzer.uax\_url\_email.tokenizer":"uax\_url\_email","index.analysis.analyzer.uax\_url\_email.filter.2":"stop","index.analysis.analyzer.uax\_url\_email.filter.1":"lowercase","index.analysis.analyzer.uax\_url\_email.filter.0":"standard","index.analysis.analyzer.indexAnalyzerEnglish.type":"custom","index.analysis.filter.mySnowballEnglish.type":"snowball","index.analysis.analyzer.searchAnalyzerEnglish.filter.2":"mySnowballEnglish","index.analysis.analyzer.searchAnalyzerEnglish.filter.1":"lowercase","index.analysis.analyzer.searchAnalyzerEnglish.filter.0":"standard","index.number\_of\_shards":"4","index.analysis.analyzer.indexAnalyzerEnglish.filter.1":"mySnowballEnglish","index.analysis.analyzer.indexAnalyzerEnglish.filter.0":"lowercase","index.version.created":"191199"}}}
> 
> is there something wrong with either?
> 
> On Tuesday, 13 November 2012 22:47:39 UTC, Chris Male wrote:
> 
> > Hi Paul,
> > 
> > What problem are you seeing with your mappings?
> > 
> > I see you've marked username and email\_address as not\_analyzed which will  
> > mean they will be indexed as a single term, which seems to be the behaviour  
> > you are after. Are you able to share some queries that are not working as  
> > you'd hoped?
> > 
> > On Wednesday, November 14, 2012 5:35:37 AM UTC+13, paul.cdf wrote:
> > 
> > > Hi,
> > > 
> > > I'm new to elasticsearch, and am having issues setting up document  
> > > mapping, i have set up multiple indexes, one per language, and have the  
> > > same document mapping set up per index (see below) i'm trying to set it up,  
> > > so the user can search for the username or email address as a whole, and  
> > > not allow them to do a part search of them, how can I achieve this?
> > > 
> > > Excuse the php :
> > > 
> > > 'id' =\> array('type' =\> 'string', 'store' =\> 'yes', 'index'  
> > > =\> 'no', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > > 'username' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > > 'not\_analyzed', 'boost' =\> 2.0, 'include\_in\_all' =\> true),  
> > > 'email\_address' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > > 'not\_analyzed', 'boost' =\> 2.0, 'include\_in\_all' =\> true),  
> > > 'bio' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > > 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > > 'first\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > > 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > > 'last\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > > 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > > 'company\_name' =\> array('type' =\> 'string', 'store' =\> 'no', 'index' =\>  
> > > 'analyzed', 'boost' =\> 1.0, 'include\_in\_all' =\> true),  
> > > 'active' =\> array('type' =\> 'boolean', 'store' =\> 'yes', 'index'  
> > > =\> 'no' , 'boost' =\> 1.0, 'include\_in\_all' =\> true),

--

---

<div class="post-metadata">

**Author:** ![paul\_cdf](https://avatars.discourse-cdn.com/v4/letter/p/e19b73/32.png) [@paul\_cdf](https://discuss.elastic.co/u/paul_cdf)\
**Post date:** [November 15, 2012, 10:34am UTC](https://discuss.elastic.co/t/how-to-store-email-address-and-username-without-the-part-search/9698/5 "2012-11-15T10:34:00Z")

</div>

Thats great, thanks!

--

---

<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:04am UTC](https://discuss.elastic.co/t/how-to-store-email-address-and-username-without-the-part-search/9698/6 "2017-07-06T03:04:09Z")

</div>


