# termQuery behavior with multiple words

**URL:** https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340
**Category:** Elasticsearch
**Created:** [January 10, 2012, 8:36pm UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340 "2012-01-10T20:36:21Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)
#### Post date: [January 10, 2012, 8:36pm UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340/1 "2012-01-10T20:36:21Z")

</div>

Suppose my user types in a search string with multiple words, like  
"yellow car".

I want to find all documents that have both words, not necessarily  
adjacent or in the same order, but not documents that contain only one  
of the words.

If I used something like termQuery("description", "yellow car"), what  
would this produce?

Do I need to parse the individual words out of the search string  
myself to accomplish what I want?

---

<div class="post-metadata">

### Author: ![plaflamme](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@plaflamme](https://discuss.elastic.co/u/plaflamme)
#### Post date: [January 10, 2012, 9:31pm UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340/2 "2012-01-10T21:31:30Z")

</div>

You're probably looking for this:

> **[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 this, to breakdown your query string before searching

> **[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're not familiar with Lucene, you may want to read about analyzers.  
They're the things that breakdown full text into indexable/searchable  
pieces.

Hope it helps,  
Philippe

On Tue, Jan 10, 2012 at 15:36, Frank LaRosa [frank@studyblue.com](mailto:frank@studyblue.com) wrote:

> Suppose my user types in a search string with multiple words, like  
> "yellow car".
> 
> I want to find all documents that have both words, not necessarily  
> adjacent or in the same order, but not documents that contain only one  
> of the words.
> 
> If I used something like termQuery("description", "yellow car"), what  
> would this produce?
> 
> Do I need to parse the individual words out of the search string  
> myself to accomplish what I want?

---

<div class="post-metadata">

### Author: ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)
#### Post date: [January 10, 2012, 9:36pm UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340/3 "2012-01-10T21:36:42Z")

</div>

I'm familiar with Solr. Can I just submit a Solr query string?

For example, when I'm using Solr I might submit a query such as  
"+description:yellow +description:car".

On Jan 10, 3:31 pm, Philippe Laflamme [philippe.lafla...@obiba.org](mailto:philippe.lafla...@obiba.org)  
wrote:

> You're probably looking for this:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)  
> or this, to breakdown your query string before searchinghttp://www.elasticsearch.org/guide/reference/api/admin-indices-analyz...
> 
> If you're not familiar with Lucene, you may want to read about analyzers.  
> They're the things that breakdown full text into indexable/searchable  
> pieces.
> 
> Hope it helps,  
> Philippe
> 
> On Tue, Jan 10, 2012 at 15:36, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) wrote:
> 
> > Suppose my user types in a search string with multiple words, like  
> > "yellow car".
> 
> > I want to find all documents that have both words, not necessarily  
> > adjacent or in the same order, but not documents that contain only one  
> > of the words.
> 
> > If I used something like termQuery("description", "yellow car"), what  
> > would this produce?
> 
> > Do I need to parse the individual words out of the search string  
> > myself to accomplish what I want?

---

<div class="post-metadata">

### Author: ![Frank\_LaRosa](https://avatars.discourse-cdn.com/v4/letter/f/bc8723/32.png) [@Frank\_LaRosa](https://discuss.elastic.co/u/Frank_LaRosa)
#### Post date: [January 10, 2012, 9:44pm UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340/4 "2012-01-10T21:44:42Z")

</div>

This is nice, but it's not Java. Isn't there a Java API for any of  
this stuff?

On Jan 10, 3:31 pm, Philippe Laflamme [philippe.lafla...@obiba.org](mailto:philippe.lafla...@obiba.org)  
wrote:

> You're probably looking for this:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)  
> or this, to breakdown your query string before searchinghttp://www.elasticsearch.org/guide/reference/api/admin-indices-analyz...
> 
> If you're not familiar with Lucene, you may want to read about analyzers.  
> They're the things that breakdown full text into indexable/searchable  
> pieces.
> 
> Hope it helps,  
> Philippe
> 
> On Tue, Jan 10, 2012 at 15:36, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) wrote:
> 
> > Suppose my user types in a search string with multiple words, like  
> > "yellow car".
> 
> > I want to find all documents that have both words, not necessarily  
> > adjacent or in the same order, but not documents that contain only one  
> > of the words.
> 
> > If I used something like termQuery("description", "yellow car"), what  
> > would this produce?
> 
> > Do I need to parse the individual words out of the search string  
> > myself to accomplish what I want?

---

<div class="post-metadata">

### Author: ![plaflamme](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@plaflamme](https://discuss.elastic.co/u/plaflamme)
#### Post date: [January 11, 2012, 1:25am UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340/5 "2012-01-11T01:25:03Z")

</div>

Yes, using this:

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

On Tue, Jan 10, 2012 at 16:36, Frank LaRosa [frank@studyblue.com](mailto:frank@studyblue.com) wrote:

> I'm familiar with Solr. Can I just submit a Solr query string?
> 
> For example, when I'm using Solr I might submit a query such as  
> "+description:yellow +description:car".
> 
> On Jan 10, 3:31 pm, Philippe Laflamme [philippe.lafla...@obiba.org](mailto:philippe.lafla...@obiba.org)  
> wrote:
> 
> > You're probably looking for this:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)  
> > or this, to breakdown your query string before searchinghttp://  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyz)...
> > 
> > If you're not familiar with Lucene, you may want to read about analyzers.  
> > They're the things that breakdown full text into indexable/searchable  
> > pieces.
> > 
> > Hope it helps,  
> > Philippe
> > 
> > On Tue, Jan 10, 2012 at 15:36, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) wrote:
> > 
> > > Suppose my user types in a search string with multiple words, like  
> > > "yellow car".
> > 
> > > I want to find all documents that have both words, not necessarily  
> > > adjacent or in the same order, but not documents that contain only one  
> > > of the words.
> > 
> > > If I used something like termQuery("description", "yellow car"), what  
> > > would this produce?
> > 
> > > Do I need to parse the individual words out of the search string  
> > > myself to accomplish what I want?

