Elasticsearch ver: 6.2.4
I have now got the results of composite aggregation by:
GET index/_search
{
"aggs": {
"my_buckets": {
"composite": {
"sources": [
{
"name": {
"terms": {
"field": "name.keyword"
}
}
}
]
}
}
},
"query":{
}
}
To simplify the question, the query part is omitted here.
I can get the results like:
"aggregations": {
"my_buckets": {
"buckets": [
{
"key": {
"name": "Bill Gates"
},
"doc_count": 1
},
{
"key": {
"name": "Steven Paul Jobs"
},
"doc_count": 1
},
{
"key": {
"name": "Gates Godar"
},
"doc_count": 1
}
]
}
}
I noticed that the order of the search results is not sorted by the score. If I use the following DSL:
{
"_source": "name",
"query":{
}
}
The results are ordered by score. That's what I want. But I need to use aggregations to group several attributes in the index and get the value.
How can we achieve to sort the composite aggregation results by the score? Is there a way to combine the "aggregations" with the "_source" part? It confuses me for several days, any idea is appreciated!
Thanks.