# Sorting in a double field

**URL:** <https://discuss.elastic.co/t/sorting-in-a-double-field/3136>\
**Category:** Elasticsearch\
**Created:** [July 22, 2010, 6:46am UTC](https://discuss.elastic.co/t/sorting-in-a-double-field/3136 "2010-07-22T06:46:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajgamer](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@ajgamer](https://discuss.elastic.co/u/ajgamer)\
**Post date:** [July 22, 2010, 6:46am UTC](https://discuss.elastic.co/t/sorting-in-a-double-field/3136/1 "2010-07-22T06:46:57Z")

</div>

Hi,

I'm trying to sort on a double field(score based sorting) and I'm  
unable to sort based on score values. My score mapping looks something  
like this.

score" : {  
"omit\_term\_freq\_and\_positions" : false,  
"index\_name" : "score",  
"index" : "analyzed",  
"analyzer" : "sortable",  
"omit\_norms" : false,  
"store" : "no",  
"boost" : 1.0,  
"precision\_step" : 4,  
"term\_vector" : "no",  
"type" : "double"  
},

And the way i call is  
http://\*\*\*. **_._.** :9200/tournament/detail/\_search?q=tournamentid:686&sort=score:forward&analyzer=sortable  
. But i get random scores. I have another mapping for userid like:

userid" : {  
"omit\_term\_freq\_and\_positions" : true,  
"index\_name" : "userid",  
"index" : "not\_analyzed",  
"omit\_norms" : true,  
"store" : "no",  
"boost" : 1.0,  
"term\_vector" : "no",  
"type" : "string"  
}

And when i do a sort on userid i get the results sorted based on  
userid properly. What am i missing here, i suppose my mapping  
configuration for score needs a tweak.

Kind Regards.

---

<div class="post-metadata">

**Author:** ![ajgamer](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@ajgamer](https://discuss.elastic.co/u/ajgamer)\
**Post date:** [July 22, 2010, 9:49am UTC](https://discuss.elastic.co/t/sorting-in-a-double-field/3136/2 "2010-07-22T09:49:34Z")

</div>

Hi,

We managed to solve the issue. It turned out to be that score is a keyword  
and changing it to userscore did the trick. The mapping now is:

```
          "userscore" : {
            "omit_term_freq_and_positions" : true,
            "index_name" : "userscore",
            "index" : "not_analyzed",
            "omit_norms" : true,
            "store" : "no",
            "boost" : 1.0,
            "precision_step" : 4,
            "term_vector" : "no",
            "type" : "double"
          },

```

Kind Regards.

On Thu, Jul 22, 2010 at 12:16 PM, ajgamer [abie.joseph14@gmail.com](mailto:abie.joseph14@gmail.com) wrote:

> Hi,
> 
> I'm trying to sort on a double field(score based sorting) and I'm  
> unable to sort based on score values. My score mapping looks something  
> like this.
> 
> score" : {  
> "omit\_term\_freq\_and\_positions" : false,  
> "index\_name" : "score",  
> "index" : "analyzed",  
> "analyzer" : "sortable",  
> "omit\_norms" : false,  
> "store" : "no",  
> "boost" : 1.0,  
> "precision\_step" : 4,  
> "term\_vector" : "no",  
> "type" : "double"  
> },
> 
> And the way i call is  
> http://  
> _ **.** _.\*.\*\*:9200/tournament/detail/\_search?q=tournamentid:686&sort=score:forward&analyzer=sortable  
> . But i get random scores. I have another mapping for userid like:
> 
> userid" : {  
> "omit\_term\_freq\_and\_positions" : true,  
> "index\_name" : "userid",  
> "index" : "not\_analyzed",  
> "omit\_norms" : true,  
> "store" : "no",  
> "boost" : 1.0,  
> "term\_vector" : "no",  
> "type" : "string"  
> }
> 
> And when i do a sort on userid i get the results sorted based on  
> userid properly. What am i missing here, i suppose my mapping  
> configuration for score needs a tweak.
> 
> Kind Regards.

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [July 22, 2010, 6:22pm UTC](https://discuss.elastic.co/t/sorting-in-a-double-field/3136/3 "2010-07-22T18:22:37Z")

</div>

Actually, you are correct, its in the sort parsing stage, where "score" is  
used to denote sorting by the score of a doc... . Not sure what I took when  
I coded it, but its a mistake. It should have been `_score`, as is the  
convention for "internal" fields or constants in elasticsearch. Damn, need  
to be changed, I will open an issue and change it, even though it breaks  
backward, its important!

-shay.banon

On Thu, Jul 22, 2010 at 12:49 PM, Abbie Joseph [abie.joseph14@gmail.com](mailto:abie.joseph14@gmail.com)wrote:

> Hi,
> 
> We managed to solve the issue. It turned out to be that score is a keyword  
> and changing it to userscore did the trick. The mapping now is:
> 
> ```
> "userscore" : {
> 
> "omit_term_freq_and_positions" : true,
> "index_name" : "userscore",
> 
> "index" : "not_analyzed",
> "omit_norms" : true,
> "store" : "no",
> "boost" : 1.0,
> "precision_step" : 4,
> "term_vector" : "no",
> "type" : "double"
> },
> 
> ```
> 
> Kind Regards.
> 
> On Thu, Jul 22, 2010 at 12:16 PM, ajgamer [abie.joseph14@gmail.com](mailto:abie.joseph14@gmail.com) wrote:
> 
> > Hi,
> > 
> > I'm trying to sort on a double field(score based sorting) and I'm  
> > unable to sort based on score values. My score mapping looks something  
> > like this.
> > 
> > score" : {  
> > "omit\_term\_freq\_and\_positions" : false,  
> > "index\_name" : "score",  
> > "index" : "analyzed",  
> > "analyzer" : "sortable",  
> > "omit\_norms" : false,  
> > "store" : "no",  
> > "boost" : 1.0,  
> > "precision\_step" : 4,  
> > "term\_vector" : "no",  
> > "type" : "double"  
> > },
> > 
> > And the way i call is  
> > http://  
> > _ **.** _.\*.\*\*:9200/tournament/detail/\_search?q=tournamentid:686&sort=score:forward&analyzer=sortable  
> > . But i get random scores. I have another mapping for userid like:
> > 
> > userid" : {  
> > "omit\_term\_freq\_and\_positions" : true,  
> > "index\_name" : "userid",  
> > "index" : "not\_analyzed",  
> > "omit\_norms" : true,  
> > "store" : "no",  
> > "boost" : 1.0,  
> > "term\_vector" : "no",  
> > "type" : "string"  
> > }
> > 
> > And when i do a sort on userid i get the results sorted based on  
> > userid properly. What am i missing here, i suppose my mapping  
> > configuration for score needs a tweak.
> > 
> > Kind Regards.

---

<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, 4:21am UTC](https://discuss.elastic.co/t/sorting-in-a-double-field/3136/4 "2017-07-06T04:21:47Z")

</div>


