# Behavior of multi field query\_string query doesn't seem to match documentation

**URL:** <https://discuss.elastic.co/t/behavior-of-multi-field-query-string-query-doesnt-seem-to-match-documentation/10618>\
**Category:** Elasticsearch\
**Created:** [February 4, 2013, 4:35pm UTC](https://discuss.elastic.co/t/behavior-of-multi-field-query-string-query-doesnt-seem-to-match-documentation/10618 "2013-02-04T16:35:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonardo\_Souza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leonardo_souza/32/2503_2.png) [@Leonardo\_Souza](https://discuss.elastic.co/u/Leonardo_Souza)\
**Post date:** [February 4, 2013, 4:35pm UTC](https://discuss.elastic.co/t/behavior-of-multi-field-query-string-query-doesnt-seem-to-match-documentation/10618/1 "2013-02-04T16:35:56Z")

</div>

Hey guys,

While doing some tests related to searching across multiple fields I  
stumbled upon a behavior with multi field query\_string query that seems to  
contradict what is stated in the official documentation. Below is what the  
documentation says on this matter:

"The idea of running the query\_string query against multiple fields is by

> internally creating several queries for the same query string, each with  
> default\_field that match the fields provided."  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query.html)

So, given the information above, I expected that the following multi field  
query:

curl -XGET 'localhost:9200/testgroupquery/\_search?pretty' -d '{  
"query": {  
"query\_string": {  
"fields": [  
"title",  
"address"  
],  
"auto\_generate\_phrase\_queries": true,  
"boost": 1.0,  
"default\_operator": "and",  
"use\_dis\_max" : true,  
"query": "hotel praha"  
}  
}  
}'

Would translate into a dis\_max query like this:

curl -XGET 'localhost:9200/testgroupquery/\_search?pretty' -d '{  
"query": {  
"dis\_max" : {  
"tie\_breaker" : 0.0,  
"queries" : [  
{  
"query\_string": {  
"default\_field": "title",  
"auto\_generate\_phrase\_queries": true,  
"boost": 1.0,  
"default\_operator": "and",  
"query": "hotel praha"  
}  
},  
{  
"query\_string": {  
"default\_field": "address",  
"auto\_generate\_phrase\_queries": true,  
"boost": 1.0,  
"default\_operator": "and",  
"query": "hotel praha"  
}  
}  
]  
}  
}  
}'

But apparently it doesn't. I first noticed this because the resultset  
returned is different between these two queries: while the multi field  
query\_string query matches all documents containing both "hotel" and  
"praha" in the title and/or address fields (_including cross matching  
between the fields_ - e.g. "hotel" in title and "praha" in address), the  
dis\_max query above returns just documents that contain both terms "hotel"  
and "praha" in the _same field_ (either title or address).

Looking at the final query for these two distinct requests using the  
Validate API, I can see that the output is quite different indeed:

_multi field query\_string query_

curl -XGET  
'localhost:9200/testgroupquery/\_validate/query?pretty&explain=true' -d '{  
"query\_string": {  
"fields": [  
"title",  
"address"  
],  
"auto\_generate\_phrase\_queries": true,  
"boost": 1.0,  
"default\_operator": "and",  
"use\_dis\_max" : true,  
"query": "hotel praha"  
}  
}'

{  
"valid" : true,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"explanations" : [ {  
"index" : "testgroupquery",  
"valid" : true,  
"explanation" : "_+(title:hotel | address:hotel) +(title:praha |  
address:praha)_"  
} ]  
}

_dis\_max query_  
\*  
\*  
curl -XGET  
'localhost:9200/testgroupquery/\_validate/query?pretty&explain=true' -d '{  
"dis\_max" : {  
"tie\_breaker" : 0.0,  
"queries" : [  
{  
"query\_string": {  
"default\_field": "title",  
"auto\_generate\_phrase\_queries": true,  
"boost": 1.0,  
"default\_operator": "and",  
"query": "hotel praha"  
}  
},  
{  
"query\_string": {  
"default\_field": "address",  
"auto\_generate\_phrase\_queries": true,  
"boost": 1.0,  
"default\_operator": "and",  
"query": "hotel praha"  
}  
}  
]  
}  
}'

{  
"valid" : true,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"failed" : 0  
},  
"explanations" : [ {  
"index" : "testgroupquery",  
"valid" : true,  
"explanation" : "_((+title:hotel +title:praha) | (+address:hotel  
+address:praha))_"  
} ]  
}

The reason I'm pointing out this difference is that I've been trying to  
configure my application to work in precisely the way the multi field  
query\_string query works, allowing users to search for multiple terms  
allowing matches across multiple fields. So that's exactly the behavior I  
want, but it seems to contradict what is in the documentation, so I want to  
make sure this matching across multiple fields is an expected behavior and  
not some anomaly that will be _corrected_ at some point.

