Bucket sort may be wrong

I am trying to use bucket_sort, but i am not sure if it's working correctly.

		"aggs": {
			"group_by_phone": {
				"terms": {
					"field": "phoneNumber.keyword"
				},
				"aggs": {
					"totalTnxAmount": {
						"sum": {
							"field": "amount"
						}
					},
					"sales_bucket_sort": {
						"bucket_sort": {
							"sort": [
								{
									"totalTnxAmount": {
										"order": "desc"
									}
								}
							]
						}
					},
					"aggs": {
						"top_hits": {
							"_source": [
								"firstName",
								"lastName"
							],
							"size": 1
						}
					}
				}
			}
		}

Please can anyone tell me if anything is wrong with this aggregation

Hi @NathBabs .
What's the problem with the query? Doesn't return the results it expects?

1 Like

@RabBit_BR Apparently it should sort based on total transactions over a period of time , Top performance - descending or Bottom performance - ascending.
When testing it, I have just little data to test with and it seems to work.
But when deployed to production, I have been getting complaints that the bottom performing list is just a reverse of the top performing list. So it's actually not even showing the bottom performance, but yet i don't seem to see anything wrong with my query if I change the order to either any one of "desc" or "asc"

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