# Sort aggregation by score

**URL:** https://discuss.elastic.co/t/sort-aggregation-by-score/121237
**Category:** Elasticsearch
**Created:** [February 23, 2018, 3:13pm UTC](https://discuss.elastic.co/t/sort-aggregation-by-score/121237 "2018-02-23T15:13:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![neoshinesnh](https://avatars.discourse-cdn.com/v4/letter/n/bbe5ce/32.png) [@neoshinesnh](https://discuss.elastic.co/u/neoshinesnh)
#### Post date: [February 23, 2018, 3:13pm UTC](https://discuss.elastic.co/t/sort-aggregation-by-score/121237/1 "2018-02-23T15:13:40Z")

</div>

I need to aggregation items of a text field and sort by score

```
{
    "aggs": {
        "name": {
            "aggs": {
                "name": {
                    "terms": {
                        "field": "name.raw",
                        "size": 5
                    }
                }
            },
            "bool": {
                "must": [
                    {
                        "match": {
                            "name.auto": "New York"
                        }
                    }
                ],
                "should": [
                    {
                        "match_phrase_prefix": {
                            "name.lower": "New York"
                        }
                    }
                ]
            }
        }
    },
    "size": 0
}
```

---

<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: [March 23, 2018, 3:13pm UTC](https://discuss.elastic.co/t/sort-aggregation-by-score/121237/2 "2018-03-23T15:13:50Z")

</div>

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