# Search string with space

**URL:** <https://discuss.elastic.co/t/search-string-with-space/5068>\
**Category:** Elasticsearch\
**Created:** [August 5, 2011, 2:09pm UTC](https://discuss.elastic.co/t/search-string-with-space/5068 "2011-08-05T14:09:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ElasticUser](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@ElasticUser](https://discuss.elastic.co/u/ElasticUser)\
**Post date:** [August 5, 2011, 2:09pm UTC](https://discuss.elastic.co/t/search-string-with-space/5068/1 "2011-08-05T14:09:07Z")

</div>

In my raw message, I have apache directory text. I am using term query as below  
.setQuery(termQuery("message", ""apache directory""))  
But get 0 hits.  
Can someone let me know the API for matching strings separated by space? Please suggest....need solution urgently. 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:** [August 6, 2011, 6:41pm UTC](https://discuss.elastic.co/t/search-string-with-space/5068/2 "2011-08-06T18:41:57Z")

</div>

You have to change your analyzer for this field.  
By default, strings are tokenized into terms.

David 😉

Le 5 août 2011 à 16:09, ElasticUser [lkodwaney@gmail.com](mailto:lkodwaney@gmail.com) a écrit :

> In my raw message, I have apache directory text. I am using term query as  
> below  
> .setQuery(termQuery("message", ""apache directory""))  
> But get 0 hits.  
> Can someone let me know the API for matching strings separated by space?  
> Please suggest....need solution urgently. Thanks
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/search-string-with-space-tp3228790p3228790.html](http://elasticsearch-users.115913.n3.nabble.com/search-string-with-space-tp3228790p3228790.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [August 6, 2011, 7:29pm UTC](https://discuss.elastic.co/t/search-string-with-space/5068/3 "2011-08-06T19:29:36Z")

</div>

Or you can use a different query type to do a phrase search. I know  
query string query will work:

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

or a text phrase query should work:

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

Best Regards,  
Paul

On Aug 6, 12:41 pm, David Pilato [da...@pilato.fr](mailto:da...@pilato.fr) wrote:

> You have to change your analyzer for this field.  
> By default, strings are tokenized into terms.
> 
> David 😉
> 
> Le 5 août 2011 à 16:09, ElasticUser [lkodwa...@gmail.com](mailto:lkodwa...@gmail.com) a écrit :
> 
> > In my raw message, I have apache directory text. I am using term query as  
> > below  
> > .setQuery(termQuery("message", ""apache directory""))  
> > But get 0 hits.  
> > Can someone let me know the API for matching strings separated by space?  
> > Please suggest....need solution urgently. Thanks
> 
> > --  
> > View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/search-string-with-sp](http://elasticsearch-users.115913.n3.nabble.com/search-string-with-sp)...  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:58am UTC](https://discuss.elastic.co/t/search-string-with-space/5068/4 "2017-07-06T03:58:02Z")

</div>


