# Searching terms

**URL:** <https://discuss.elastic.co/t/searching-terms/7096>\
**Category:** Elasticsearch\
**Created:** [March 22, 2012, 1:41pm UTC](https://discuss.elastic.co/t/searching-terms/7096 "2012-03-22T13:41:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [March 22, 2012, 1:41pm UTC](https://discuss.elastic.co/t/searching-terms/7096/1 "2012-03-22T13:41:20Z")

</div>

Hi,

I have a following question. Is it possible for Elasticsearch to index text  
fields to allow searching complex terms like 'how are you'? I would like to  
find documents with fields containing exact term 'how are you', not only  
words 'how', 'are' and 'you'. How should I index such fields to allow  
searching like this, and how should I build such a request?

Thanks for help.

Best regards.  
Marcin.

---

<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:** [March 22, 2012, 1:51pm UTC](https://discuss.elastic.co/t/searching-terms/7096/2 "2012-03-22T13:51:02Z")

</div>

You can define a keyword mapping. ES won't touch what you index.  
Or you can define to use a AND operator instead of OR (default) in your  
query  
Or you can use lucene syntax to query on +how +are +you

I think that there are many other ways to do it...

HTH  
David.

Le 22 mars 2012 à 14:41, Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com) a écrit :

> I have a following question. Is it possible for Elasticsearch to index text  
> fields to allow searching complex terms like 'how are you'? I would like to  
> find documents with fields containing exact term 'how are you', not only  
> words 'how', 'are' and 'you'. How should I index such fields to allow  
> searching like this, and how should I build such a request?
> 
> Thanks for help.
> 
> Best regards.  
> Marcin.

--  
David Pilato  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [March 22, 2012, 2:26pm UTC](https://discuss.elastic.co/t/searching-terms/7096/3 "2012-03-22T14:26:53Z")

</div>

Hi thanks, but I think you misunderstood me. As I understand your examples  
will find all the documents with fields containing all of the given words  
'how', 'are' and 'you', so the matching fields would be:

1. How are you today?
2. How something you anything are something else.
3. ...

right ?

But I want to find the fields that contains exactly 'how are you' so the  
matching 1 from above would be the only correct match.

Best regards.

2012/3/22 [david@pilato.fr](mailto:david@pilato.fr) [david@pilato.fr](mailto:david@pilato.fr)

> \*\*
> 
> You can define a keyword mapping. ES won't touch what you index.
> 
> Or you can define to use a AND operator instead of OR (default) in your  
> query
> 
> Or you can use lucene syntax to query on +how +are +you
> 
> I think that there are many other ways to do it...
> 
> HTH
> 
> David.
> 
> Le 22 mars 2012 à 14:41, Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com) a écrit :
> 
> Hi,
> 
> I have a following question. Is it possible for Elasticsearch to index  
> text fields to allow searching complex terms like 'how are you'? I would  
> like to find documents with fields containing exact term 'how are you', not  
> only words 'how', 'are' and 'you'. How should I index such fields to allow  
> searching like this, and how should I build such a request?
> 
> Thanks for help.
> 
> Best regards.  
> Marcin.
> 
> --  
> David Pilato  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet

---

<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:** [March 22, 2012, 2:36pm UTC](https://discuss.elastic.co/t/searching-terms/7096/4 "2012-03-22T14:36:07Z")

</div>

So you want ES to index field without tokenizing its content.  
A keyword analyzer will do it. By default, ES use the standard analyzer.

That's the first proposal I wrote.

You have to define it at index time. If ES has already tokenized the field, you won't be able to search exact sentence.

Does it answer to your needs ?

David 😉  
Twitter : @dadoonet / @elasticsearchfr

Le 22 mars 2012 à 15:26, Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com) a écrit :

> Hi thanks, but I think you misunderstood me. As I understand your examples will find all the documents with fields containing all of the given words 'how', 'are' and 'you', so the matching fields would be:
> 
> 1. How are you today?
> 2. How something you anything are something else.
> 3. ...
> 
> right ?
> 
> But I want to find the fields that contains exactly 'how are you' so the matching 1 from above would be the only correct match.
> 
> Best regards.
> 
> 2012/3/22 [david@pilato.fr](mailto:david@pilato.fr) [david@pilato.fr](mailto:david@pilato.fr)  
> You can define a keyword mapping. ES won't touch what you index.  
> Or you can define to use a AND operator instead of OR (default) in your query  
> Or you can use lucene syntax to query on +how +are +you
> 
> I think that there are many other ways to do it...
> 
> HTH  
> David.
> 
> Le 22 mars 2012 à 14:41, Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com) a écrit :
> 
> Hi,
> 
> I have a following question. Is it possible for Elasticsearch to index text fields to allow searching complex terms like 'how are you'? I would like to find documents with fields containing exact term 'how are you', not only words 'how', 'are' and 'you'. How should I index such fields to allow searching like this, and how should I build such a request?
> 
> Thanks for help.
> 
> Best regards.  
> Marcin.
> 
> --  
> David Pilato  
> [http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
> Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 22, 2012, 2:41pm UTC](https://discuss.elastic.co/t/searching-terms/7096/5 "2012-03-22T14:41:33Z")

</div>

On Thu, 2012-03-22 at 15:36 +0100, David Pilato wrote:

> So you want ES to index field without tokenizing its content.  
> A keyword analyzer will do it. By default, ES use the standard  
> analyzer.

> That's the first proposal I wrote.

> You have to define it at index time. If ES has already tokenized the  
> field, you won't be able to search exact sentence.

I think he is asking about a phrase search, in which case the  
'text\_phrase' query or a query\_string query would work

clint

> Does it answer to your needs ?
> 
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr
> 
> Le 22 mars 2012 Ã 15:26, Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com) a  
> Ã©crit :
> 
> > Hi thanks, but I think you misunderstood me. As I understand your  
> > examples will find all the documents with fields containing all of  
> > the given words 'how', 'are' and 'you', so the matching fields would  
> > be:
> > 
> > 1. How are you today?
> > 2. How something you anything are something else.
> > 3. ...
> > 
> > right ?
> > 
> > But I want to find the fields that contains exactly 'how are you' so  
> > the matching 1 from above would be the only correct match.
> > 
> > Best regards.
> > 
> > 2012/3/22 [david@pilato.fr](mailto:david@pilato.fr) [david@pilato.fr](mailto:david@pilato.fr)  
> > You can define a keyword mapping. ES won't touch what you  
> > index.
> > 
> > ```
> > Or you can define to use a AND operator instead of OR
> > (default) in your query 
> >     
> > Or you can use lucene syntax to query on +how +are +you 
> >     
> >     
> > I think that there are many other ways to do it... 
> >     
> >     
> > HTH 
> >     
> > David. 
> >     
> >     
> >     
> > Le 22 mars 2012 Ã 14:41, Marcin Dojwa
> > <m.dojwa@livechatinc.com> a Ã©crit : 
> >     
> > Hi, 
> >              
> > I have a following question. Is it possible for
> > Elasticsearch to index text fields to allow
> > searching complex terms like 'how are you'? I would
> > like to find documents with fields containing exact
> > term 'how are you', not only words 'how', 'are' and
> > 'you'. How should I index such fields to allow
> > searching like this, and how should I build such a
> > request?
> >              
> > Thanks for help.
> >              
> > Best regards.
> > Marcin.
> >     
> >       
> >     
> > -- 
> > David Pilato 
> > http://dev.david.pilato.fr/ 
> > Twitter : @dadoonet 
> > 
> > ```

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [March 22, 2012, 3:47pm UTC](https://discuss.elastic.co/t/searching-terms/7096/6 "2012-03-22T15:47:35Z")

</div>

Yes, I meant the phrase search 🙂 Thank you all for help, that's great that  
it is possible 🙂 I will check this as soon as possible.

Best regards.

W dniu czwartek, 22 marca 2012 użytkownik Clinton Gormley \<  
[clint@traveljury.com](mailto:clint@traveljury.com)\> napisał:

> On Thu, 2012-03-22 at 15:36 +0100, David Pilato wrote:
> 
> > So you want ES to index field without tokenizing its content.  
> > A keyword analyzer will do it. By default, ES use the standard  
> > analyzer.
> 
> > That's the first proposal I wrote.
> 
> > You have to define it at index time. If ES has already tokenized the  
> > field, you won't be able to search exact sentence.
> 
> I think he is asking about a phrase search, in which case the  
> 'text\_phrase' query or a query\_string query would work
> 
> clint
> 
> > Does it answer to your needs ?
> > 
> > David 😉  
> > Twitter : @dadoonet / @elasticsearchfr
> > 
> > Le 22 mars 2012 à 15:26, Marcin Dojwa [m.dojwa@livechatinc.com](mailto:m.dojwa@livechatinc.com) a  
> > écrit :
> > 
> > > Hi thanks, but I think you misunderstood me. As I understand your  
> > > examples will find all the documents with fields containing all of  
> > > the given words 'how', 'are' and 'you', so the matching fields would  
> > > be:
> > > 
> > > 1. How are you today?
> > > 2. How something you anything are something else.
> > > 3. ...
> > > 
> > > right ?
> > > 
> > > But I want to find the fields that contains exactly 'how are you' so  
> > > the matching 1 from above would be the only correct match.
> > > 
> > > Best regards.
> > > 
> > > 2012/3/22 [david@pilato.fr](mailto:david@pilato.fr) [david@pilato.fr](mailto:david@pilato.fr)  
> > > You can define a keyword mapping. ES won't touch what you  
> > > index.
> > > 
> > > ```
> > > Or you can define to use a AND operator instead of OR
> > > (default) in your query
> > > 
> > > Or you can use lucene syntax to query on +how +are +you
> > > 
> > > I think that there are many other ways to do it...
> > > 
> > > HTH
> > > 
> > > David.
> > > 
> > > Le 22 mars 2012 à 14:41, Marcin Dojwa
> > > <m.dojwa@livechatinc.com> a écrit :
> > > 
> > > Hi,
> > > 
> > > I have a following question. Is it possible for
> > > Elasticsearch to index text fields to allow
> > > searching complex terms like 'how are you'? I would
> > > like to find documents with fields containing exact
> > > term 'how are you', not only words 'how', 'are' and
> > > 'you'. How should I index such fields to allow
> > > searching like this, and how should I build such a
> > > request?
> > > 
> > > Thanks for help.
> > > 
> > > Best regards.
> > > Marcin.
> > > 
> > > --
> > > David Pilato
> > > http://dev.david.pilato.fr/
> > > Twitter : @dadoonet
> > > 
> > > ```

---

<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:** [March 22, 2012, 4:19pm UTC](https://discuss.elastic.co/t/searching-terms/7096/7 "2012-03-22T16:19:55Z")

</div>

> I think he is asking about a phrase search, in which case the  
> 'text\_phrase' query or a query\_string query would work

Thanks Clint.

I was not aware of it.

David.

---

<div class="post-metadata">

**Author:** ![Marcin\_Dojwa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcin_dojwa/32/2307_2.png) [@Marcin\_Dojwa](https://discuss.elastic.co/u/Marcin_Dojwa)\
**Post date:** [March 22, 2012, 6:02pm UTC](https://discuss.elastic.co/t/searching-terms/7096/8 "2012-03-22T18:02:34Z")

</div>

'text\_phrase' works perfect, thank you very much.

Best regards.  
Marcin.

2012/3/22 [david@pilato.fr](mailto:david@pilato.fr) [david@pilato.fr](mailto:david@pilato.fr)

> \*\*
> 
> > I think he is asking about a phrase search, in which case the
> 
> > 'text\_phrase' query or a query\_string query would work
> 
> Thanks Clint.
> 
> I was not aware of it.
> 
> David.

---

<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:35am UTC](https://discuss.elastic.co/t/searching-terms/7096/9 "2017-07-06T03:35:08Z")

</div>


