# Score based on integer value

**URL:** <https://discuss.elastic.co/t/score-based-on-integer-value/8907>\
**Category:** Elasticsearch\
**Created:** [August 31, 2012, 5:48pm UTC](https://discuss.elastic.co/t/score-based-on-integer-value/8907 "2012-08-31T17:48:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Yuska](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_yuska/32/2717_2.png) [@Chris\_Yuska](https://discuss.elastic.co/u/Chris_Yuska)\
**Post date:** [August 31, 2012, 5:48pm UTC](https://discuss.elastic.co/t/score-based-on-integer-value/8907/1 "2012-08-31T17:48:50Z")

</div>

I've searched and I can't seem to find anyone else asking this sort of  
question. I have many Person objects that are searchable by name and  
should be scored by name match and number of mutual friends. Saying I have  
two people in my search results for "Chris":

person\_id: 1  
name: Chris Foo  
friends:  
id: 3  
mutual\_friends: 4  
...  
person\_id: 2  
name: Chris Bar  
friends:  
id: 3  
mutual\_friends: 6  
...

How can I score the person 2 higher than person 1 based on the integer  
value of mutual\_friends? Note that I don't want to strictly sort based on  
this number; I just want it to boost the overall score. I know I could do  
something hacky like:

person\_id: 1  
name: Chris Foo  
friends: [3, 3, 3, 3, ...]  
person\_id: 2  
name: Chris Bar  
friends: [3, 3, 3, 3, 3, 3, ...]

and the frequency of the friend\_id would cause a boost, but surely there's  
a better way..?

--

---

<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:** [August 31, 2012, 6:12pm UTC](https://discuss.elastic.co/t/score-based-on-integer-value/8907/2 "2012-08-31T18:12:40Z")

</div>

Did you look at custom scoring ?  
I think it could help you even if I didn't use it myself.

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

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 31 août 2012 à 19:48, Chris Yuska [chrisyuska@gmail.com](mailto:chrisyuska@gmail.com) a écrit :

> I've searched and I can't seem to find anyone else asking this sort of question. I have many Person objects that are searchable by name and should be scored by name match and number of mutual friends. Saying I have two people in my search results for "Chris":
> 
> person\_id: 1  
> name: Chris Foo  
> friends:  
> id: 3  
> mutual\_friends: 4  
> ...  
> person\_id: 2  
> name: Chris Bar  
> friends:  
> id: 3  
> mutual\_friends: 6  
> ...
> 
> How can I score the person 2 higher than person 1 based on the integer value of mutual\_friends? Note that I don't want to strictly sort based on this number; I just want it to boost the overall score. I know I could do something hacky like:
> 
> person\_id: 1  
> name: Chris Foo  
> friends: [3, 3, 3, 3, ...]  
> person\_id: 2  
> name: Chris Bar  
> friends: [3, 3, 3, 3, 3, 3, ...]
> 
> ## and the frequency of the friend\_id would cause a boost, but surely there's a better way..?

--

---

<div class="post-metadata">

**Author:** ![Chris\_Yuska](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_yuska/32/2717_2.png) [@Chris\_Yuska](https://discuss.elastic.co/u/Chris_Yuska)\
**Post date:** [August 31, 2012, 7:56pm UTC](https://discuss.elastic.co/t/score-based-on-integer-value/8907/3 "2012-08-31T19:56:52Z")

</div>

I have, but I'm a little unsure of how it works exactly. Does it not  
determine the score for the whole search? I'm actually matching on a slew  
of other fields, but I left them out to simplify this post. It would be a  
headache creating a custom score based on all of those fields as well. Or  
am I misunderstanding custom\_score and I can limit it to customizing the  
score of just that field?

On Friday, August 31, 2012 2:13:23 PM UTC-4, David Pilato wrote:

> Did you look at custom scoring ?  
> I think it could help you even if I didn't use it myself.
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/custom-score-query.html)
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 31 août 2012 à 19:48, Chris Yuska \<[chris...@gmail.com](mailto:chris...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> I've searched and I can't seem to find anyone else asking this sort of  
> question. I have many Person objects that are searchable by name and  
> should be scored by name match and number of mutual friends. Saying I have  
> two people in my search results for "Chris":
> 
> person\_id: 1  
> name: Chris Foo  
> friends:  
> id: 3  
> mutual\_friends: 4  
> ...  
> person\_id: 2  
> name: Chris Bar  
> friends:  
> id: 3  
> mutual\_friends: 6  
> ...
> 
> How can I score the person 2 higher than person 1 based on the integer  
> value of mutual\_friends? Note that I don't want to strictly sort based on  
> this number; I just want it to boost the overall score. I know I could do  
> something hacky like:
> 
> person\_id: 1  
> name: Chris Foo  
> friends: [3, 3, 3, 3, ...]  
> person\_id: 2  
> name: Chris Bar  
> friends: [3, 3, 3, 3, 3, 3, ...]
> 
> and the frequency of the friend\_id would cause a boost, but surely there's  
> a better way..?
> 
> --

--

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://discuss.elastic.co/u/phill)\
**Post date:** [September 1, 2012, 1:23am UTC](https://discuss.elastic.co/t/score-based-on-integer-value/8907/4 "2012-09-01T01:23:22Z")

</div>

Any type o f query combined with another in a boolQuery and that part  
of the expression boosted separately.

On 8/31/2012 12:56 PM, Chris Yuska wrote:

> I have, but I'm a little unsure of how it works exactly. Does it not  
> determine the score for the whole search? I'm actually matching on a  
> slew of other fields, but I left them out to simplify this post. It  
> would be a headache creating a custom score based on all of those  
> fields as well. Or am I misunderstanding custom\_score and I can limit  
> it to customizing the score of just that field?

--

---

<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:14am UTC](https://discuss.elastic.co/t/score-based-on-integer-value/8907/5 "2017-07-06T03:14:20Z")

</div>


