# Unable to get \_score value when using field collapse and sort

**URL:** https://discuss.elastic.co/t/unable-to-get-score-value-when-using-field-collapse-and-sort/113038
**Category:** Elasticsearch
**Created:** [December 22, 2017, 4:51pm UTC](https://discuss.elastic.co/t/unable-to-get-score-value-when-using-field-collapse-and-sort/113038 "2017-12-22T16:51:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![amyc](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@amyc](https://discuss.elastic.co/u/amyc)
#### Post date: [December 22, 2017, 4:51pm UTC](https://discuss.elastic.co/t/unable-to-get-score-value-when-using-field-collapse-and-sort/113038/1 "2017-12-22T16:51:48Z")

</div>

When I search with sort other than \_score, the results dose not show \_score. However if I add "track\_scores" : "true", it does.

If for this same query, field collapse is used, "track\_scores" : "true" doesn't help.

I found a similar issue in ES bug 27122/ (or 23840), and it was fixed in 6.1.0. But this issue only address the max\_score, not the case above.

Any idea?

thanks!

Yifeng

---

<div class="post-metadata">

### Author: ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)
#### Post date: [December 28, 2017, 12:17pm UTC](https://discuss.elastic.co/t/unable-to-get-score-value-when-using-field-collapse-and-sort/113038/2 "2017-12-28T12:17:17Z")

</div>

Hi @amyc,

You can add \_score to your sort fields and track its value:

```
POST likes/doc/_bulk
{"index":{"_id": 1}}
{"likes": 10, "user": "john", "message": "elastic"}
{"index":{"_id": 2}}
{"likes": 20, "user": "john", "message": "elastic"}
{"index":{"_id": 3}}
{"likes": 5, "user": "ryan", "message": "elastic"}
{"index":{"_id": 4}}
{"likes": 10, "user": "ryan", "message": "elastic"}

GET likes/_search
{
  "track_scores": "true",
  "query": {
    "match": {
      "message": "elastic"
    }
  },
  "collapse": {
    "field": "user.keyword"
  },
  "sort": [
    "likes",
    "_score"
  ]
} 

```

Response:

```
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 4,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "likes",
        "_type": "doc",
        "_id": "3",
        "_score": 0.2876821,
        "_source": {
          "likes": 5,
          "user": "ryan",
          "message": "elastic"
        },
        "fields": {
          "user.keyword": [
            "ryan"
          ]
        },
        "sort": [
          5,
          0.2876821
        ]
      },
      {
        "_index": "likes",
        "_type": "doc",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "likes": 10,
          "user": "john",
          "message": "elastic"
        },
        "fields": {
          "user.keyword": [
            "john"
          ]
        },
        "sort": [
          10,
          0.2876821
        ]
      }
    ]
  }
}

```

Hope it helps.

Cheers,  
LG

---

<div class="post-metadata">

### Author: ![amyc](https://avatars.discourse-cdn.com/v4/letter/a/ea5d25/32.png) [@amyc](https://discuss.elastic.co/u/amyc)
#### Post date: [January 2, 2018, 2:08pm UTC](https://discuss.elastic.co/t/unable-to-get-score-value-when-using-field-collapse-and-sort/113038/3 "2018-01-02T14:08:48Z")

</div>

@luiz.santos, this works for me, thank you very much!

---

<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: [January 30, 2018, 2:09pm UTC](https://discuss.elastic.co/t/unable-to-get-score-value-when-using-field-collapse-and-sort/113038/4 "2018-01-30T14:09:12Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
