# How to score results based on value of a different field

**URL:** <https://discuss.elastic.co/t/how-to-score-results-based-on-value-of-a-different-field/12096>\
**Category:** Elasticsearch\
**Created:** [May 23, 2013, 12:54pm UTC](https://discuss.elastic.co/t/how-to-score-results-based-on-value-of-a-different-field/12096 "2013-05-23T12:54:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_O](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dave_o/32/69398_2.png) [@Dave\_O](https://discuss.elastic.co/u/Dave_O)\
**Post date:** [May 23, 2013, 12:54pm UTC](https://discuss.elastic.co/t/how-to-score-results-based-on-value-of-a-different-field/12096/1 "2013-05-23T12:54:22Z")

</div>

Hello,  
I'm running esearch 0.90 and are running queries where I would like the  
output ranked and sorted by another field.

A couple examples

I have data such as

id, name, address, group  
1,john,Laurel, 1  
2,mike, Southold,1  
3,pete,north,5  
4,pete,smithtown,3  
5,jackson,laurelton,2

What I would like to do is query by a field such as Name but be able to use  
the "group" field as part of the ranking.

So if I query where name = 'pete' I want the group with the lowest  
numbers to have a higher score.

So  
4,pete,smithtown,3  
would rank higher then  
3,pete,north,5

I also might want to do a bounding box query and then rank all the results  
by group.

When I add the sort by group it "nulls" the score for all my records.

--  
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:** ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)\
**Post date:** [May 23, 2013, 1:22pm UTC](https://discuss.elastic.co/t/how-to-score-results-based-on-value-of-a-different-field/12096/2 "2013-05-23T13:22:45Z")

</div>

Hi Dave,

If you add \_score as a secondary sort it will come back:

"sort": [  
{  
"group": {  
"order": "asc"  
}  
},  
"\_score"  
]

Cheers,  
Boaz

On Thursday, May 23, 2013 2:54:22 PM UTC+2, Dave O wrote:

> Hello,  
> I'm running esearch 0.90 and are running queries where I would like the  
> output ranked and sorted by another field.
> 
> A couple examples
> 
> I have data such as
> 
> id, name, address, group  
> 1,john,Laurel, 1  
> 2,mike, Southold,1  
> 3,pete,north,5  
> 4,pete,smithtown,3  
> 5,jackson,laurelton,2
> 
> What I would like to do is query by a field such as Name but be able to  
> use the "group" field as part of the ranking.
> 
> So if I query where name = 'pete' I want the group with the lowest  
> numbers to have a higher score.
> 
> So  
> 4,pete,smithtown,3  
> would rank higher then  
> 3,pete,north,5
> 
> I also might want to do a bounding box query and then rank all the results  
> by group.
> 
> When I add the sort by group it "nulls" the score for all my records.

--  
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:** ![Dave\_O](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dave_o/32/69398_2.png) [@Dave\_O](https://discuss.elastic.co/u/Dave_O)\
**Post date:** [May 23, 2013, 4:30pm UTC](https://discuss.elastic.co/t/how-to-score-results-based-on-value-of-a-different-field/12096/3 "2013-05-23T16:30:32Z")

</div>

Great! Thank you! This works great!

On Thursday, May 23, 2013 9:22:45 AM UTC-4, Boaz Leskes wrote:

> Hi Dave,
> 
> If you add \_score as a secondary sort it will come back:
> 
> "sort": [  
> {  
> "group": {  
> "order": "asc"  
> }  
> },  
> "\_score"  
> ]
> 
> Cheers,  
> Boaz
> 
> On Thursday, May 23, 2013 2:54:22 PM UTC+2, Dave O wrote:
> 
> > Hello,  
> > I'm running esearch 0.90 and are running queries where I would like the  
> > output ranked and sorted by another field.
> > 
> > A couple examples
> > 
> > I have data such as
> > 
> > id, name, address, group  
> > 1,john,Laurel, 1  
> > 2,mike, Southold,1  
> > 3,pete,north,5  
> > 4,pete,smithtown,3  
> > 5,jackson,laurelton,2
> > 
> > What I would like to do is query by a field such as Name but be able to  
> > use the "group" field as part of the ranking.
> > 
> > So if I query where name = 'pete' I want the group with the lowest  
> > numbers to have a higher score.
> > 
> > So  
> > 4,pete,smithtown,3  
> > would rank higher then  
> > 3,pete,north,5
> > 
> > I also might want to do a bounding box query and then rank all the  
> > results by group.
> > 
> > When I add the sort by group it "nulls" the score for all my records.

--  
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/how-to-score-results-based-on-value-of-a-different-field/12096/4 "2017-07-06T02:35:02Z")

</div>


