# Exact Match in String field

**URL:** <https://discuss.elastic.co/t/exact-match-in-string-field/9560>\
**Category:** Elasticsearch\
**Created:** [November 5, 2012, 3:26pm UTC](https://discuss.elastic.co/t/exact-match-in-string-field/9560 "2012-11-05T15:26:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shannu](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@shannu](https://discuss.elastic.co/u/shannu)\
**Post date:** [November 5, 2012, 3:26pm UTC](https://discuss.elastic.co/t/exact-match-in-string-field/9560/1 "2012-11-05T15:26:29Z")

</div>

Hello All,

I would like to perform EXACT Match (Example Search : "Firstname Lastname")  
in a String field "ArticleBody" where the _value of the field is a big  
chunk of text_ and within in this text I would like to perform the exact  
match.

I came across couple of links:

[http://paulsabou.com/blog/2012/03/25/advanced-exact-matching-with-elastic-search/](http://paulsabou.com/blog/2012/03/25/advanced-exact-matching-with-elastic-search/)  
[http://gauth.fr/2012/08/exact-search-with-elasticsearch/](http://gauth.fr/2012/08/exact-search-with-elasticsearch/)

which explains that if we change the mapping of the filed to  
"not\_analyzed", then the entire field value will be considered as one  
string and I understand that this will only work where the field values are  
2-3 words and wanted to be considered as one single term.

But in my case the Field "ArticleBody" will contain a very big chunk of  
text(I dont want to treat the entire body of the article as single string)  
and would like to find specific keywords(like: "Elastic Search", "Firstname  
Lastname") within this text.

Can this be done ? Please shed some light on this.

Many thanks in advance,  
Shannu.

--

---

<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 5, 2012, 5:21pm UTC](https://discuss.elastic.co/t/exact-match-in-string-field/9560/2 "2012-11-05T17:21:17Z")

</div>

There are a few ways to achieve what you want.

First of all, all the concepts related to search stem from Lucene. You can  
learn more about searching in Elasticsearch, but reading about Lucene.

Second, is case important to you? Your goal is to create an analyzer that  
creates tokens that helps you achieve your queries. This could entail not  
lowercasing, stemming, and removing stop words.

Easiest way is using phrase queries:  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html) Make  
sure you use a correct analyzer.

You can also using span queries with a slop of 0:

> **[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.

--  
Ivan

On Mon, Nov 5, 2012 at 7:26 AM, shannu [shanmukhaveeranki@gmail.com](mailto:shanmukhaveeranki@gmail.com) wrote:

> Hello All,
> 
> I would like to perform EXACT Match (Example Search : "Firstname  
> Lastname") in a String field "ArticleBody" where the _value of the field  
> is a big chunk of text_ and within in this text I would like to perform  
> the exact match.
> 
> I came across couple of links:
> 
> [http://paulsabou.com/blog/2012/03/25/advanced-exact-matching-with-elastic-search/](http://paulsabou.com/blog/2012/03/25/advanced-exact-matching-with-elastic-search/)  
> [http://gauth.fr/2012/08/exact-search-with-elasticsearch/](http://gauth.fr/2012/08/exact-search-with-elasticsearch/)
> 
> which explains that if we change the mapping of the filed to  
> "not\_analyzed", then the entire field value will be considered as one  
> string and I understand that this will only work where the field values are  
> 2-3 words and wanted to be considered as one single term.
> 
> But in my case the Field "ArticleBody" will contain a very big chunk of  
> text(I dont want to treat the entire body of the article as single string)  
> and would like to find specific keywords(like: "Elastic Search", "Firstname  
> Lastname") within this text.
> 
> Can this be done ? Please shed some light on this.
> 
> Many thanks in advance,  
> Shannu.
> 
> --

--

---

<div class="post-metadata">

**Author:** ![shannu](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@shannu](https://discuss.elastic.co/u/shannu)\
**Post date:** [November 6, 2012, 9:43am UTC](https://discuss.elastic.co/t/exact-match-in-string-field/9560/3 "2012-11-06T09:43:39Z")

</div>

Hey Ivan,

Thanks a lot for the reply and very good information.

Regards,  
Shannu.

On Monday, November 5, 2012 5:21:20 PM UTC, Ivan Brusic wrote:

> There are a few ways to achieve what you want.
> 
> First of all, all the concepts related to search stem from Lucene. You can  
> learn more about searching in Elasticsearch, but reading about Lucene.
> 
> Second, is case important to you? Your goal is to create an analyzer that  
> creates tokens that helps you achieve your queries. This could entail not  
> lowercasing, stemming, and removing stop words.
> 
> Easiest way is using phrase queries:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/match-query.html) Make  
> sure you use a correct analyzer.
> 
> You can also using span queries with a slop of 0:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/span-near-query.html)
> 
> --  
> Ivan
> 
> On Mon, Nov 5, 2012 at 7:26 AM, shannu \<[shanmukh...@gmail.com](mailto:shanmukh...@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > Hello All,
> > 
> > I would like to perform EXACT Match (Example Search : "Firstname  
> > Lastname") in a String field "ArticleBody" where the _value of the field  
> > is a big chunk of text_ and within in this text I would like to perform  
> > the exact match.
> > 
> > I came across couple of links:
> > 
> > [http://paulsabou.com/blog/2012/03/25/advanced-exact-matching-with-elastic-search/](http://paulsabou.com/blog/2012/03/25/advanced-exact-matching-with-elastic-search/)  
> > [http://gauth.fr/2012/08/exact-search-with-elasticsearch/](http://gauth.fr/2012/08/exact-search-with-elasticsearch/)
> > 
> > which explains that if we change the mapping of the filed to  
> > "not\_analyzed", then the entire field value will be considered as one  
> > string and I understand that this will only work where the field values are  
> > 2-3 words and wanted to be considered as one single term.
> > 
> > But in my case the Field "ArticleBody" will contain a very big chunk of  
> > text(I dont want to treat the entire body of the article as single string)  
> > and would like to find specific keywords(like: "Elastic Search", "Firstname  
> > Lastname") within this text.
> > 
> > Can this be done ? Please shed some light on this.
> > 
> > Many thanks in advance,  
> > Shannu.
> > 
> > --

--

---

<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:06am UTC](https://discuss.elastic.co/t/exact-match-in-string-field/9560/4 "2017-07-06T03:06:02Z")

</div>


