# (Newbie) Differences between text and field/query\_string, and matching words vs phrases

**URL:** <https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748>\
**Category:** Elasticsearch\
**Created:** [February 19, 2012, 5:28pm UTC](https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748 "2012-02-19T17:28:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Dunn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_dunn/32/2315_2.png) [@Nick\_Dunn](https://discuss.elastic.co/u/Nick_Dunn)\
**Post date:** [February 19, 2012, 5:28pm UTC](https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748/1 "2012-02-19T17:28:36Z")

</div>

Hello all. I'm very new to ES and Lucene, but I have spent a lot of  
time devouring the documentation, this group and Stack Overflow.  
However I've yet to find a definitive answer to my, hopefully simple,  
question.

I'm indexing several types (books, authors, publishers and a few  
others) which in the first instance I would like searchable from a  
single text input. I understand from the docs that the text query  
([http://www.elasticsearch.org/guide/reference/query-dsl/text-](http://www.elasticsearch.org/guide/reference/query-dsl/text-)  
query.html) is designed for this out of the box "one size fits all"  
requirement. However I would also like to support a basic search  
syntax of:

- have each keyword as optional (OR), which the default operator for a  
text query uses (tick!)
- allow for a keyword to be prefixed with + or - to include/preclude  
it from the search (which is supported by the query\_string query  
type... tick!)
- allow for phrases by wrapping these in double quotes, so these  
become required phrases (e.g. "lorem ipsum" is essentially +"lorem  
ipsum")

In all instances I want to search "\_all" for the time being.

After some playing with the various query types, it seems that the  
text type offers good out of the box functionality, but the field/  
query\_string type offers the +/- syntax. But am I correct in saying  
neither offer the phrase/double quotes syntax?

Having used elasticsearch-head to visually compile some queries, I am  
wondering whether the above can only be implemented with some pre-  
processing my end before sending the query to ES. I could use a  
boolean query and then process in incoming query string to parse out  
the +/- and phrases to build the must/should/must\_not parts of the  
boolean query myself.

I had hoped that I could simply throw this at ES verbatim, but will I  
need to add my own layer of string parsing first?

Any direction greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Nick\_Dunn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_dunn/32/2315_2.png) [@Nick\_Dunn](https://discuss.elastic.co/u/Nick_Dunn)\
**Post date:** [February 19, 2012, 5:36pm UTC](https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748/2 "2012-02-19T17:36:56Z")

</div>

To elaborate a little more. Let's say my query input was:

"lord of the rings" tolkien -hobbit

I would hope it to be interpreted something like this... but without  
me having to end the boolean query explicitly.

> <https://gist.github.com/nickdunn/1864764>

I hope I'm explaining myself properly.

On Feb 19, 5:28 pm, Nick Dunn [n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) wrote:

> Hello all. I'm very new to ES and Lucene, but I have spent a lot of  
> time devouring the documentation, this group and Stack Overflow.  
> However I've yet to find a definitive answer to my, hopefully simple,  
> question.
> 
> I'm indexing several types (books, authors, publishers and a few  
> others) which in the first instance I would like searchable from a  
> single text input. I understand from the docs that the text query  
> ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-)  
> query.html) is designed for this out of the box "one size fits all"  
> requirement. However I would also like to support a basic search  
> syntax of:
> 
> - have each keyword as optional (OR), which the default operator for a  
> text query uses (tick!)
> - allow for a keyword to be prefixed with + or - to include/preclude  
> it from the search (which is supported by the query\_string query  
> type... tick!)
> - allow for phrases by wrapping these in double quotes, so these  
> become required phrases (e.g. "lorem ipsum" is essentially +"lorem  
> ipsum")
> 
> In all instances I want to search "\_all" for the time being.
> 
> After some playing with the various query types, it seems that the  
> text type offers good out of the box functionality, but the field/  
> query\_string type offers the +/- syntax. But am I correct in saying  
> neither offer the phrase/double quotes syntax?
> 
> Having used elasticsearch-head to visually compile some queries, I am  
> wondering whether the above can only be implemented with some pre-  
> processing my end before sending the query to ES. I could use a  
> boolean query and then process in incoming query string to parse out  
> the +/- and phrases to build the must/should/must\_not parts of the  
> boolean query myself.
> 
> I had hoped that I could simply throw this at ES verbatim, but will I  
> need to add my own layer of string parsing first?
> 
> Any direction greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Nick\_Dunn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_dunn/32/2315_2.png) [@Nick\_Dunn](https://discuss.elastic.co/u/Nick_Dunn)\
**Post date:** [February 19, 2012, 5:53pm UTC](https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748/3 "2012-02-19T17:53:22Z")

</div>

And please, if you don't think this level of complexity is necessary,  
by all means just tell me to use a query\_string search and nothing  
more 😉

On Feb 19, 5:36 pm, Nick Dunn [n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) wrote:

> To elaborate a little more. Let's say my query input was:
> 
> "lord of the rings" tolkien -hobbit
> 
> I would hope it to be interpreted something like this... but without  
> me having to end the boolean query explicitly.
> 
> [gist:1864764 · GitHub](https://gist.github.com/1864764)
> 
> I hope I'm explaining myself properly.
> 
> On Feb 19, 5:28 pm, Nick Dunn [n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) wrote:
> 
> > Hello all. I'm very new to ES and Lucene, but I have spent a lot of  
> > time devouring the documentation, this group and Stack Overflow.  
> > However I've yet to find a definitive answer to my, hopefully simple,  
> > question.
> 
> > I'm indexing several types (books, authors, publishers and a few  
> > others) which in the first instance I would like searchable from a  
> > single text input. I understand from the docs that the text query  
> > ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-)  
> > query.html) is designed for this out of the box "one size fits all"  
> > requirement. However I would also like to support a basic search  
> > syntax of:
> 
> > - have each keyword as optional (OR), which the default operator for a  
> > text query uses (tick!)
> > - allow for a keyword to be prefixed with + or - to include/preclude  
> > it from the search (which is supported by the query\_string query  
> > type... tick!)
> > - allow for phrases by wrapping these in double quotes, so these  
> > become required phrases (e.g. "lorem ipsum" is essentially +"lorem  
> > ipsum")
> 
> > In all instances I want to search "\_all" for the time being.
> 
> > After some playing with the various query types, it seems that the  
> > text type offers good out of the box functionality, but the field/  
> > query\_string type offers the +/- syntax. But am I correct in saying  
> > neither offer the phrase/double quotes syntax?
> 
> > Having used elasticsearch-head to visually compile some queries, I am  
> > wondering whether the above can only be implemented with some pre-  
> > processing my end before sending the query to ES. I could use a  
> > boolean query and then process in incoming query string to parse out  
> > the +/- and phrases to build the must/should/must\_not parts of the  
> > boolean query myself.
> 
> > I had hoped that I could simply throw this at ES verbatim, but will I  
> > need to add my own layer of string parsing first?
> 
> > Any direction greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [February 20, 2012, 12:17am UTC](https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748/4 "2012-02-20T00:17:34Z")

</div>

Hi,

I would use query\_string

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

it supports all the three requirements stated in your first mail.

Regards,  
Lukas

On Sun, Feb 19, 2012 at 6:53 PM, Nick Dunn [nick@nick-dunn.co.uk](mailto:nick@nick-dunn.co.uk) wrote:

> And please, if you don't think this level of complexity is necessary,  
> by all means just tell me to use a query\_string search and nothing  
> more 😉
> 
> On Feb 19, 5:36 pm, Nick Dunn [n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) wrote:
> 
> > To elaborate a little more. Let's say my query input was:
> > 
> > "lord of the rings" tolkien -hobbit
> > 
> > I would hope it to be interpreted something like this... but without  
> > me having to end the boolean query explicitly.
> > 
> > [gist:1864764 · GitHub](https://gist.github.com/1864764)
> > 
> > I hope I'm explaining myself properly.
> > 
> > On Feb 19, 5:28 pm, Nick Dunn [n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) wrote:
> > 
> > > Hello all. I'm very new to ES and Lucene, but I have spent a lot of  
> > > time devouring the documentation, this group and Stack Overflow.  
> > > However I've yet to find a definitive answer to my, hopefully simple,  
> > > question.
> > 
> > > I'm indexing several types (books, authors, publishers and a few  
> > > others) which in the first instance I would like searchable from a  
> > > single text input. I understand from the docs that the text query  
> > > ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-)  
> > > query.html) is designed for this out of the box "one size fits all"  
> > > requirement. However I would also like to support a basic search  
> > > syntax of:
> > 
> > > - have each keyword as optional (OR), which the default operator for a  
> > > text query uses (tick!)
> > > - allow for a keyword to be prefixed with + or - to include/preclude  
> > > it from the search (which is supported by the query\_string query  
> > > type... tick!)
> > > - allow for phrases by wrapping these in double quotes, so these  
> > > become required phrases (e.g. "lorem ipsum" is essentially +"lorem  
> > > ipsum")
> > 
> > > In all instances I want to search "\_all" for the time being.
> > 
> > > After some playing with the various query types, it seems that the  
> > > text type offers good out of the box functionality, but the field/  
> > > query\_string type offers the +/- syntax. But am I correct in saying  
> > > neither offer the phrase/double quotes syntax?
> > 
> > > Having used elasticsearch-head to visually compile some queries, I am  
> > > wondering whether the above can only be implemented with some pre-  
> > > processing my end before sending the query to ES. I could use a  
> > > boolean query and then process in incoming query string to parse out  
> > > the +/- and phrases to build the must/should/must\_not parts of the  
> > > boolean query myself.
> > 
> > > I had hoped that I could simply throw this at ES verbatim, but will I  
> > > need to add my own layer of string parsing first?
> > 
> > > Any direction greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Nick\_Dunn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nick_dunn/32/2315_2.png) [@Nick\_Dunn](https://discuss.elastic.co/u/Nick_Dunn)\
**Post date:** [February 20, 2012, 10:30am UTC](https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748/5 "2012-02-20T10:30:50Z")

</div>

Thanks, Lukas. Digging around some more you are quite right, my  
requirements are met. The ES docs aren't explicit about the phrase  
(double quotes) matching, but this works nicely. Cheers!

On Feb 20, 12:17 am, Lukáš Vlček [lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) wrote:

> Hi,
> 
> I would use query\_stringhttp://www.elasticsearch.org/guide/reference/query-dsl/query-string-q...  
> it supports all the three requirements stated in your first mail.
> 
> Regards,  
> Lukas
> 
> On Sun, Feb 19, 2012 at 6:53 PM, Nick Dunn [n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) wrote:
> 
> > And please, if you don't think this level of complexity is necessary,  
> > by all means just tell me to use a query\_string search and nothing  
> > more 😉
> 
> > On Feb 19, 5:36 pm, Nick Dunn [n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) wrote:
> > 
> > > To elaborate a little more. Let's say my query input was:
> 
> > > "lord of the rings" tolkien -hobbit
> 
> > > I would hope it to be interpreted something like this... but without  
> > > me having to end the boolean query explicitly.
> 
> > > [gist:1864764 · GitHub](https://gist.github.com/1864764)
> 
> > > I hope I'm explaining myself properly.
> 
> > > On Feb 19, 5:28 pm, Nick Dunn [n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) wrote:
> 
> > > > Hello all. I'm very new to ES and Lucene, but I have spent a lot of  
> > > > time devouring the documentation, this group and Stack Overflow.  
> > > > However I've yet to find a definitive answer to my, hopefully simple,  
> > > > question.
> 
> > > > I'm indexing several types (books, authors, publishers and a few  
> > > > others) which in the first instance I would like searchable from a  
> > > > single text input. I understand from the docs that the text query  
> > > > ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-)  
> > > > query.html) is designed for this out of the box "one size fits all"  
> > > > requirement. However I would also like to support a basic search  
> > > > syntax of:
> 
> > > > - have each keyword as optional (OR), which the default operator for a  
> > > > text query uses (tick!)
> > > > - allow for a keyword to be prefixed with + or - to include/preclude  
> > > > it from the search (which is supported by the query\_string query  
> > > > type... tick!)
> > > > - allow for phrases by wrapping these in double quotes, so these  
> > > > become required phrases (e.g. "lorem ipsum" is essentially +"lorem  
> > > > ipsum")
> 
> > > > In all instances I want to search "\_all" for the time being.
> 
> > > > After some playing with the various query types, it seems that the  
> > > > text type offers good out of the box functionality, but the field/  
> > > > query\_string type offers the +/- syntax. But am I correct in saying  
> > > > neither offer the phrase/double quotes syntax?
> 
> > > > Having used elasticsearch-head to visually compile some queries, I am  
> > > > wondering whether the above can only be implemented with some pre-  
> > > > processing my end before sending the query to ES. I could use a  
> > > > boolean query and then process in incoming query string to parse out  
> > > > the +/- and phrases to build the must/should/must\_not parts of the  
> > > > boolean query myself.
> 
> > > > I had hoped that I could simply throw this at ES verbatim, but will I  
> > > > need to add my own layer of string parsing first?
> 
> > > > Any direction greatly appreciated.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [February 20, 2012, 1:25pm UTC](https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748/6 "2012-02-20T13:25:54Z")

</div>

The field/query\_string option provides the query syntax that you are after, text just analyzes the text you provide, without understanding specify syntax. field/query\_string does support phrase searches by wrapping text in ".

On Monday, February 20, 2012 at 12:30 PM, Nick Dunn wrote:

> Thanks, Lukas. Digging around some more you are quite right, my  
> requirements are met. The ES docs aren't explicit about the phrase  
> (double quotes) matching, but this works nicely. Cheers!
> 
> On Feb 20, 12:17 am, Lukáš Vlček \<[lukas.vl...@gmail.com](mailto:lukas.vl...@gmail.com) ([http://gmail.com](http://gmail.com))\> wrote:
> 
> > Hi,
> > 
> > I would use query\_stringhttp://www.elasticsearch.org/guide/reference/query-dsl/query-string-q...  
> > it supports all the three requirements stated in your first mail.
> > 
> > Regards,  
> > Lukas
> > 
> > On Sun, Feb 19, 2012 at 6:53 PM, Nick Dunn \<[n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) ([http://nick-dunn.co.uk](http://nick-dunn.co.uk))\> wrote:
> > 
> > > And please, if you don't think this level of complexity is necessary,  
> > > by all means just tell me to use a query\_string search and nothing  
> > > more 😉
> > 
> > > On Feb 19, 5:36 pm, Nick Dunn \<[n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) ([http://nick-dunn.co.uk](http://nick-dunn.co.uk))\> wrote:
> > > 
> > > > To elaborate a little more. Let's say my query input was:
> > 
> > > > "lord of the rings" tolkien -hobbit
> > 
> > > > I would hope it to be interpreted something like this... but without  
> > > > me having to end the boolean query explicitly.
> > 
> > > > [gist:1864764 · GitHub](https://gist.github.com/1864764)
> > 
> > > > I hope I'm explaining myself properly.
> > 
> > > > On Feb 19, 5:28 pm, Nick Dunn \<[n...@nick-dunn.co.uk](mailto:n...@nick-dunn.co.uk) ([http://nick-dunn.co.uk](http://nick-dunn.co.uk))\> wrote:
> > 
> > > > > Hello all. I'm very new to ES and Lucene, but I have spent a lot of  
> > > > > time devouring the documentation, this group and Stack Overflow.  
> > > > > However I've yet to find a definitive answer to my, hopefully simple,  
> > > > > question.
> > 
> > > > > I'm indexing several types (books, authors, publishers and a few  
> > > > > others) which in the first instance I would like searchable from a  
> > > > > single text input. I understand from the docs that the text query  
> > > > > ([Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/text-)  
> > > > > query.html) is designed for this out of the box "one size fits all"  
> > > > > requirement. However I would also like to support a basic search  
> > > > > syntax of:
> > 
> > > > > - have each keyword as optional (OR), which the default operator for a  
> > > > > text query uses (tick!)
> > > > > - allow for a keyword to be prefixed with + or - to include/preclude  
> > > > > it from the search (which is supported by the query\_string query  
> > > > > type... tick!)
> > > > > - allow for phrases by wrapping these in double quotes, so these  
> > > > > become required phrases (e.g. "lorem ipsum" is essentially +"lorem  
> > > > > ipsum")
> > 
> > > > > In all instances I want to search "\_all" for the time being.
> > 
> > > > > After some playing with the various query types, it seems that the  
> > > > > text type offers good out of the box functionality, but the field/  
> > > > > query\_string type offers the +/- syntax. But am I correct in saying  
> > > > > neither offer the phrase/double quotes syntax?
> > 
> > > > > Having used elasticsearch-head to visually compile some queries, I am  
> > > > > wondering whether the above can only be implemented with some pre-  
> > > > > processing my end before sending the query to ES. I could use a  
> > > > > boolean query and then process in incoming query string to parse out  
> > > > > the +/- and phrases to build the must/should/must\_not parts of the  
> > > > > boolean query myself.
> > 
> > > > > I had hoped that I could simply throw this at ES verbatim, but will I  
> > > > > need to add my own layer of string parsing first?
> > 
> > > > > Any direction greatly appreciated.

---

<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:38am UTC](https://discuss.elastic.co/t/newbie-differences-between-text-and-field-query-string-and-matching-words-vs-phrases/6748/7 "2017-07-06T03:38:47Z")

</div>