---

<div class="post-metadata">

### Author: ![plaflamme](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@plaflamme](https://discuss.elastic.co/u/plaflamme)
#### Post date: [January 11, 2012, 1:25am UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340/6 "2012-01-11T01:25:36Z")

</div>

Yes, there is. Look for SearchSourceBuilder to build search queries.

Philippe

On Tue, Jan 10, 2012 at 16:44, Frank LaRosa [frank@studyblue.com](mailto:frank@studyblue.com) wrote:

> This is nice, but it's not Java. Isn't there a Java API for any of  
> this stuff?
> 
> On Jan 10, 3:31 pm, Philippe Laflamme [philippe.lafla...@obiba.org](mailto:philippe.lafla...@obiba.org)  
> wrote:
> 
> > You're probably looking for this:
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)  
> > or this, to breakdown your query string before searchinghttp://  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyz)...
> > 
> > If you're not familiar with Lucene, you may want to read about analyzers.  
> > They're the things that breakdown full text into indexable/searchable  
> > pieces.
> > 
> > Hope it helps,  
> > Philippe
> > 
> > On Tue, Jan 10, 2012 at 15:36, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) wrote:
> > 
> > > Suppose my user types in a search string with multiple words, like  
> > > "yellow car".
> > 
> > > I want to find all documents that have both words, not necessarily  
> > > adjacent or in the same order, but not documents that contain only one  
> > > of the words.
> > 
> > > If I used something like termQuery("description", "yellow car"), what  
> > > would this produce?
> > 
> > > Do I need to parse the individual words out of the search string  
> > > myself to accomplish what I want?

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [January 11, 2012, 12:16pm UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340/7 "2012-01-11T12:16:43Z")

</div>

Have a look:

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

then pass this to the TransportClient

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

Peter.

On 11 Jan., 02:25, Philippe Laflamme [philippe.lafla...@obiba.org](mailto:philippe.lafla...@obiba.org)  
wrote:

> Yes, there is. Look for SearchSourceBuilder to build search queries.
> 
> Philippe
> 
> On Tue, Jan 10, 2012 at 16:44, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) wrote:
> 
> > This is nice, but it's not Java. Isn't there a Java API for any of  
> > this stuff?
> 
> > On Jan 10, 3:31 pm, Philippe Laflamme [philippe.lafla...@obiba.org](mailto:philippe.lafla...@obiba.org)  
> > wrote:
> > 
> > > You're probably looking for this:
> 
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-query.html)  
> > > or this, to breakdown your query string before searchinghttp://  
> > > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-analyz)...
> 
> > > If you're not familiar with Lucene, you may want to read about analyzers.  
> > > They're the things that breakdown full text into indexable/searchable  
> > > pieces.
> 
> > > Hope it helps,  
> > > Philippe
> 
> > > On Tue, Jan 10, 2012 at 15:36, Frank LaRosa [fr...@studyblue.com](mailto:fr...@studyblue.com) wrote:
> > > 
> > > > Suppose my user types in a search string with multiple words, like  
> > > > "yellow car".
> 
> > > > I want to find all documents that have both words, not necessarily  
> > > > adjacent or in the same order, but not documents that contain only one  
> > > > of the words.
> 
> > > > If I used something like termQuery("description", "yellow car"), what  
> > > > would this produce?
> 
> > > > Do I need to parse the individual words out of the search string  
> > > > myself to accomplish what I want?

---

<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:43am UTC](https://discuss.elastic.co/t/termquery-behavior-with-multiple-words/6340/8 "2017-07-06T03:43:09Z")

</div>


