# Exact match search on field with "standard" analyzer

**URL:** <https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617>\
**Category:** Elasticsearch\
**Created:** [November 8, 2012, 4:28am UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617 "2012-11-08T04:28:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hemant\_pahilwani](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hemant\_pahilwani](https://discuss.elastic.co/u/hemant_pahilwani)\
**Post date:** [November 8, 2012, 4:28am UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/1 "2012-11-08T04:28:19Z")

</div>

Hi,

i have following mapping where firstname is analyzed using standard  
analyzer. The reason for using standar analyzer is to allow regular search  
features on firstname field. I have a required to do exact search and  
match query works fine as long as there are no special charaters in search  
string or field value. However if there is any special character like '@'  
which are stored in firstname field or if there are special characters in  
search string. the results are not as expected. Is there any way to make  
sure the exact search works with special characters?

Mapping:

> ```
> "mappings": {
> "user": {
> "_source": {
> "enabled": true
> },
> "properties": {
> "myuniqueid": {
> "type": "string",
> "index": "not_analyzed"
> },
> "firstname": {
> "type": "string",
> "index": "analyzed",
> "analyzer": "standard"
> },
> 
> ```

.  
.  
.

> ```
> }
> }
> }
> 
> ```

--

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [November 8, 2012, 10:12am UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/2 "2012-11-08T10:12:55Z")

</div>

On Thursday, November 8, 2012 5:28:19 AM UTC+1, hemantp wrote:

> Hi,
> 
> i have following mapping where firstname is analyzed using standard  
> analyzer. The reason for using standar analyzer is to allow regular search  
> features on firstname field. I have a required to do exact search and  
> match query works fine as long as there are no special charaters in search  
> string or field value. However if there is any special character like '@'  
> which are stored in firstname field or if there are special characters in  
> search string. the results are not as expected. Is there any way to make  
> sure the exact search works with special characters?

hey,

can you elaborate on what an exact match means to you. An example would be  
great too so I can give you good advice.

simon

> Mapping:
> 
> > ```
> > "mappings": {
> > "user": {
> > "_source": {
> > "enabled": true
> > },
> > "properties": {
> > "myuniqueid": {
> > "type": "string",
> > "index": "not_analyzed"
> > },
> > "firstname": {
> > "type": "string",
> > "index": "analyzed",
> > "analyzer": "standard"
> > },
> > 
> > ```
> 
> .  
> .  
> .
> 
> > ```
> > }
> > }
> > }
> > 
> > ```

--

---

<div class="post-metadata">

**Author:** ![hemant\_pahilwani](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hemant\_pahilwani](https://discuss.elastic.co/u/hemant_pahilwani)\
**Post date:** [November 8, 2012, 4:21pm UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/3 "2012-11-08T16:21:00Z")

</div>

Exact match as in the record should be returned only if the value in  
firstname field is exactly same as the search string.(case ignored)

For example, if search string is John then it should only return records  
that have firstname as "John". records with firstname as Johnathan, Johny,  
Dijohn should not be returned. Exact match query works fine and results  
are as expected if there are no special characters like '@'.  
If the search string is "good@one", it returns records that have firstname  
as "good" as well as records with firstname as "one" and also records which  
have firstname as "good@one". I just want records which have "good@one" as  
firstname, it seems to divide search string into "good" and "one" and is  
returning results accordingly.

On Thursday, November 8, 2012 2:12:55 AM UTC-8, simonw wrote:

> On Thursday, November 8, 2012 5:28:19 AM UTC+1, hemantp wrote:
> 
> > Hi,
> > 
> > i have following mapping where firstname is analyzed using standard  
> > analyzer. The reason for using standar analyzer is to allow regular search  
> > features on firstname field. I have a required to do exact search and  
> > match query works fine as long as there are no special charaters in search  
> > string or field value. However if there is any special character like '@'  
> > which are stored in firstname field or if there are special characters in  
> > search string. the results are not as expected. Is there any way to make  
> > sure the exact search works with special characters?
> 
> hey,
> 
> can you elaborate on what an exact match means to you. An example would be  
> great too so I can give you good advice.
> 
> simon
> 
> > Mapping:
> > 
> > > ```
> > > "mappings": {
> > > "user": {
> > > "_source": {
> > > "enabled": true
> > > },
> > > "properties": {
> > > "myuniqueid": {
> > > "type": "string",
> > > "index": "not_analyzed"
> > > },
> > > "firstname": {
> > > "type": "string",
> > > "index": "analyzed",
> > > "analyzer": "standard"
> > > },
> > > 
> > > ```
> > 
> > .  
> > .  
> > .
> > 
> > > ```
> > > }
> > > }
> > > }
> > > 
> > > ```

--

---

<div class="post-metadata">

**Author:** ![hemant\_pahilwani](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hemant\_pahilwani](https://discuss.elastic.co/u/hemant_pahilwani)\
**Post date:** [November 8, 2012, 5:26pm UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/4 "2012-11-08T17:26:48Z")

</div>

match query that i am currently using, it is multi match because i will be  
adding more fields in future:

{query:{"multi\_match" : {"query" : "good@one","fields" : ["firstname"],  
"use\_dis\_max" : false}}}

On Thursday, November 8, 2012 8:21:05 AM UTC-8, hemantp wrote:

> Exact match as in the record should be returned only if the value in  
> firstname field is exactly same as the search string.(case ignored)
> 
> For example, if search string is John then it should only return records  
> that have firstname as "John". records with firstname as Johnathan, Johny,  
> Dijohn should not be returned. Exact match query works fine and results  
> are as expected if there are no special characters like '@'.  
> If the search string is "good@one", it returns records that have firstname  
> as "good" as well as records with firstname as "one" and also records which  
> have firstname as "good@one". I just want records which have "good@one" as  
> firstname, it seems to divide search string into "good" and "one" and is  
> returning results accordingly.
> 
> On Thursday, November 8, 2012 2:12:55 AM UTC-8, simonw wrote:
> 
> > On Thursday, November 8, 2012 5:28:19 AM UTC+1, hemantp wrote:
> > 
> > > Hi,
> > > 
> > > i have following mapping where firstname is analyzed using standard  
> > > analyzer. The reason for using standar analyzer is to allow regular search  
> > > features on firstname field. I have a required to do exact search and  
> > > match query works fine as long as there are no special charaters in search  
> > > string or field value. However if there is any special character like '@'  
> > > which are stored in firstname field or if there are special characters in  
> > > search string. the results are not as expected. Is there any way to make  
> > > sure the exact search works with special characters?
> > 
> > hey,
> > 
> > can you elaborate on what an exact match means to you. An example would  
> > be great too so I can give you good advice.
> > 
> > simon
> > 
> > > Mapping:
> > > 
> > > > ```
> > > > "mappings": {
> > > > "user": {
> > > > "_source": {
> > > > "enabled": true
> > > > },
> > > > "properties": {
> > > > "myuniqueid": {
> > > > "type": "string",
> > > > "index": "not_analyzed"
> > > > },
> > > > "firstname": {
> > > > "type": "string",
> > > > "index": "analyzed",
> > > > "analyzer": "standard"
> > > > },
> > > > 
> > > > ```
> > > 
> > > .  
> > > .  
> > > .
> > > 
> > > > ```
> > > > }
> > > > }
> > > > }
> > > > 
> > > > ```

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [November 8, 2012, 5:57pm UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/5 "2012-11-08T17:57:39Z")

</div>

You cannot achieve what you require by using the standard analyzer. The  
standard analyzer is tokenizing the string and creating two tokens: "good"  
and "one". You can see the results by using the analysis API:

curl '  
[http://localhost:9200/\_analyze?text=good@one&analyzer=standard&pretty=true](http://localhost:9200/_analyze?text=good@one&analyzer=standard&pretty=true)'

The field would need to be not\_analyzed in order for it to have an exact  
match, or at the very least, an analyzer that creates only one token (use  
case dependent).

If the field needs to be analyzed for other queries, you can use the  
multi-field type, which is a common use case:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

If you choose to set the field as not\_analyzed, then it will be case  
sensitive. You can create a custom analyzer that does not tokenize, but  
still applies a lowercase filter. Search the mailing list for examples.

Cheers,

Ivan

On Thu, Nov 8, 2012 at 8:21 AM, hemantp [hemant.pahilwani@gmail.com](mailto:hemant.pahilwani@gmail.com) wrote:

> Exact match as in the record should be returned only if the value in  
> firstname field is exactly same as the search string.(case ignored)
> 
> For example, if search string is John then it should only return records  
> that have firstname as "John". records with firstname as Johnathan, Johny,  
> Dijohn should not be returned. Exact match query works fine and results  
> are as expected if there are no special characters like '@'.  
> If the search string is "good@one", it returns records that have  
> firstname as "good" as well as records with firstname as "one" and also  
> records which have firstname as "good@one". I just want records which  
> have "good@one" as firstname, it seems to divide search string into  
> "good" and "one" and is returning results accordingly.
> 
> On Thursday, November 8, 2012 2:12:55 AM UTC-8, simonw wrote:
> 
> > On Thursday, November 8, 2012 5:28:19 AM UTC+1, hemantp wrote:
> > 
> > > Hi,
> > > 
> > > i have following mapping where firstname is analyzed using standard  
> > > analyzer. The reason for using standar analyzer is to allow regular search  
> > > features on firstname field. I have a required to do exact search and  
> > > match query works fine as long as there are no special charaters in search  
> > > string or field value. However if there is any special character like '@'  
> > > which are stored in firstname field or if there are special characters in  
> > > search string. the results are not as expected. Is there any way to make  
> > > sure the exact search works with special characters?
> > 
> > hey,
> > 
> > can you elaborate on what an exact match means to you. An example would  
> > be great too so I can give you good advice.
> > 
> > simon
> > 
> > > Mapping:
> > > 
> > > > ```
> > > > "mappings": {
> > > > "user": {
> > > > "_source": {
> > > > "enabled": true
> > > > },
> > > > "properties": {
> > > > "myuniqueid": {
> > > > "type": "string",
> > > > "index": "not_analyzed"
> > > > },
> > > > "firstname": {
> > > > "type": "string",
> > > > "index": "analyzed",
> > > > "analyzer": "standard"
> > > > },
> > > > 
> > > > ```
> > > 
> > > .  
> > > .  
> > > .
> > > 
> > > > ```
> > > > }
> > > > }
> > > > }
> > > > 
> > > > ```
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![hemant\_pahilwani](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hemant\_pahilwani](https://discuss.elastic.co/u/hemant_pahilwani)\
**Post date:** [November 8, 2012, 9:45pm UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/6 "2012-11-08T21:45:33Z")

</div>

Thanks Ivan, this is the answer is was looking for. One small question:

I have an existing index with half a million records and i will be using  
putmapping to change the mapping for firstname field to multi-field type in  
order to store not\_analyzed version of firstname. After changing the  
mapping, do i need to reindex all the records?

On Thursday, November 8, 2012 9:57:42 AM UTC-8, Ivan Brusic wrote:

> You cannot achieve what you require by using the standard analyzer. The  
> standard analyzer is tokenizing the string and creating two tokens: "good"  
> and "one". You can see the results by using the analysis API:
> 
> curl '  
> [http://localhost:9200/\_analyze?text=good@one&analyzer=standard&pretty=true](http://localhost:9200/_analyze?text=good@one&analyzer=standard&pretty=true)  
> '
> 
> The field would need to be not\_analyzed in order for it to have an exact  
> match, or at the very least, an analyzer that creates only one token (use  
> case dependent).
> 
> If the field needs to be analyzed for other queries, you can use the  
> multi-field type, which is a common use case:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)
> 
> If you choose to set the field as not\_analyzed, then it will be case  
> sensitive. You can create a custom analyzer that does not tokenize, but  
> still applies a lowercase filter. Search the mailing list for examples.
> 
> Cheers,
> 
> Ivan
> 
> On Thu, Nov 8, 2012 at 8:21 AM, hemantp \<[hemant.p...@gmail.com](mailto:hemant.p...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Exact match as in the record should be returned only if the value in  
> > firstname field is exactly same as the search string.(case ignored)
> > 
> > For example, if search string is John then it should only return records  
> > that have firstname as "John". records with firstname as Johnathan, Johny,  
> > Dijohn should not be returned. Exact match query works fine and results  
> > are as expected if there are no special characters like '@'.  
> > If the search string is "good@one", it returns records that have  
> > firstname as "good" as well as records with firstname as "one" and also  
> > records which have firstname as "good@one". I just want records which have  
> > "good@one" as firstname, it seems to divide search string into "good" and  
> > "one" and is returning results accordingly.
> > 
> > On Thursday, November 8, 2012 2:12:55 AM UTC-8, simonw wrote:
> > 
> > > On Thursday, November 8, 2012 5:28:19 AM UTC+1, hemantp wrote:
> > > 
> > > > Hi,
> > > > 
> > > > i have following mapping where firstname is analyzed using standard  
> > > > analyzer. The reason for using standar analyzer is to allow regular search  
> > > > features on firstname field. I have a required to do exact search and  
> > > > match query works fine as long as there are no special charaters in search  
> > > > string or field value. However if there is any special character like '@'  
> > > > which are stored in firstname field or if there are special characters in  
> > > > search string. the results are not as expected. Is there any way to make  
> > > > sure the exact search works with special characters?
> > > 
> > > hey,
> > > 
> > > can you elaborate on what an exact match means to you. An example would  
> > > be great too so I can give you good advice.
> > > 
> > > simon
> > > 
> > > > Mapping:
> > > > 
> > > > > ```
> > > > > "mappings": {
> > > > > "user": {
> > > > > "_source": {
> > > > > "enabled": true
> > > > > },
> > > > > "properties": {
> > > > > "myuniqueid": {
> > > > > "type": "string",
> > > > > "index": "not_analyzed"
> > > > > },
> > > > > "firstname": {
> > > > > "type": "string",
> > > > > "index": "analyzed",
> > > > > "analyzer": "standard"
> > > > > },
> > > > > 
> > > > > ```
> > > > 
> > > > .  
> > > > .  
> > > > .
> > > > 
> > > > > ```
> > > > > }
> > > > > }
> > > > > }
> > > > > 
> > > > > ```
> > > 
> > > --

--

---

<div class="post-metadata">

**Author:** ![simonw\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/simonw_2/32/1130_2.png) [@simonw\_2](https://discuss.elastic.co/u/simonw_2)\
**Post date:** [November 9, 2012, 8:26am UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/7 "2012-11-09T08:26:02Z")

</div>

On Thursday, November 8, 2012 10:45:33 PM UTC+1, hemantp wrote:

> Thanks Ivan, this is the answer is was looking for. One small question:
> 
> I have an existing index with half a million records and i will be using  
> putmapping to change the mapping for firstname field to multi-field type in  
> order to store not\_analyzed version of firstname. After changing the  
> mapping, do i need to reindex all the records?

hey there,

the simple answer is: yes!

simon

> On Thursday, November 8, 2012 9:57:42 AM UTC-8, Ivan Brusic wrote:
> 
> > You cannot achieve what you require by using the standard analyzer. The  
> > standard analyzer is tokenizing the string and creating two tokens: "good"  
> > and "one". You can see the results by using the analysis API:
> > 
> > curl '  
> > [http://localhost:9200/\_analyze?text=good@one&analyzer=standard&pretty=true](http://localhost:9200/_analyze?text=good@one&analyzer=standard&pretty=true)  
> > '
> > 
> > The field would need to be not\_analyzed in order for it to have an exact  
> > match, or at the very least, an analyzer that creates only one token (use  
> > case dependent).
> > 
> > If the field needs to be analyzed for other queries, you can use the  
> > multi-field type, which is a common use case:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html)
> > 
> > If you choose to set the field as not\_analyzed, then it will be case  
> > sensitive. You can create a custom analyzer that does not tokenize, but  
> > still applies a lowercase filter. Search the mailing list for examples.
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Thu, Nov 8, 2012 at 8:21 AM, hemantp [hemant.p...@gmail.com](mailto:hemant.p...@gmail.com) wrote:
> > 
> > > Exact match as in the record should be returned only if the value in  
> > > firstname field is exactly same as the search string.(case ignored)
> > > 
> > > For example, if search string is John then it should only return records  
> > > that have firstname as "John". records with firstname as Johnathan, Johny,  
> > > Dijohn should not be returned. Exact match query works fine and results  
> > > are as expected if there are no special characters like '@'.  
> > > If the search string is "good@one", it returns records that have  
> > > firstname as "good" as well as records with firstname as "one" and also  
> > > records which have firstname as "good@one". I just want records which have  
> > > "good@one" as firstname, it seems to divide search string into "good" and  
> > > "one" and is returning results accordingly.
> > > 
> > > On Thursday, November 8, 2012 2:12:55 AM UTC-8, simonw wrote:
> > > 
> > > > On Thursday, November 8, 2012 5:28:19 AM UTC+1, hemantp wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > i have following mapping where firstname is analyzed using standard  
> > > > > analyzer. The reason for using standar analyzer is to allow regular search  
> > > > > features on firstname field. I have a required to do exact search and  
> > > > > match query works fine as long as there are no special charaters in search  
> > > > > string or field value. However if there is any special character like '@'  
> > > > > which are stored in firstname field or if there are special characters in  
> > > > > search string. the results are not as expected. Is there any way to make  
> > > > > sure the exact search works with special characters?
> > > > 
> > > > hey,
> > > > 
> > > > can you elaborate on what an exact match means to you. An example would  
> > > > be great too so I can give you good advice.
> > > > 
> > > > simon
> > > > 
> > > > > Mapping:
> > > > > 
> > > > > > ```
> > > > > > "mappings": {
> > > > > > "user": {
> > > > > > "_source": {
> > > > > > "enabled": true
> > > > > > },
> > > > > > "properties": {
> > > > > > "myuniqueid": {
> > > > > > "type": "string",
> > > > > > "index": "not_analyzed"
> > > > > > },
> > > > > > "firstname": {
> > > > > > "type": "string",
> > > > > > "index": "analyzed",
> > > > > > "analyzer": "standard"
> > > > > > },
> > > > > > 
> > > > > > ```
> > > > > 
> > > > > .  
> > > > > .  
> > > > > .
> > > > > 
> > > > > > ```
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > > 
> > > > > > ```
> > > > 
> > > > --

--

---

<div class="post-metadata">

**Author:** ![gsojitra](https://avatars.discourse-cdn.com/v4/letter/g/e79b87/32.png) [@gsojitra](https://discuss.elastic.co/u/gsojitra)\
**Post date:** [July 5, 2017, 7:24am UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/8 "2017-07-05T07:24:36Z")

</div>

> [@hemant\_pahilwani](#):
>
> good@one

You can use match\_phrase query to solve this problem.

---

<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:** [November 4, 2022, 4:01am UTC](https://discuss.elastic.co/t/exact-match-search-on-field-with-standard-analyzer/9617/9 "2022-11-04T04:01:24Z")

</div>


