# Boost query by another field

**URL:** <https://discuss.elastic.co/t/boost-query-by-another-field/14741>\
**Category:** Elasticsearch\
**Created:** [December 6, 2013, 12:12am UTC](https://discuss.elastic.co/t/boost-query-by-another-field/14741 "2013-12-06T00:12:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![slushi](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@slushi](https://discuss.elastic.co/u/slushi)\
**Post date:** [December 6, 2013, 12:12am UTC](https://discuss.elastic.co/t/boost-query-by-another-field/14741/1 "2013-12-06T00:12:57Z")

</div>

I would like to boost a query based on whether a separate field of the  
document contains the query term. This is similar to a bool query with  
must/should clauses except I would like the clauses' scores to be  
multiplied rather than added. Basically, I would like the score to be  
mainly based on the main query, but just slightly modified based on the  
separate field. If I do a bool query, it seems as though there is a fairly  
good chance that in certain cases the 'should' clause on the separate field  
could play too large or too small a role during scoring.

--  
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/32858b81-9d7c-4e70-9490-d15d55bb5724%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/32858b81-9d7c-4e70-9490-d15d55bb5724%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:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 6, 2013, 7:58am UTC](https://discuss.elastic.co/t/boost-query-by-another-field/14741/2 "2013-12-06T07:58:44Z")

</div>

Hey

check out the function score query and its score mode:

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

--Alex

On Fri, Dec 6, 2013 at 1:12 AM, slushi [kireetreddy@gmail.com](mailto:kireetreddy@gmail.com) wrote:

> I would like to boost a query based on whether a separate field of the  
> document contains the query term. This is similar to a bool query with  
> must/should clauses except I would like the clauses' scores to be  
> multiplied rather than added. Basically, I would like the score to be  
> mainly based on the main query, but just slightly modified based on the  
> separate field. If I do a bool query, it seems as though there is a fairly  
> good chance that in certain cases the 'should' clause on the separate field  
> could play too large or too small a role during scoring.
> 
> --  
> 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/32858b81-9d7c-4e70-9490-d15d55bb5724%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/32858b81-9d7c-4e70-9490-d15d55bb5724%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/CAGCwEM\_3nhtxppf%2BTp2BMxVDv8Ozk5WF%2BsCz5n14W2hHQmN\_zw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_3nhtxppf%2BTp2BMxVDv8Ozk5WF%2BsCz5n14W2hHQmN_zw%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:** ![slushi](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@slushi](https://discuss.elastic.co/u/slushi)\
**Post date:** [December 6, 2013, 4:20pm UTC](https://discuss.elastic.co/t/boost-query-by-another-field/14741/3 "2013-12-06T16:20:44Z")

</div>

How would that work? I would need to see if the analyzed query term(s) hit the document field. I can see the function score working if the boost factor is pre-computed and captured in a numerical field, but that isn't what I am trying to do here.

On Dec 6, 2013, at 2:58 AM, Alexander Reelsen wrote:

> Hey
> 
> check out the function score query and its score mode: [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)
> 
> --Alex
> 
> On Fri, Dec 6, 2013 at 1:12 AM, slushi [kireetreddy@gmail.com](mailto:kireetreddy@gmail.com) wrote:  
> I would like to boost a query based on whether a separate field of the document contains the query term. This is similar to a bool query with must/should clauses except I would like the clauses' scores to be multiplied rather than added. Basically, I would like the score to be mainly based on the main query, but just slightly modified based on the separate field. If I do a bool query, it seems as though there is a fairly good chance that in certain cases the 'should' clause on the separate field could play too large or too small a role during scoring.
> 
> --  
> 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/32858b81-9d7c-4e70-9490-d15d55bb5724%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/32858b81-9d7c-4e70-9490-d15d55bb5724%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 a topic in the Google Groups "elasticsearch" group.  
> To unsubscribe from this topic, visit [https://groups.google.com/d/topic/elasticsearch/zyHZOO\_l8PA/unsubscribe](https://groups.google.com/d/topic/elasticsearch/zyHZOO_l8PA/unsubscribe).  
> To unsubscribe from this group and all its topics, 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/CAGCwEM\_3nhtxppf%2BTp2BMxVDv8Ozk5WF%2BsCz5n14W2hHQmN\_zw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM_3nhtxppf%2BTp2BMxVDv8Ozk5WF%2BsCz5n14W2hHQmN_zw%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/10FCD9FC-4AF4-49BF-8D94-93E8D2923E47%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/10FCD9FC-4AF4-49BF-8D94-93E8D2923E47%40gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 6, 2013, 4:27pm UTC](https://discuss.elastic.co/t/boost-query-by-another-field/14741/4 "2013-12-06T16:27:21Z")

</div>

On Thu, Dec 5, 2013 at 7:12 PM, slushi [kireetreddy@gmail.com](mailto:kireetreddy@gmail.com) wrote:

> Basically, I would like the score to be mainly based on the main query,  
> but just slightly modified based on the separate field. If I do a bool  
> query, it seems as though there is a fairly good chance that in certain  
> cases the 'should' clause on the separate field could play too large or too  
> small a role during scoring.

This text makes the Boosting Query (  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html))  
sound like the best choice or a bool query with very different boosts on  
the clauses. Those both basically add the scaled scores together. Like  
this: score = score\_1 \* 10 + score\_2.

I don't believe there is a query type that scores by multiplying results,  
though. I mean, one like this: score = score\_1 \* score\_2. I'm not sure  
the exact use case for such a thing, though.

--  
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/CAPmjWd0sezE86uPQV52HSwsp9gWieRfcFMfQEvnWkjHOkEW-Xw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0sezE86uPQV52HSwsp9gWieRfcFMfQEvnWkjHOkEW-Xw%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:** ![slushi](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@slushi](https://discuss.elastic.co/u/slushi)\
**Post date:** [December 6, 2013, 6:00pm UTC](https://discuss.elastic.co/t/boost-query-by-another-field/14741/5 "2013-12-06T18:00:09Z")

</div>

The use case is as follows: I have several documents with a full text field  
as well as metadata fields (title, tags, etc). It seems to me that the main  
driver of relevance should be the full text field, but if a metadata field  
also matches, I would like to experiment with boosting the score. The issue  
with adding scores is that the metadata field clause could contribute too  
much or too little to the final score. instead i would like to do something  
like "score the query against the full text field and if it also matches a  
metadata field, boost the score by 10%".

On Friday, December 6, 2013 11:27:21 AM UTC-5, Nikolas Everett wrote:

> On Thu, Dec 5, 2013 at 7:12 PM, slushi \<[kiree...@gmail.com](mailto:kiree...@gmail.com) \<javascript:\>\>wrote:
> 
> > Basically, I would like the score to be mainly based on the main query,  
> > but just slightly modified based on the separate field. If I do a bool  
> > query, it seems as though there is a fairly good chance that in certain  
> > cases the 'should' clause on the separate field could play too large or too  
> > small a role during scoring.
> 
> This text makes the Boosting Query (  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html))  
> sound like the best choice or a bool query with very different boosts on  
> the clauses. Those both basically add the scaled scores together. Like  
> this: score = score\_1 \* 10 + score\_2.
> 
> I don't believe there is a query type that scores by multiplying results,  
> though. I mean, one like this: score = score\_1 \* score\_2. I'm not sure  
> the exact use case for such a thing, though.

--  
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/834f4fbb-85f2-416c-bb4d-37bb140d2703%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/834f4fbb-85f2-416c-bb4d-37bb140d2703%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:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [December 6, 2013, 6:07pm UTC](https://discuss.elastic.co/t/boost-query-by-another-field/14741/6 "2013-12-06T18:07:58Z")

</div>

Have a look at  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/query-dsl-function-score-query.html#_relation_to_literal_custom_boost_literal_literal_custom_score_literal_and_literal_custom_filters_score_literal).  
Check the "and the Custom  
Filters Score Query[http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/query-dsl-custom-filters-score-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/master/query-dsl-custom-filters-score-query.html)"  
part. That might have what you want.

On Fri, Dec 6, 2013 at 1:00 PM, slushi [kireetreddy@gmail.com](mailto:kireetreddy@gmail.com) wrote:

> The use case is as follows: I have several documents with a full text  
> field as well as metadata fields (title, tags, etc). It seems to me that  
> the main driver of relevance should be the full text field, but if a  
> metadata field also matches, I would like to experiment with boosting the  
> score. The issue with adding scores is that the metadata field clause could  
> contribute too much or too little to the final score. instead i would like  
> to do something like "score the query against the full text field and if it  
> also matches a metadata field, boost the score by 10%".
> 
> On Friday, December 6, 2013 11:27:21 AM UTC-5, Nikolas Everett wrote:
> 
> > On Thu, Dec 5, 2013 at 7:12 PM, slushi [kiree...@gmail.com](mailto:kiree...@gmail.com) wrote:
> > 
> > > Basically, I would like the score to be mainly based on the main query,  
> > > but just slightly modified based on the separate field. If I do a bool  
> > > query, it seems as though there is a fairly good chance that in certain  
> > > cases the 'should' clause on the separate field could play too large or too  
> > > small a role during scoring.
> > 
> > This text makes the Boosting Query ([http://www.elasticsearch.org/](http://www.elasticsearch.org/)  
> > guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html)  
> > sound like the best choice or a bool query with very different boosts on  
> > the clauses. Those both basically add the scaled scores together. Like  
> > this: score = score\_1 \* 10 + score\_2.
> > 
> > I don't believe there is a query type that scores by multiplying results,  
> > though. I mean, one like this: score = score\_1 \* score\_2. I'm not sure  
> > the exact use case for such a thing, though.
> 
> --  
> 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/834f4fbb-85f2-416c-bb4d-37bb140d2703%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/834f4fbb-85f2-416c-bb4d-37bb140d2703%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/CAPmjWd0j7xVoP62M\_Y8QAELpbVf-tcMp\_CVc\_HqVpAnjTqo40A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0j7xVoP62M_Y8QAELpbVf-tcMp_CVc_HqVpAnjTqo40A%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, 2:02am UTC](https://discuss.elastic.co/t/boost-query-by-another-field/14741/7 "2017-07-06T02:02:47Z")

</div>


