Bug? Combining "custom_score" script with "sort" gives value 'null' for score

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.

--

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 :slight_smile: 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.

--

You can enabled track scores for scores to be calculated.

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 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 :slight_smile: 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.

--

--