# Multi\_match boolean across fields

**URL:** <https://discuss.elastic.co/t/multi-match-boolean-across-fields/16150>\
**Category:** Elasticsearch\
**Created:** [March 4, 2014, 3:59pm UTC](https://discuss.elastic.co/t/multi-match-boolean-across-fields/16150 "2014-03-04T15:59:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thibaut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thibaut/32/1757_2.png) [@Thibaut](https://discuss.elastic.co/u/Thibaut)\
**Post date:** [March 4, 2014, 3:59pm UTC](https://discuss.elastic.co/t/multi-match-boolean-across-fields/16150/1 "2014-03-04T15:59:37Z")

</div>

Hello,

I'd like to build a specific query to ES that I can't find currently, here  
is what I would like to do:  
The query would be a _multi\_match_ that keeps only the documents that have  
all the terms in the query (the terms can be spread across several fields).

The default _multi\_match_ gives me documents that match at least one term  
of the query (too much documents), and if I add _"boolean": "and"_ it gives  
me only documents that have all the terms of the query in one particular  
field (too strict).

As a solution, I was thinking about using the analyzer of ES to get the  
list of tokens, then do an "AND" query of _multi\_match_ queries for one  
token in all the field, but it introduces a big overhead as there is two  
API calls to ES.

Could you give me any pointers on how I could build such a query ?  
Thanks,  
Thibaut

--  
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/ee1b7644-fbb5-466d-8998-f7104e25f59a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/ee1b7644-fbb5-466d-8998-f7104e25f59a%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:** ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)\
**Post date:** [March 4, 2014, 10:52pm UTC](https://discuss.elastic.co/t/multi-match-boolean-across-fields/16150/2 "2014-03-04T22:52:26Z")

</div>

I'd probably just aggregate all the fields you are interested in into 1  
field and then match/AND on that 1 field. You probably can do a copy\_to to  
accomplish the aggregation to a single field:

[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to)

--  
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/cf6b0267-4533-46cc-8701-d6dc4b243c75%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cf6b0267-4533-46cc-8701-d6dc4b243c75%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:** ![Thibaut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thibaut/32/1757_2.png) [@Thibaut](https://discuss.elastic.co/u/Thibaut)\
**Post date:** [March 4, 2014, 11:24pm UTC](https://discuss.elastic.co/t/multi-match-boolean-across-fields/16150/3 "2014-03-04T23:24:19Z")

</div>

Thank you! I haven't tried it yet, but reading the documentation makes me  
understand that it will solve my needs.

Is it possible to keep the boosting applied to the individual fields when  
computing the score ?  
Should I keep the original query and add the match/AND you're talking  
about, as a query filter, on the field created by the _copy\_to_ ?

On Tuesday, March 4, 2014 11:52:26 PM UTC+1, Binh Ly wrote:

> I'd probably just aggregate all the fields you are interested in into 1  
> field and then match/AND on that 1 field. You probably can do a copy\_to to  
> accomplish the aggregation to a single field:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html#copy-to)

--  
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/1d2cdf59-c18b-4b02-840c-7568263bac95%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1d2cdf59-c18b-4b02-840c-7568263bac95%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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [March 5, 2014, 12:52pm UTC](https://discuss.elastic.co/t/multi-match-boolean-across-fields/16150/4 "2014-03-05T12:52:31Z")

</div>

On 5 March 2014 00:24, Thibaut [thibaut.patel@gmail.com](mailto:thibaut.patel@gmail.com) wrote:

> Is it possible to keep the boosting applied to the individual fields when  
> computing the score ?

No. Field-level index time boosts will not be preserved with copy\_to.

Coming very soon in 1.1.0 is the `cross_fields` type of multi\_match query,  
which is designed to solve exactly the problem you are dealing with. Have  
a look at the docs:

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

--  
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/CAPt3XKTmqr3Z%2Bz1CyHTQEPw2d3NT5toD\_hhPngcY2OX%3DoSdM\_w%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPt3XKTmqr3Z%2Bz1CyHTQEPw2d3NT5toD_hhPngcY2OX%3DoSdM_w%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:** ![Thibaut](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thibaut/32/1757_2.png) [@Thibaut](https://discuss.elastic.co/u/Thibaut)\
**Post date:** [March 5, 2014, 1:15pm UTC](https://discuss.elastic.co/t/multi-match-boolean-across-fields/16150/5 "2014-03-05T13:15:11Z")

</div>

Thanks, I actually came across this part of the documentation a few hours  
ago, and this sentence is exactly what I was looking for: "It first  
analyzes the query string into individual terms, then looks for each term  
in any of the fields, as though they were one big field.".

I can't wait to upgrade to 1.1.0 then !

On Wednesday, March 5, 2014 1:52:31 PM UTC+1, Clinton Gormley wrote:

> On 5 March 2014 00:24, Thibaut \<[thibau...@gmail.com](mailto:thibau...@gmail.com) \<javascript:\>\> wrote:
> 
> > Is it possible to keep the boosting applied to the individual fields when  
> > computing the score ?
> 
> No. Field-level index time boosts will not be preserved with copy\_to.
> 
> Coming very soon in 1.1.0 is the `cross_fields` type of multi\_match query,  
> which is designed to solve exactly the problem you are dealing with. Have  
> a look at the docs:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#multi-match-types)[http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fquery-dsl-multi-match-query.html%23multi-match-types&sa=D&sntz=1&usg=AFQjCNHAzpV5GqKrn3j5jSFEcesYigGeWw](http://www.google.com/url?q=http%3A%2F%2Fwww.elasticsearch.org%2Fguide%2Fen%2Felasticsearch%2Freference%2Fcurrent%2Fquery-dsl-multi-match-query.html%23multi-match-types&sa=D&sntz=1&usg=AFQjCNHAzpV5GqKrn3j5jSFEcesYigGeWw)

--  
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/818017bb-0eb1-4412-a68e-c7e0d6b078e9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/818017bb-0eb1-4412-a68e-c7e0d6b078e9%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:** ![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:45am UTC](https://discuss.elastic.co/t/multi-match-boolean-across-fields/16150/6 "2017-07-06T01:45:34Z")

</div>


