-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Closed
Labels
:Analytics/AggregationsAggregationsAggregations>featuregood first issuelow hanging fruitlow hanging fruithelp wantedadoptmeadoptme
Description
Elasticsearch version 6.5.1
Plugins installed: []
JVM version JVM 1.8.0_192
OS version Debian 8.11
Description of the problem including expected versus actual behavior:
- Actual behavior :
When sorting an aggregation with abucket_sortbased on its_count, ifdoc_countare equals the item that should be in first position is the last one, other items are in the right order. - Expected :
Every items should be in the right order, including the first one.
Steps to reproduce:
- Create a basic index :
curl -XPUT 'http://localhost:9200/messages' -H 'Content-Type: application/json' -d '
{
"settings": {
"number_of_shards": 1,
"number_of_replicas" : 0
},
"mappings": {
"user": {
"properties": {
"rank": {
"type": "keyword"
}
}
}
}
}'
- Insert one
userwith a differentrankeach time (fromatod) :
userwith ranka
curl -XPUT 'http://localhost:9200/messages/user/001' -H 'Content-Type: application/json' -d '
{
"@timestamp": "2018-12-06T01:00:00+01:00",
"rank": "a"
}'
userwith rankb
curl -XPUT 'http://localhost:9200/messages/user/002' -H 'Content-Type: application/json' -d '
{
"@timestamp": "2018-12-06T01:00:00+01:00",
"rank": "b"
}'
userwith rankc
curl -XPUT 'http://localhost:9200/messages/user/003' -H 'Content-Type: application/json' -d '
{
"@timestamp": "2018-12-06T01:00:00+01:00",
"rank": "c"
}'
userwith rankd
curl -XPUT 'http://localhost:9200/messages/user/004' -H 'Content-Type: application/json' -d '
{
"@timestamp": "2018-12-06T01:00:00+01:00",
"rank": "d"
}'
- Aggregate on the
rankproperty and sort bycountwith abucket_sort:
curl -XGET 'http://localhost:9200/messages/_search?pretty=true' -H 'Content-Type: application/json' -d '
{
"size": 0,
"aggregations": {
"top_by_color": {
"composite": {
"size": 1000,
"sources": [
{
"rank": {
"terms": {
"field": "rank",
"missing_bucket": true,
"order": "asc"
}
}
}
]
},
"aggregations": {
"top_bucket_sort": {
"bucket_sort": {
"sort": [
{
"_count": {
"order": "asc"
}
}
],
"size": 1000
}
}
}
}
}
}'
Aggregation result is :
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0,
"hits": [
]
},
"aggregations": {
"top_by_color": {
"after_key": {
"rank": "d"
},
"buckets": [
{
"key": {
"rank": "b"
},
"doc_count": 1
},
{
"key": {
"rank": "c"
},
"doc_count": 1
},
{
"key": {
"rank": "d"
},
"doc_count": 1
},
{
"key": {
"rank": "a"
},
"doc_count": 1
}
]
}
}
}
We have ranks sorted has : b, c, d, a instead of a, b, c, d.
Metadata
Metadata
Assignees
Labels
:Analytics/AggregationsAggregationsAggregations>featuregood first issuelow hanging fruitlow hanging fruithelp wantedadoptmeadoptme