# Bug? Combining "custom\_score" script with "sort" gives value 'null' for score

**URL:** <https://discuss.elastic.co/t/bug-combining-custom-score-script-with-sort-gives-value-null-for-score/9989>\
**Category:** Elasticsearch\
**Created:** [December 7, 2012, 3:38pm UTC](https://discuss.elastic.co/t/bug-combining-custom-score-script-with-sort-gives-value-null-for-score/9989 "2012-12-07T15:38:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wires](https://avatars.discourse-cdn.com/v4/letter/w/f4b2a3/32.png) [@wires](https://discuss.elastic.co/u/wires)\
**Post date:** [December 7, 2012, 3:38pm UTC](https://discuss.elastic.co/t/bug-combining-custom-score-script-with-sort-gives-value-null-for-score/9989/1 "2012-12-07T15:38:12Z")

</div>

Hello guys,

It seems I cannot combine a "custom\_score" query with sorting?  
Is this known? is it a bug?

For example, this query:

{  
"sort": [  
{  
"creation\_date": {  
"order": "desc"  
}  
}  
],  
"query": {  
"custom\_score": {  
"query": {  
"match\_all": {}  
},  
"script": "42"  
}  
}  
}

Gives a result somewhat like this:

hits: {

- total: 22791
- max\_score: null
- hits: [
  - {
    - \_index: w24\_121207.160252
    - \_type: vpro
    - \_id: 2a7365ef-f1aa-4ba7-95b0-30e6a9d5a833
    - \_score: null

However, the following query just works fine:

{  
"query": {  
"custom\_score": {  
"query": {  
"match\_all": {}  
},  
"script": "42"  
}  
}  
}

Result: \_score: 42

Is this expected? Can I somehow work around this?

Thanks,  
Jelle.

--

---

<div class="post-metadata">

**Author:** ![wires](https://avatars.discourse-cdn.com/v4/letter/w/f4b2a3/32.png) [@wires](https://discuss.elastic.co/u/wires)\
**Post date:** [December 12, 2012, 12:14pm UTC](https://discuss.elastic.co/t/bug-combining-custom-score-script-with-sort-gives-value-null-for-score/9989/2 "2012-12-12T12:14:07Z")

</div>

Op vrijdag 7 december 2012 16:38:12 UTC+1 schreef wires het volgende:

> Hello guys,
> 
> It seems I cannot combine a "custom\_score" query with sorting?  
> Is this known? is it a bug?

to answer this myself 🙂 it is known and it is not a bug. You are either  
sorting on a field or on \_score, which is rather obvious actually (I was  
wondering, how is sorting combined with scoring? answer: it's not...).

When you are sorting scores are no longer calculated.

--

---

<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:** [December 12, 2012, 10:40pm UTC](https://discuss.elastic.co/t/bug-combining-custom-score-script-with-sort-gives-value-null-for-score/9989/3 "2012-12-12T22:40:32Z")

</div>

You can enabled track scores for scores to be calculated.

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

Not sure if this works with custom scores, but I do not see any reason why  
it should not.

--  
Ivan

On Wed, Dec 12, 2012 at 4:14 AM, wires [jelleherold@gmail.com](mailto:jelleherold@gmail.com) wrote:

> Op vrijdag 7 december 2012 16:38:12 UTC+1 schreef wires het volgende:
> 
> > Hello guys,
> > 
> > It seems I cannot combine a "custom\_score" query with sorting?  
> > Is this known? is it a bug?
> 
> to answer this myself 🙂 it is known and it is not a bug. You are either  
> sorting on a field or on \_score, which is rather obvious actually (I was  
> wondering, how is sorting combined with scoring? answer: it's not...).
> 
> When you are sorting scores are no longer calculated.
> 
> --

--

---

<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:00am UTC](https://discuss.elastic.co/t/bug-combining-custom-score-script-with-sort-gives-value-null-for-score/9989/4 "2017-07-06T03:00:02Z")

</div>


