# What is the difference between query\_string and multi-match for querying docs?

**URL:** <https://discuss.elastic.co/t/what-is-the-difference-between-query-string-and-multi-match-for-querying-docs/15566>\
**Category:** Elasticsearch\
**Created:** [February 3, 2014, 6:55pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-query-string-and-multi-match-for-querying-docs/15566 "2014-02-03T18:55:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [February 3, 2014, 6:55pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-query-string-and-multi-match-for-querying-docs/15566/1 "2014-02-03T18:55:50Z")

</div>

Hi,

Can anyone please tell me a detailed difference between these two queries.  
I studied the documentation but not able to figure out the difference  
between two. Can anyone please explain it with some examples in a more  
detailed fashion. I expect query string to give me docs which matches  
maximum number of terms which are generated by search\_analyzer to indexed  
docs but it is not happening that way.

Please help !!!

Thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [February 3, 2014, 7:09pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-query-string-and-multi-match-for-querying-docs/15566/2 "2014-02-03T19:09:13Z")

</div>

The key difference is that a query\_string query (with multiple fields and  
the AND operator) will match when each term exists in at least one field  
while a multi-match query (also using AND) matches only when all the terms  
exist in at least one field. The terms of a query\_string query do not need  
to exist in the same field, while it does matter in a multi-match.

Play around with the Sense Chrome plugin and some sample data:  
[https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo](https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo)

Cheers,

Ivan

On Mon, Feb 3, 2014 at 10:55 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:

> Hi,
> 
> Can anyone please tell me a detailed difference between these two queries.  
> I studied the documentation but not able to figure out the difference  
> between two. Can anyone please explain it with some examples in a more  
> detailed fashion. I expect query string to give me docs which matches  
> maximum number of terms which are generated by search\_analyzer to indexed  
> docs but it is not happening that way.
> 
> Please help !!!
> 
> Thanks
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBP-3JhfnX0Qoj0uYnBBUX\_V9Oysc45tg40eK7b7NB0rQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBP-3JhfnX0Qoj0uYnBBUX_V9Oysc45tg40eK7b7NB0rQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [February 3, 2014, 7:26pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-query-string-and-multi-match-for-querying-docs/15566/3 "2014-02-03T19:26:09Z")

</div>

Hi Ivan,

Thanks for the reply. Can you please tell how query\_string works internally  
? In the documentation, it says query is parsed internally. I want to know  
what is the meaning of this ? Let's say I 'm searching for "delhi t" so how  
query\_string will query for this string. Also assume I'm using  
search\_analyzer = standard with filter  
lowercase,asciifolding,suggestion\_shingle  
(min\_gram=2,max\_gram=2),edgengram(min\_gram=2,max\_gram=15). I know after  
search\_analyzer I'll have the following:

{  
"tokens" : [ {  
"token" : "de",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "del",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delh",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "de",  
"start\_offset" : 0,  
"end\_offset" : 7,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "del",  
"start\_offset" : 0,  
"end\_offset" : 7,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delh",  
"start\_offset" : 0,  
"end\_offset" : 7,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi",  
"start\_offset" : 0,  
"end\_offset" : 7,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi ",  
"start\_offset" : 0,  
"end\_offset" : 7,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi t",  
"start\_offset" : 0,  
"end\_offset" : 7,  
"type" : "word",  
"position" : 1  
} ]  
}

So, now how a query string will search in a document ?

Thanks

On Tue, Feb 4, 2014 at 12:39 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> The key difference is that a query\_string query (with multiple fields and  
> the AND operator) will match when each term exists in at least one field  
> while a multi-match query (also using AND) matches only when all the terms  
> exist in at least one field. The terms of a query\_string query do not need  
> to exist in the same field, while it does matter in a multi-match.
> 
> Play around with the Sense Chrome plugin and some sample data:  
> [https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo](https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo)
> 
> Cheers,
> 
> Ivan
> 
> On Mon, Feb 3, 2014 at 10:55 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:
> 
> > Hi,
> > 
> > Can anyone please tell me a detailed difference between these two  
> > queries. I studied the documentation but not able to figure out the  
> > difference between two. Can anyone please explain it with some examples in  
> > a more detailed fashion. I expect query string to give me docs which  
> > matches maximum number of terms which are generated by search\_analyzer to  
> > indexed docs but it is not happening that way.
> > 
> > Please help !!!
> > 
> > Thanks
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com)  
> > .  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBP-3JhfnX0Qoj0uYnBBUX\_V9Oysc45tg40eK7b7NB0rQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBP-3JhfnX0Qoj0uYnBBUX_V9Oysc45tg40eK7b7NB0rQ%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6XQ%3DJWCN9KkSS4cjs1ua1rtcy3Fcr8xG-AFN4dBC5HNw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6XQ%3DJWCN9KkSS4cjs1ua1rtcy3Fcr8xG-AFN4dBC5HNw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [February 3, 2014, 7:33pm UTC](https://discuss.elastic.co/t/what-is-the-difference-between-query-string-and-multi-match-for-querying-docs/15566/4 "2014-02-03T19:33:29Z")

</div>

Try using the plugin I suggested and/or the explain API.

> **[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 Mon, Feb 3, 2014 at 11:26 AM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:

> Hi Ivan,
> 
> Thanks for the reply. Can you please tell how query\_string works  
> internally ? In the documentation, it says query is parsed internally. I  
> want to know what is the meaning of this ? Let's say I 'm searching for  
> "delhi t" so how query\_string will query for this string. Also assume I'm  
> using search\_analyzer = standard with filter  
> lowercase,asciifolding,suggestion\_shingle  
> (min\_gram=2,max\_gram=2),edgengram(min\_gram=2,max\_gram=15). I know after  
> search\_analyzer I'll have the following:
> 
> {  
> "tokens" : [ {  
> "token" : "de",  
> "start\_offset" : 0,  
> "end\_offset" : 5,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "del",  
> "start\_offset" : 0,  
> "end\_offset" : 5,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "delh",  
> "start\_offset" : 0,  
> "end\_offset" : 5,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "delhi",  
> "start\_offset" : 0,  
> "end\_offset" : 5,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "de",  
> "start\_offset" : 0,  
> "end\_offset" : 7,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "del",  
> "start\_offset" : 0,  
> "end\_offset" : 7,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "delh",  
> "start\_offset" : 0,  
> "end\_offset" : 7,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "delhi",  
> "start\_offset" : 0,  
> "end\_offset" : 7,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "delhi ",  
> "start\_offset" : 0,  
> "end\_offset" : 7,  
> "type" : "word",  
> "position" : 1  
> }, {  
> "token" : "delhi t",  
> "start\_offset" : 0,  
> "end\_offset" : 7,  
> "type" : "word",  
> "position" : 1  
> } ]  
> }
> 
> So, now how a query string will search in a document ?
> 
> Thanks
> 
> On Tue, Feb 4, 2014 at 12:39 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> 
> > The key difference is that a query\_string query (with multiple fields and  
> > the AND operator) will match when each term exists in at least one field  
> > while a multi-match query (also using AND) matches only when all the terms  
> > exist in at least one field. The terms of a query\_string query do not need  
> > to exist in the same field, while it does matter in a multi-match.
> > 
> > Play around with the Sense Chrome plugin and some sample data:  
> > [https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo](https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo)
> > 
> > Cheers,
> > 
> > Ivan
> > 
> > On Mon, Feb 3, 2014 at 10:55 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:
> > 
> > > Hi,
> > > 
> > > Can anyone please tell me a detailed difference between these two  
> > > queries. I studied the documentation but not able to figure out the  
> > > difference between two. Can anyone please explain it with some examples in  
> > > a more detailed fashion. I expect query string to give me docs which  
> > > matches maximum number of terms which are generated by search\_analyzer to  
> > > indexed docs but it is not happening that way.
> > > 
> > > Please help !!!
> > > 
> > > Thanks
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com)  
> > > .  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBP-3JhfnX0Qoj0uYnBBUX\_V9Oysc45tg40eK7b7NB0rQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBP-3JhfnX0Qoj0uYnBBUX_V9Oysc45tg40eK7b7NB0rQ%40mail.gmail.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6XQ%3DJWCN9KkSS4cjs1ua1rtcy3Fcr8xG-AFN4dBC5HNw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6XQ%3DJWCN9KkSS4cjs1ua1rtcy3Fcr8xG-AFN4dBC5HNw%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRM\_ZF4bvQCdOvQnyxgz%3DNrQAbAG02e8CGTHQoPrDrQw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRM_ZF4bvQCdOvQnyxgz%3DNrQAbAG02e8CGTHQoPrDrQw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dark\_shadow](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dark\_shadow](https://discuss.elastic.co/u/dark_shadow)\
**Post date:** [February 4, 2014, 11:32am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-query-string-and-multi-match-for-querying-docs/15566/5 "2014-02-04T11:32:30Z")

</div>

Hi Ivan,

I followed your advice and started using explain api for query\_string but I  
guess in process I found a bug (don't know if it really is a bug or  
intended behaviour of query\_string). This is going to be a long post,  
please be patient with me.

I'm using a doc:{name:"new delhi to goa",st:"goa"}  
On using analyzer api for indexing I got these tokens:

{  
"tokens" : [ {  
"token" : "new",  
"start\_offset" : 0,  
"end\_offset" : 3,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new",  
"start\_offset" : 0,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new ",  
"start\_offset" : 0,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new d",  
"start\_offset" : 0,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new de",  
"start\_offset" : 0,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new del",  
"start\_offset" : 0,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delh",  
"start\_offset" : 0,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi",  
"start\_offset" : 0,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new ",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new d",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new de",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new del",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delh",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi ",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi t",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi to",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new ",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new d",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new de",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new del",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delh",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi ",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi t",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi to",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi to ",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi to g",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi to go",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "new delhi to goa",  
"start\_offset" : 0,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "del",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delh",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi",  
"start\_offset" : 4,  
"end\_offset" : 9,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "del",  
"start\_offset" : 4,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delh",  
"start\_offset" : 4,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi",  
"start\_offset" : 4,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi ",  
"start\_offset" : 4,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi t",  
"start\_offset" : 4,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi to",  
"start\_offset" : 4,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "del",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delh",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi ",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi t",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi to",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi to ",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi to g",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi to go",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "delhi to goa",  
"start\_offset" : 4,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "to ",  
"start\_offset" : 10,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 3  
}, {  
"token" : "to g",  
"start\_offset" : 10,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 3  
}, {  
"token" : "to go",  
"start\_offset" : 10,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 3  
}, {  
"token" : "to goa",  
"start\_offset" : 10,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 3  
}, {  
"token" : "goa",  
"start\_offset" : 13,  
"end\_offset" : 16,  
"type" : "word",  
"position" : 4  
} ]  
}

Now, if I query like: "delhi to goa", I got this by search\_analyzer:

{  
"tokens" : [ {  
"token" : "del",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delh",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi",  
"start\_offset" : 0,  
"end\_offset" : 5,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "del",  
"start\_offset" : 0,  
"end\_offset" : 8,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delh",  
"start\_offset" : 0,  
"end\_offset" : 8,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi",  
"start\_offset" : 0,  
"end\_offset" : 8,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi ",  
"start\_offset" : 0,  
"end\_offset" : 8,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi t",  
"start\_offset" : 0,  
"end\_offset" : 8,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi to",  
"start\_offset" : 0,  
"end\_offset" : 8,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "del",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delh",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi ",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi t",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi to",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi to ",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi to g",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi to go",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "delhi to goa",  
"start\_offset" : 0,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 1  
}, {  
"token" : "to ",  
"start\_offset" : 6,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "to g",  
"start\_offset" : 6,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "to go",  
"start\_offset" : 6,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "to goa",  
"start\_offset" : 6,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 2  
}, {  
"token" : "goa",  
"start\_offset" : 9,  
"end\_offset" : 12,  
"type" : "word",  
"position" : 3  
} ]  
}

On using explain api, it gives me following:

{text=new delhi to goa,boostFactor=9.820192307,po=9.82}  
510.39673 = custom score, product of:  
510.39673 = script score function: composed of:  
510.39673 = sum of:  
371.12375 = max of:  
371.12375 = sum of:  
104.61707 = weight(text:del in 1003990)  
[PerFieldSimilarity], result of:  
104.61707 = score(doc=1003990,freq=5.0 = termFreq=5.0  
), product of:  
0.43576795 = queryWeight, product of:  
5.368244 = idf(docFreq=53067, maxDocs=4187328)  
0.08117513 = queryNorm  
240.0752 = fieldWeight in 1003990, product of:  
2.236068 = tf(freq=5.0), with freq of:  
5.0 = termFreq=5.0  
5.368244 = idf(docFreq=53067, maxDocs=4187328)  
20.0 = fieldNorm(doc=1003990)  
133.24011 = weight(text:delh in 1003990)  
[PerFieldSimilarity], result of:  
133.24011 = score(doc=1003990,freq=5.0 = termFreq=5.0  
), product of:  
0.49178073 = queryWeight, product of:  
6.058268 = idf(docFreq=26616, maxDocs=4187328)  
0.08117513 = queryNorm  
270.934 = fieldWeight in 1003990, product of:  
2.236068 = tf(freq=5.0), with freq of:  
5.0 = termFreq=5.0  
6.058268 = idf(docFreq=26616, maxDocs=4187328)  
20.0 = fieldNorm(doc=1003990)  
133.26657 = weight(text:delhi in 1003990)  
[PerFieldSimilarity], result of:  
133.26657 = score(doc=1003990,freq=5.0 = termFreq=5.0  
), product of:  
0.49182954 = queryWeight, product of:  
6.0588694 = idf(docFreq=26600, maxDocs=4187328)  
0.08117513 = queryNorm  
270.96088 = fieldWeight in 1003990, product of:  
2.236068 = tf(freq=5.0), with freq of:  
5.0 = termFreq=5.0  
6.0588694 = idf(docFreq=26600, maxDocs=4187328)  
20.0 = fieldNorm(doc=1003990)  
139.27298 = max of:  
139.27298 = weight(text:goa^20.0 in 1003990)  
[PerFieldSimilarity], result of:  
139.27298 = score(doc=1003990,freq=3.0 = termFreq=3.0  
), product of:  
0.5712808 = queryWeight, product of:  
20.0 = boost  
7.037633 = idf(docFreq=9995, maxDocs=4187328)  
0.004058757 = queryNorm  
243.79076 = fieldWeight in 1003990, product of:  
1.7320508 = tf(freq=3.0), with freq of:  
3.0 = termFreq=3.0  
7.037633 = idf(docFreq=9995, maxDocs=4187328)  
20.0 = fieldNorm(doc=1003990)  
1.0 = queryBoost

Though the above explain shows the results for:  
del  
delh  
delhi  
goa

But not getting results for other tokens which were generated by my search  
analyzer. Why is it so ?

I have read that query\_string uses query parser which is based on Lucene by  
default. So, My guess is query\_string is using a whitespace tokenizer after  
my tokens are generated by search analyzer, am I correct ? How can I make  
query\_string to calculate score for all the tokens which are generated by  
search\_analyzer. Please correct me if I am wrong.

There is one more things which I noticed,  
I'm using a query time boost on one of my doc field but it is not working  
the way I thought it would work. In the above explain you can see, there is  
a boost associated with goa but not with delhi, though but goa and delhi  
are present in original doc. My guess for this is,  
query\_string applies boost to only terms where a term is a token of a user  
typed string which is not analyzed by any analyzer because in the above  
example, goa is kept as it is but delhi is being analyzed. Am I correct ?

Waiting a reply !!!

Thanks

On Tue, Feb 4, 2014 at 1:03 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:

> Try using the plugin I suggested and/or the explain API.  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-explain.html)
> 
> On Mon, Feb 3, 2014 at 11:26 AM, Mukul Gupta [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com)wrote:
> 
> > Hi Ivan,
> > 
> > Thanks for the reply. Can you please tell how query\_string works  
> > internally ? In the documentation, it says query is parsed internally. I  
> > want to know what is the meaning of this ? Let's say I 'm searching for  
> > "delhi t" so how query\_string will query for this string. Also assume I'm  
> > using search\_analyzer = standard with filter  
> > lowercase,asciifolding,suggestion\_shingle  
> > (min\_gram=2,max\_gram=2),edgengram(min\_gram=2,max\_gram=15). I know after  
> > search\_analyzer I'll have the following:
> > 
> > {  
> > "tokens" : [ {  
> > "token" : "de",  
> > "start\_offset" : 0,  
> > "end\_offset" : 5,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "del",  
> > "start\_offset" : 0,  
> > "end\_offset" : 5,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "delh",  
> > "start\_offset" : 0,  
> > "end\_offset" : 5,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "delhi",  
> > "start\_offset" : 0,  
> > "end\_offset" : 5,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "de",  
> > "start\_offset" : 0,  
> > "end\_offset" : 7,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "del",  
> > "start\_offset" : 0,  
> > "end\_offset" : 7,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "delh",  
> > "start\_offset" : 0,  
> > "end\_offset" : 7,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "delhi",  
> > "start\_offset" : 0,  
> > "end\_offset" : 7,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "delhi ",  
> > "start\_offset" : 0,  
> > "end\_offset" : 7,  
> > "type" : "word",  
> > "position" : 1  
> > }, {  
> > "token" : "delhi t",  
> > "start\_offset" : 0,  
> > "end\_offset" : 7,  
> > "type" : "word",  
> > "position" : 1  
> > } ]  
> > }
> > 
> > So, now how a query string will search in a document ?
> > 
> > Thanks
> > 
> > On Tue, Feb 4, 2014 at 12:39 AM, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) wrote:
> > 
> > > The key difference is that a query\_string query (with multiple fields  
> > > and the AND operator) will match when each term exists in at least one  
> > > field while a multi-match query (also using AND) matches only when all the  
> > > terms exist in at least one field. The terms of a query\_string query do not  
> > > need to exist in the same field, while it does matter in a multi-match.
> > > 
> > > Play around with the Sense Chrome plugin and some sample data:  
> > > [https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo](https://chrome.google.com/webstore/detail/sense/doinijnbnggojdlcjifpdckfokbbfpbo)
> > > 
> > > Cheers,
> > > 
> > > Ivan
> > > 
> > > On Mon, Feb 3, 2014 at 10:55 AM, coder [mukulnitkkr@gmail.com](mailto:mukulnitkkr@gmail.com) wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Can anyone please tell me a detailed difference between these two  
> > > > queries. I studied the documentation but not able to figure out the  
> > > > difference between two. Can anyone please explain it with some examples in  
> > > > a more detailed fashion. I expect query string to give me docs which  
> > > > matches maximum number of terms which are generated by search\_analyzer to  
> > > > indexed docs but it is not happening that way.
> > > > 
> > > > Please help !!!
> > > > 
> > > > Thanks
> > > > 
> > > > --  
> > > > You received this message because you are subscribed to the Google  
> > > > Groups "elasticsearch" group.  
> > > > To unsubscribe from this group and stop receiving emails from it, send  
> > > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > > To view this discussion on the web visit  
> > > > [https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fbc68c13-bcb9-40cb-9726-becbef14f278%40googlegroups.com)  
> > > > .  
> > > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > > 
> > > --  
> > > You received this message because you are subscribed to the Google  
> > > Groups "elasticsearch" group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBP-3JhfnX0Qoj0uYnBBUX\_V9Oysc45tg40eK7b7NB0rQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBP-3JhfnX0Qoj0uYnBBUX_V9Oysc45tg40eK7b7NB0rQ%40mail.gmail.com)  
> > > .
> > > 
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6XQ%3DJWCN9KkSS4cjs1ua1rtcy3Fcr8xG-AFN4dBC5HNw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp6XQ%3DJWCN9KkSS4cjs1ua1rtcy3Fcr8xG-AFN4dBC5HNw%40mail.gmail.com)  
> > .
> > 
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRM\_ZF4bvQCdOvQnyxgz%3DNrQAbAG02e8CGTHQoPrDrQw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQBRM_ZF4bvQCdOvQnyxgz%3DNrQAbAG02e8CGTHQoPrDrQw%40mail.gmail.com)  
> .
> 
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4SDcKVOm6nh\_-NQg7O5bVeQGLmQ3HD7UvAdu%3DB9m\_Nxw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAAVTvp4SDcKVOm6nh_-NQg7O5bVeQGLmQ3HD7UvAdu%3DB9m_Nxw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:52am UTC](https://discuss.elastic.co/t/what-is-the-difference-between-query-string-and-multi-match-for-querying-docs/15566/6 "2017-07-06T01:52:46Z")

</div>


