# Range versus term boosting in Elastic Search

**URL:** <https://discuss.elastic.co/t/range-versus-term-boosting-in-elastic-search/8017>\
**Category:** Elasticsearch\
**Created:** [June 8, 2012, 9:13am UTC](https://discuss.elastic.co/t/range-versus-term-boosting-in-elastic-search/8017 "2012-06-08T09:13:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stine](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@Stine](https://discuss.elastic.co/u/Stine)\
**Post date:** [June 8, 2012, 9:13am UTC](https://discuss.elastic.co/t/range-versus-term-boosting-in-elastic-search/8017/1 "2012-06-08T09:13:25Z")

</div>

Hi,

I am struggling to make boosting work the way I want it to in Elastic  
Search.

Let's say I have some profiles indexed containing gender, interests  
and age, and let's say that I find it most relevant that the gender  
matches, then the interest and the least important criterium is the  
user's age. I was expecting the below query to result in an ordering  
of the matching profiles according to the just mentioned principle,  
but when I execute it I get some males first and then I get the female  
Anna of the age 50 before the female Maria who likes cars... why  
doesn't Maria get a higher score than Anna??

{  
"query": {  
"bool" : {  
"should" : [  
{ "term" : { "gender" : { "term": "male", "boost":  
10.0 } } },  
{ "term" : { "likes" : { "term": "cars", "boost" :  
5.0 } } },  
{ "range" : { "age" : { "from" : 50, "boost" :  
1.0 } } }  
],  
"minimum\_number\_should\_match" : 1  
}  
}  
}

Hints will be greatly appreciated, thanks,  
Stine

---

<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:** [June 8, 2012, 9:24am UTC](https://discuss.elastic.co/t/range-versus-term-boosting-in-elastic-search/8017/2 "2012-06-08T09:24:37Z")

</div>

Hi Stine,

Is Anna a male ?

Just kidding !

Do you find Maria when you search only for cars ? Do you use default mapping ?  
Did you try to activate explain to see how ES (Lucene) computes results scores ?

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

[http://www.elasticsearch.org/guide/reference/api/search/explain.html](http://www.elasticsearch.org/guide/reference/api/search/explain.html)

David.

Le 8 juin 2012 à 11:13, Stine [stinesplace@gmail.com](mailto:stinesplace@gmail.com) a écrit :

> Hi,
> 
> I am struggling to make boosting work the way I want it to in Elastic  
> Search.
> 
> Let's say I have some profiles indexed containing gender, interests  
> and age, and let's say that I find it most relevant that the gender  
> matches, then the interest and the least important criterium is the  
> user's age. I was expecting the below query to result in an ordering  
> of the matching profiles according to the just mentioned principle,  
> but when I execute it I get some males first and then I get the female  
> Anna of the age 50 before the female Maria who likes cars... why  
> doesn't Maria get a higher score than Anna??
> 
> {  
> "query": {  
> "bool" : {  
> "should" : [  
> { "term" : { "gender" : { "term": "male", "boost":  
> 10.0 } } },  
> { "term" : { "likes" : { "term": "cars", "boost" :  
> 5.0 } } },  
> { "range" : { "age" : { "from" : 50, "boost" :  
> 1.0 } } }  
> ],  
> "minimum\_number\_should\_match" : 1  
> }  
> }  
> }
> 
> Hints will be greatly appreciated, thanks,  
> Stine

--  
David Pilato  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet

---

<div class="post-metadata">

**Author:** ![Stine](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@Stine](https://discuss.elastic.co/u/Stine)\
**Post date:** [June 8, 2012, 9:31am UTC](https://discuss.elastic.co/t/range-versus-term-boosting-in-elastic-search/8017/3 "2012-06-08T09:31:51Z")

</div>

Was just thinking that it might be useful if I posted the curl commands necessary to reproduce...

$ curl -XPUT http://localhost:9200/users/profile/1 -d '{ "nickname" : "bob", "gender" : "male", "age" : 48, "likes" : "airplanes" }'

$ curl -XPUT [http://localhost:9200/users/profile/2](http://localhost:9200/users/profile/2) -d '{  
"nickname" : "carlos",  
"gender" : "male",  
"age" : 24,  
"likes" : "food"  
}

$ curl -XPUT [http://localhost:9200/users/profile/3](http://localhost:9200/users/profile/3) -d '{  
"nickname" : "julio",  
"gender" : "male",  
"age" : 18,  
"likes" : "ladies"  
}

$ curl -XPUT [http://localhost:9200/users/profile/4](http://localhost:9200/users/profile/4) -d '{  
"nickname" : "maria",  
"gender" : "female",  
"age" : 25,  
"likes" : "cars"  
}

$ curl -XPUT [http://localhost:9200/users/profile/5](http://localhost:9200/users/profile/5) -d '{  
"nickname" : "anna",  
"gender" : "female",  
"age" : 50,  
"likes" : "clothes"  
}

$ curl -XGET [http://localhost:9200/users/profile/\_search](http://localhost:9200/users/profile/_search) -d '{  
"query": {  
"bool" : {  
"should" : [  
{ "term" : { "gender" : { "term": "male", "boost": 10.0 } } },  
{ "term" : { "likes" : { "term": "cars", "boost" : 5.0 } } },  
{ "range" : { "age" : { "from" : 50, "boost" : 1.0 } } }  
],  
"minimum\_number\_should\_match" : 1  
}  
}  
}'

---

<div class="post-metadata">

**Author:** ![Stine](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@Stine](https://discuss.elastic.co/u/Stine)\
**Post date:** [June 8, 2012, 12:52pm UTC](https://discuss.elastic.co/t/range-versus-term-boosting-in-elastic-search/8017/4 "2012-06-08T12:52:31Z")

</div>

Thanks! I tried to add the explain, but must admit I did not get much out of it ;D Hmm..

---

<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, 3:25am UTC](https://discuss.elastic.co/t/range-versus-term-boosting-in-elastic-search/8017/5 "2017-07-06T03:25:11Z")

</div>

Closed on July 6, 2017, 3:25am UTC


