mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
ability to run custom aggregation with query and append result to query
This commit is contained in:
parent
ea671d03a4
commit
1fec50accf
@ -373,6 +373,7 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
|||||||
"type": index
|
"type": index
|
||||||
"size": RESULTS_PER_PAGE
|
"size": RESULTS_PER_PAGE
|
||||||
"scroll": ES_SCROLL_TIME+'m'
|
"scroll": ES_SCROLL_TIME+'m'
|
||||||
|
"stat-type": type
|
||||||
"body": buildElasticDataQuery(type, custom, $scope.agePicker.start, $scope.agePicker.end, moment($scope.datePickerStart.selected), moment($scope.datePickerEnd.selected), $scope.sorting)
|
"body": buildElasticDataQuery(type, custom, $scope.agePicker.start, $scope.agePicker.end, moment($scope.datePickerStart.selected), moment($scope.datePickerEnd.selected), $scope.sorting)
|
||||||
, (error, response) ->
|
, (error, response) ->
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -11,8 +11,17 @@ class API::StatisticsController < API::ApiController
|
|||||||
def #{path}
|
def #{path}
|
||||||
authorize :statistic, :#{path}?
|
authorize :statistic, :#{path}?
|
||||||
query = MultiJson.load(request.body.read)
|
query = MultiJson.load(request.body.read)
|
||||||
|
statistic_type = request.query_parameters.delete('stat-type')
|
||||||
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
|
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
|
||||||
# TODO
|
|
||||||
|
stat_index = StatisticIndex.find_by_es_type_key("#{path}")
|
||||||
|
stat_type = StatisticType.where(statistic_index_id: stat_index.id, key: statistic_type).first
|
||||||
|
client = Elasticsearch::Model.client
|
||||||
|
stat_type.statistic_custom_aggregations.each do |custom|
|
||||||
|
c_res = client.search index: custom.es_index, type:custom.es_type, q:custom.query
|
||||||
|
results['aggregations'][custom.field] = c_res
|
||||||
|
end
|
||||||
|
|
||||||
render json: results
|
render json: results
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
class RemovePathFromStatisticCustomAggregations < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
remove_column :statistic_custom_aggregations, :path, :string
|
||||||
|
end
|
||||||
|
end
|
@ -0,0 +1,6 @@
|
|||||||
|
class AddEsIndexEsTypeToStatisticCustomAggregations < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :statistic_custom_aggregations, :es_index, :string
|
||||||
|
add_column :statistic_custom_aggregations, :es_type, :string
|
||||||
|
end
|
||||||
|
end
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20160905142700) do
|
ActiveRecord::Schema.define(version: 20160906094847) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@ -543,11 +543,12 @@ ActiveRecord::Schema.define(version: 20160905142700) do
|
|||||||
|
|
||||||
create_table "statistic_custom_aggregations", force: :cascade do |t|
|
create_table "statistic_custom_aggregations", force: :cascade do |t|
|
||||||
t.text "query"
|
t.text "query"
|
||||||
t.string "path"
|
|
||||||
t.integer "statistic_type_id"
|
t.integer "statistic_type_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "field"
|
t.string "field"
|
||||||
|
t.string "es_index"
|
||||||
|
t.string "es_type"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "statistic_custom_aggregations", ["statistic_type_id"], name: "index_statistic_custom_aggregations_on_statistic_type_id", using: :btree
|
add_index "statistic_custom_aggregations", ["statistic_type_id"], name: "index_statistic_custom_aggregations_on_statistic_type_id", using: :btree
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
one:
|
one:
|
||||||
query: '{query:{bool:{must:[range:{start_at:{gte:"2016-08-01T02:00:00+02:00", lte:"2016-09-01T02:00:00+02:00"}, match:{available_type: "machines"}}]}}}'
|
query: '{query:{bool:{must:[range:{start_at:{gte:"2016-08-01T02:00:00+02:00", lte:"2016-09-01T02:00:00+02:00"}, match:{available_type: "machines"}}]}}}'
|
||||||
path: "/fablab/availabilities"
|
|
||||||
statistic_type_id: 2
|
statistic_type_id: 2
|
||||||
field: "available_hours"
|
field: "available_hours"
|
||||||
|
es_index: "fablab"
|
||||||
|
es_type: "availabilities"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user