After additional research (source code of ES) I've found out that the Range aggregator also has access to the _score. Below an example that solved my problem:
POST /test/_search
{
"query": {
"match": {
"name": "red fox"
}
},
"aggs": {
"mostRelevantColors": {
"range": {
"script": {
"source": "_score"
},
"ranges": [
{
"from": 0.5
}
]
},
"aggs": {
"colors": {
"terms": {
"field": "color"
}
}
}
}
}
}
Response
{
"hits": {
"hits": [
{
"_score": 0.87546873,
"_type": "_doc",
"_id": "l7petGgBlKKsTTjoJ0OO",
"_source": {
"color": "red",
"name": "red fox"
},
"_index": "test"
},
{
"_score": 0.18232156,
"_type": "_doc",
"_id": "f7pdtGgBlKKsTTjo-0O4",
"_source": {
"color": "white",
"name": "arctic fox"
},
"_index": "test"
}
],
"total": 2,
"max_score": 0.87546873
},
"_shards": {
"successful": 1,
"failed": 0,
"skipped": 0,
"total": 1
},
"took": 1,
"aggregations": {
"mostRelevantColors": {
"buckets": [
{
"colors": {
"buckets": [
{
"key": "red",
"doc_count": 1
}
],
"sum_other_doc_count": 0,
"doc_count_error_upper_bound": 0
},
"from": 0.5,
"key": "0.5-*",
"doc_count": 1
}
]
}
},
"timed_out": false
}