# Exact match a string

**URL:** <https://discuss.elastic.co/t/exact-match-a-string/8332>\
**Category:** Elasticsearch\
**Created:** [July 5, 2012, 5:49pm UTC](https://discuss.elastic.co/t/exact-match-a-string/8332 "2012-07-05T17:49:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![coys](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@coys](https://discuss.elastic.co/u/coys)\
**Post date:** [July 5, 2012, 5:49pm UTC](https://discuss.elastic.co/t/exact-match-a-string/8332/1 "2012-07-05T17:49:16Z")

</div>

Hello, I would like to perform an exact match on a string - say for  
e.g. the field status which is an enum - taking 2 values  
["Automated","To be Automated"].

When I query for status:"To be automated" I require that it return  
only those results where status is exactly "To be Automated" and not  
"Automated" and if I query for status:"Automated" I again require that  
it does not return to me the results where status is "To be  
Automated".

I read a previous question where it was suggested that I set index to  
not\_analyzed or keyword for the above field, but is there a way for me  
to get these results without doing the above..and just with the help  
of a query? Thanks!

---

<div class="post-metadata">

**Author:** ![Shaun\_Farrell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaun_farrell/32/2827_2.png) [@Shaun\_Farrell](https://discuss.elastic.co/u/Shaun_Farrell)\
**Post date:** [July 5, 2012, 5:58pm UTC](https://discuss.elastic.co/t/exact-match-a-string/8332/2 "2012-07-05T17:58:31Z")

</div>

You can but I'm not sure it will be as performat to do it.

You can try a field query where its like

+automated -to -be

and see if that works. The problem is that you are using the default mapping i assume and its going to tokenize those strings.

Thanks,

Shaun Farrell

On Thursday, July 5, 2012 at 1:49 PM, coys wrote:

> Hello, I would like to perform an exact match on a string - say for  
> e.g. the field status which is an enum - taking 2 values  
> ["Automated","To be Automated"].
> 
> When I query for status:"To be automated" I require that it return  
> only those results where status is exactly "To be Automated" and not  
> "Automated" and if I query for status:"Automated" I again require that  
> it does not return to me the results where status is "To be  
> Automated".
> 
> I read a previous question where it was suggested that I set index to  
> not\_analyzed or keyword for the above field, but is there a way for me  
> to get these results without doing the above..and just with the help  
> of a query? Thanks!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 5, 2012, 6:18pm UTC](https://discuss.elastic.co/t/exact-match-a-string/8332/3 "2012-07-05T18:18:05Z")

</div>

With default analyzer, i'm afraid you will never find "to" and "be" as they are english common words. So -to -be won't have any effect.

My 2 cents.

David

--

Le 5 juil. 2012 à 19:58, Shaun Farrell [farrelley@gmail.com](mailto:farrelley@gmail.com) a écrit :

> You can but I'm not sure it will be as performat to do it.
> 
> You can try a field query where its like
> 
> +automated -to -be
> 
> and see if that works. The problem is that you are using the default mapping i assume and its going to tokenize those strings.
> 
> Thanks,
> 
> Shaun Farrell
> 
> On Thursday, July 5, 2012 at 1:49 PM, coys wrote:
> 
> > Hello, I would like to perform an exact match on a string - say for  
> > e.g. the field status which is an enum - taking 2 values  
> > ["Automated","To be Automated"].
> > 
> > When I query for status:"To be automated" I require that it return  
> > only those results where status is exactly "To be Automated" and not  
> > "Automated" and if I query for status:"Automated" I again require that  
> > it does not return to me the results where status is "To be  
> > Automated".
> > 
> > I read a previous question where it was suggested that I set index to  
> > not\_analyzed or keyword for the above field, but is there a way for me  
> > to get these results without doing the above..and just with the help  
> > of a query? Thanks!

---

<div class="post-metadata">

**Author:** ![coys](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@coys](https://discuss.elastic.co/u/coys)\
**Post date:** [July 5, 2012, 8:27pm UTC](https://discuss.elastic.co/t/exact-match-a-string/8332/4 "2012-07-05T20:27:48Z")

</div>

Yep David, you're right, looks I can't find those common words, so I  
guess I'll just go ahead and index that field as not\_analyzed. Thanks  
a lot for the replies guys!

---

<div class="post-metadata">

**Author:** ![coys](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@coys](https://discuss.elastic.co/u/coys)\
**Post date:** [July 5, 2012, 10:11pm UTC](https://discuss.elastic.co/t/exact-match-a-string/8332/5 "2012-07-05T22:11:25Z")

</div>

curl -XPUT '[http://localhost:9200/nameofindex/nameofmapping/\_mapping](http://localhost:9200/nameofindex/nameofmapping/_mapping)'  
-d '

> {  
> "typeofindex" : {  
> "properties" : {  
> "metadata.status" : {"type" : "string", "index" : "not\_analyzed"}  
> }  
> }  
> }  
> Just to update, I created this mapping and this worked for me. After  
> creating this mapping I can now differentiate between fields whose  
> status are Automated and To be Automated.

---

<div class="post-metadata">

**Author:** ![aps](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@aps](https://discuss.elastic.co/u/aps)\
**Post date:** [July 6, 2012, 8:32am UTC](https://discuss.elastic.co/t/exact-match-a-string/8332/6 "2012-07-06T08:32:10Z")

</div>

Are you getting documents when you search "auto" ? Because the problem with  
not\_analyzed is it do not search documents with matching type if few of the  
words is provided in search query.

On Friday, 6 July 2012 00:11:25 UTC+2, coys wrote:

> curl -XPUT '[http://localhost:9200/nameofindex/nameofmapping/\_mapping](http://localhost:9200/nameofindex/nameofmapping/_mapping)'  
> -d '
> 
> > {  
> > "typeofindex" : {  
> > "properties" : {  
> > "metadata.status" : {"type" : "string", "index" : "not\_analyzed"}  
> > }  
> > }  
> > }  
> > Just to update, I created this mapping and this worked for me. After  
> > creating this mapping I can now differentiate between fields whose  
> > status are Automated and To be Automated.

---

<div class="post-metadata">

**Author:** ![coys](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@coys](https://discuss.elastic.co/u/coys)\
**Post date:** [July 6, 2012, 5:20pm UTC](https://discuss.elastic.co/t/exact-match-a-string/8332/7 "2012-07-06T17:20:41Z")

</div>

I'll add in what I quickly tested..I have 2 docs..1 which has status  
"To be Automated" and 2 which has status "Automated"..search results  
are as follows - in my textbox if I type "To" or "To be" or "To be  
Automated" it returns 1 correctly..however if I type "Auto" or  
"Automated" it only returns doc 2 and does not return doc1..however, I  
only provide a comboxbox so I'm able to return the required doc  
according to status correctly. 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:21am UTC](https://discuss.elastic.co/t/exact-match-a-string/8332/8 "2017-07-06T03:21:13Z")

</div>


