# OR query

**URL:** <https://discuss.elastic.co/t/or-query/11961>\
**Category:** Elasticsearch\
**Created:** [May 14, 2013, 5:35pm UTC](https://discuss.elastic.co/t/or-query/11961 "2013-05-14T17:35:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amit\_Patel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amit_patel/32/2323_2.png) [@Amit\_Patel](https://discuss.elastic.co/u/Amit_Patel)\
**Post date:** [May 14, 2013, 5:35pm UTC](https://discuss.elastic.co/t/or-query/11961/1 "2013-05-14T17:35:20Z")

</div>

I have an index with "name" and "description" filed. I am running a Boolean  
query against my index. Sometimes the term is present in both name and  
description fields, in this case the documents in which both the name and  
description contains the search term are scored higher compared to the ones  
having either the name or the description having the search term. What I  
want is to score them equal. So the the documents with either name or  
description having the term has the same score as the document having the  
search term present in both name and description. Is it possible? Here is  
the example:

{  
"name": "xyz",  
"description": "abc xyz"  
},  
{  
"name": "abc",  
"description": "xyz pqr"  
},  
{  
"name": "xyz",  
"description": "abc pqr"  
}

If the user search for term "xyz" I want all three documents above to have  
the same score. As all documents contains the term "xyz" either in name or  
in description or in both fields.

--  
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:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [May 15, 2013, 6:17am UTC](https://discuss.elastic.co/t/or-query/11961/2 "2013-05-15T06:17:11Z")

</div>

Getting the score to be exactly the same will be difficult. First of all,  
if your description field is variable between documents, then the field  
norm will have a different value.

A few things to try out. Omit term frequencies and norms for all the fields  
used in the query. Then set disableCoord on the bool query to true so that  
one clause is not score higher than the other.

--  
Ivan

On Tue, May 14, 2013 at 10:35 AM, Amit Patel [avpatel.257@gmail.com](mailto:avpatel.257@gmail.com) wrote:

> I have an index with "name" and "description" filed. I am running a  
> Boolean query against my index. Sometimes the term is present in both name  
> and description fields, in this case the documents in which both the name  
> and description contains the search term are scored higher compared to the  
> ones having either the name or the description having the search term. What  
> I want is to score them equal. So the the documents with either name or  
> description having the term has the same score as the document having the  
> search term present in both name and description. Is it possible? Here is  
> the example:
> 
> {  
> "name": "xyz",  
> "description": "abc xyz"  
> },  
> {  
> "name": "abc",  
> "description": "xyz pqr"  
> },  
> {  
> "name": "xyz",  
> "description": "abc pqr"  
> }
> 
> If the user search for term "xyz" I want all three documents above to have  
> the same score. As all documents contains the term "xyz" either in name or  
> in description or in both fields.
> 
> --  
> 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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 15, 2013, 7:43am UTC](https://discuss.elastic.co/t/or-query/11961/3 "2013-05-15T07:43:18Z")

</div>

Just a thought: I'm wondering if using custom scoring can help you here: [http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/](http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/)

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 15 mai 2013 à 08:17, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) a écrit :

> Getting the score to be exactly the same will be difficult. First of all, if your description field is variable between documents, then the field norm will have a different value.
> 
> A few things to try out. Omit term frequencies and norms for all the fields used in the query. Then set disableCoord on the bool query to true so that one clause is not score higher than the other.
> 
> --  
> Ivan
> 
> On Tue, May 14, 2013 at 10:35 AM, Amit Patel [avpatel.257@gmail.com](mailto:avpatel.257@gmail.com) wrote:  
> I have an index with "name" and "description" filed. I am running a Boolean query against my index. Sometimes the term is present in both name and description fields, in this case the documents in which both the name and description contains the search term are scored higher compared to the ones having either the name or the description having the search term. What I want is to score them equal. So the the documents with either name or description having the term has the same score as the document having the search term present in both name and description. Is it possible? Here is the example:
> 
> {  
> "name": "xyz",  
> "description": "abc xyz"  
> },  
> {  
> "name": "abc",  
> "description": "xyz pqr"  
> },  
> {  
> "name": "xyz",  
> "description": "abc pqr"  
> }
> 
> If the user search for term "xyz" I want all three documents above to have the same score. As all documents contains the term "xyz" either in name or in description or in both fields.
> 
> --  
> 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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 15, 2013, 10:32am UTC](https://discuss.elastic.co/t/or-query/11961/4 "2013-05-15T10:32:07Z")

</div>

It sounds like what you want is to use the dis\_max query instead of the  
bool query

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

Bool sums the score for each matching clause, while dis\_max uses the score  
from the best matching clause

clint

On 15 May 2013 09:44, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:

> Just a thought: I'm wondering if using custom scoring can help you here:  
> [http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/](http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/)
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> 
> Le 15 mai 2013 à 08:17, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) a écrit :
> 
> Getting the score to be exactly the same will be difficult. First of all,  
> if your description field is variable between documents, then the field  
> norm will have a different value.
> 
> A few things to try out. Omit term frequencies and norms for all the  
> fields used in the query. Then set disableCoord on the bool query to true  
> so that one clause is not score higher than the other.
> 
> --  
> Ivan
> 
> On Tue, May 14, 2013 at 10:35 AM, Amit Patel [avpatel.257@gmail.com](mailto:avpatel.257@gmail.com)wrote:
> 
> > I have an index with "name" and "description" filed. I am running a  
> > Boolean query against my index. Sometimes the term is present in both name  
> > and description fields, in this case the documents in which both the name  
> > and description contains the search term are scored higher compared to the  
> > ones having either the name or the description having the search term. What  
> > I want is to score them equal. So the the documents with either name or  
> > description having the term has the same score as the document having the  
> > search term present in both name and description. Is it possible? Here is  
> > the example:
> > 
> > {  
> > "name": "xyz",  
> > "description": "abc xyz"  
> > },  
> > {  
> > "name": "abc",  
> > "description": "xyz pqr"  
> > },  
> > {  
> > "name": "xyz",  
> > "description": "abc pqr"  
> > }
> > 
> > If the user search for term "xyz" I want all three documents above to  
> > have the same score. As all documents contains the term "xyz" either in  
> > name or in description or in both fields.
> > 
> > --  
> > 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).

