1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

migrate es api: top 10 aggregations

This commit is contained in:
Sylvain 2018-07-12 11:26:13 +02:00
parent d0ec493ff9
commit 05bd65dfb2

View File

@ -387,10 +387,9 @@ Application.Controllers.controller "GraphsController", ["$scope", "$state", "$ro
queryElasticRanking = (esType, groupKey, sortKey, callback) ->
# handle invalid callback
if typeof(callback) != "function"
console.error('[graphsController::queryElasticRanking] Error: invalid callback provided')
return
return console.error('[graphsController::queryElasticRanking] Error: invalid callback provided')
if !esType or !groupKey or !sortKey
callback([], '[graphsController::queryElasticRanking] Error: invalid parameters provided')
return callback([], '[graphsController::queryElasticRanking] Error: invalid parameters provided')
# run query
es.search
@ -496,17 +495,21 @@ Application.Controllers.controller "GraphsController", ["$scope", "$state", "$ro
"aggregations":
"subgroups":
"terms":
"field": "subType"
"field": groupKey
"size": 10
"order":
"total": "desc"
"aggregations":
"top_events":
"top_hits":
"size": 1
"sort": [
{ "ca": "desc" }
]
"total":
"sum":
"field": "stat"
# we group the results by the custom given key (eg. by event date)
q.aggregations.subgroups.terms =
field: groupKey
size: 2147483647 #FIXME https://discuss.elastic.co/t/aggregation-size-0-for-top-results/135512/2
# results must be sorted and limited later by angular
if sortKey != 'ca'
angular.forEach q.query.bool.must, (must) ->