In case it helps, the attached document contains all the requests to create  
the index and populate it with sample data, along with my query  
requests+response for each of the tests I did.

Thank you in advance for your help.

Best,  
Leo

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [February 4, 2013, 6:51pm UTC](https://discuss.elastic.co/t/behavior-of-multi-field-query-string-query-doesnt-seem-to-match-documentation/10618/2 "2013-02-04T18:51:06Z")

</div>

Hi Leo

> The reason I'm pointing out this difference is that I've been trying  
> to configure my application to work in precisely the way the multi  
> field query\_string query works, allowing users to search for multiple  
> terms allowing matches across multiple fields. So that's exactly the  
> behavior I want, but it seems to contradict what is in the  
> documentation, so I want to make sure this matching across multiple  
> fields is an expected behavior and not some anomaly that will be  
> corrected at some point.

It is expected behaviour and is unlikely to change.

The multi\_match query on the other hand DOES work the way you thought  
query\_string works, in other words:

{ multi\_match: {  
query: "foo bar",  
operator: "and",  
fields: ["one", "two"]  
}}

does translate into: "one:(+foo +bar) two:(+foo +bar)"

clint

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Leonardo\_Souza](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leonardo_souza/32/2503_2.png) [@Leonardo\_Souza](https://discuss.elastic.co/u/Leonardo_Souza)\
**Post date:** [February 4, 2013, 8:16pm UTC](https://discuss.elastic.co/t/behavior-of-multi-field-query-string-query-doesnt-seem-to-match-documentation/10618/3 "2013-02-04T20:16:27Z")

</div>

Thank you very much for your confirmation of this behavior, Clint!

Now one question still remains: is the documentation incorrect then, since  
it gives a different idea about the final query that will be generated?

Thanks,  
Leo

On Monday, February 4, 2013 1:51:06 PM UTC-5, Clinton Gormley wrote:

> Hi Leo
> 
> > The reason I'm pointing out this difference is that I've been trying  
> > to configure my application to work in precisely the way the multi  
> > field query\_string query works, allowing users to search for multiple  
> > terms allowing matches across multiple fields. So that's exactly the  
> > behavior I want, but it seems to contradict what is in the  
> > documentation, so I want to make sure this matching across multiple  
> > fields is an expected behavior and not some anomaly that will be  
> > corrected at some point.
> 
> It is expected behaviour and is unlikely to change.
> 
> The multi\_match query on the other hand DOES work the way you thought  
> query\_string works, in other words:
> 
> { multi\_match: {  
> query: "foo bar",  
> operator: "and",  
> fields: ["one", "two"]  
> }}
> 
> does translate into: "one:(+foo +bar) two:(+foo +bar)"
> 
> clint

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [February 4, 2013, 8:21pm UTC](https://discuss.elastic.co/t/behavior-of-multi-field-query-string-query-doesnt-seem-to-match-documentation/10618/4 "2013-02-04T20:21:27Z")

</div>

On Mon, 2013-02-04 at 12:16 -0800, Leonardo Souza wrote:

> Thank you very much for your confirmation of this behavior, Clint!
> 
> Now one question still remains: is the documentation incorrect then,  
> since it gives a different idea about the final query that will be  
> generated?

I'd say that the docs are, at best, ambiguous...

clint

> Thanks,  
> Leo
> 
> On Monday, February 4, 2013 1:51:06 PM UTC-5, Clinton Gormley wrote:  
> Hi Leo
> 
> ```
> > 
> > The reason I'm pointing out this difference is that I've
> been trying 
> > to configure my application to work in precisely the way the
> multi 
> > field query_string query works, allowing users to search for
> multiple 
> > terms allowing matches across multiple fields. So that's
> exactly the 
> > behavior I want, but it seems to contradict what is in the 
> > documentation, so I want to make sure this matching across
> multiple 
> > fields is an expected behavior and not some anomaly that
> will be 
> > corrected at some point. 
>     
> It is expected behaviour and is unlikely to change. 
>     
> The multi_match query on the other hand DOES work the way you
> thought 
> query_string works, in other words: 
>     
> { multi_match: { 
> query: "foo bar", 
> operator: "and", 
> fields: ["one", "two"] 
> }} 
>     
> does translate into: "one:(+foo +bar) two:(+foo +bar)" 
>     
> clint 
> 
> ```
> 
> --  
> 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).  
> 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).  
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, 2:53am UTC](https://discuss.elastic.co/t/behavior-of-multi-field-query-string-query-doesnt-seem-to-match-documentation/10618/5 "2017-07-06T02:53:03Z")

</div>