--  
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:** ![Amit\_Patel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amit_patel/32/2323_2.png) [@Amit\_Patel](https://discuss.elastic.co/u/Amit_Patel)\
**Post date:** [May 15, 2013, 10:07pm UTC](https://discuss.elastic.co/t/or-query/11961/5 "2013-05-15T22:07:09Z")

</div>

Thanks guys. I will try the suggestions and post back the results.

On Wed, May 15, 2013 at 6:32 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> It sounds like what you want is to use the dis\_max query instead of the  
> bool query
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/dis-max-query/)
> 
> Bool sums the score for each matching clause, while dis\_max uses the score  
> from the best matching clause
> 
> clint
> 
> On 15 May 2013 09:44, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> 
> > Just a thought: I'm wondering if using custom scoring can help you here:  
> > [http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/](http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/)
> > 
> > --  
> > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > 
> > Le 15 mai 2013 à 08:17, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) a écrit :
> > 
> > Getting the score to be exactly the same will be difficult. First of all,  
> > if your description field is variable between documents, then the field  
> > norm will have a different value.
> > 
> > A few things to try out. Omit term frequencies and norms for all the  
> > fields used in the query. Then set disableCoord on the bool query to true  
> > so that one clause is not score higher than the other.
> > 
> > --  
> > Ivan
> > 
> > On Tue, May 14, 2013 at 10:35 AM, Amit Patel [avpatel.257@gmail.com](mailto:avpatel.257@gmail.com)wrote:
> > 
> > > I have an index with "name" and "description" filed. I am running a  
> > > Boolean query against my index. Sometimes the term is present in both name  
> > > and description fields, in this case the documents in which both the name  
> > > and description contains the search term are scored higher compared to the  
> > > ones having either the name or the description having the search term. What  
> > > I want is to score them equal. So the the documents with either name or  
> > > description having the term has the same score as the document having the  
> > > search term present in both name and description. Is it possible? Here is  
> > > the example:
> > > 
> > > {  
> > > "name": "xyz",  
> > > "description": "abc xyz"  
> > > },  
> > > {  
> > > "name": "abc",  
> > > "description": "xyz pqr"  
> > > },  
> > > {  
> > > "name": "xyz",  
> > > "description": "abc pqr"  
> > > }
> > > 
> > > If the user search for term "xyz" I want all three documents above to  
> > > have the same score. As all documents contains the term "xyz" either in  
> > > name or in description or in both fields.
> > > 
> > > --  
> > > 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).
> 
> --  
> 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/BvOCc8COVGw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/BvOCc8COVGw/unsubscribe?hl=en-US)  
> .  
> To unsubscribe from this group and all its topics, 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:** ![Amit\_Patel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amit_patel/32/2323_2.png) [@Amit\_Patel](https://discuss.elastic.co/u/Amit_Patel)\
**Post date:** [May 21, 2013, 6:32pm UTC](https://discuss.elastic.co/t/or-query/11961/6 "2013-05-21T18:32:14Z")

</div>

Looks like the dis-max-query is the way to go in this case. Thanks for your  
help.

On Wed, May 15, 2013 at 6:07 PM, Amit Patel [avpatel.257@gmail.com](mailto:avpatel.257@gmail.com) wrote:

> Thanks guys. I will try the suggestions and post back the results.
> 
> On Wed, May 15, 2013 at 6:32 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:
> 
> > It sounds like what you want is to use the dis\_max query instead of the  
> > bool query
> > 
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/dis-max-query/)
> > 
> > Bool sums the score for each matching clause, while dis\_max uses the  
> > score from the best matching clause
> > 
> > clint
> > 
> > On 15 May 2013 09:44, David Pilato [david@pilato.fr](mailto:david@pilato.fr) wrote:
> > 
> > > Just a thought: I'm wondering if using custom scoring can help you here:  
> > > [http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/](http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query/)
> > > 
> > > --  
> > > _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> > > @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)  
> > > | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)
> > > 
> > > Le 15 mai 2013 à 08:17, Ivan Brusic [ivan@brusic.com](mailto:ivan@brusic.com) a écrit :
> > > 
> > > Getting the score to be exactly the same will be difficult. First of  
> > > all, if your description field is variable between documents, then the  
> > > field norm will have a different value.
> > > 
> > > A few things to try out. Omit term frequencies and norms for all the  
> > > fields used in the query. Then set disableCoord on the bool query to true  
> > > so that one clause is not score higher than the other.
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Tue, May 14, 2013 at 10:35 AM, Amit Patel [avpatel.257@gmail.com](mailto:avpatel.257@gmail.com)wrote:
> > > 
> > > > I have an index with "name" and "description" filed. I am running a  
> > > > Boolean query against my index. Sometimes the term is present in both name  
> > > > and description fields, in this case the documents in which both the name  
> > > > and description contains the search term are scored higher compared to the  
> > > > ones having either the name or the description having the search term. What  
> > > > I want is to score them equal. So the the documents with either name or  
> > > > description having the term has the same score as the document having the  
> > > > search term present in both name and description. Is it possible? Here is  
> > > > the example:
> > > > 
> > > > {  
> > > > "name": "xyz",  
> > > > "description": "abc xyz"  
> > > > },  
> > > > {  
> > > > "name": "abc",  
> > > > "description": "xyz pqr"  
> > > > },  
> > > > {  
> > > > "name": "xyz",  
> > > > "description": "abc pqr"  
> > > > }
> > > > 
> > > > If the user search for term "xyz" I want all three documents above to  
> > > > have the same score. As all documents contains the term "xyz" either in  
> > > > name or in description or in both fields.
> > > > 
> > > > --  
> > > > 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).
> > 
> > --  
> > 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/BvOCc8COVGw/unsubscribe?hl=en-US](https://groups.google.com/d/topic/elasticsearch/BvOCc8COVGw/unsubscribe?hl=en-US)  
> > .  
> > To unsubscribe from this group and all its topics, 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:35am UTC](https://discuss.elastic.co/t/or-query/11961/7 "2017-07-06T02:35:30Z")

</div>


