@@ -68,7 +68,7 @@ def _build_subquery(report_number):
68
68
{"match" : {"file" : report_number }},
69
69
{"match" : {"file" : report_number_movie }},
70
70
{"match" : {"file" : report_number_videoclip }},
71
- {"match" : {"_type" : "events.media_download " }}
71
+ {"match" : {"_type" : "events.cds_videos_media_download " }}
72
72
],
73
73
"minimum_should_match" : 2
74
74
}
@@ -81,7 +81,7 @@ def _build_subquery(report_number):
81
81
"should" : [
82
82
{"match" : {"file" : report_number }},
83
83
{"match" : {"file" : report_number_videorush }},
84
- {"match" : {"_type" : "events.media_download " }}
84
+ {"match" : {"_type" : "events.cds_videos_media_download " }}
85
85
],
86
86
"minimum_should_match" : 2
87
87
}
@@ -91,7 +91,6 @@ def _build_subquery(report_number):
91
91
@need_record_permission ('read_permission_factory' )
92
92
def get (self , pid , stat , record , ** kwargs ):
93
93
"""Handle GET request."""
94
-
95
94
es = Elasticsearch ([{
96
95
'host' : current_app .config ['LEGACY_STATS_ELASTIC_HOST' ],
97
96
'port' : current_app .config ['LEGACY_STATS_ELASTIC_PORT' ],
@@ -112,14 +111,17 @@ def get(self, pid, stat, record, **kwargs):
112
111
},
113
112
{
114
113
"match" : {
115
- "_type" : "events.pageviews "
114
+ "_type" : "events.cds_videos_pageviews "
116
115
}
117
116
}
118
117
]
119
118
}
120
119
}
121
120
}
122
- results = es .count (index = ES_INDEX , body = query ).get ('count' , 0 )
121
+ try :
122
+ results = es .count (index = ES_INDEX , body = query ).get ('count' , 0 )
123
+ except Exception :
124
+ return make_response ("Error getting statistics." , 400 )
123
125
124
126
# Get timestamp-aggregated downloads for specific CDS record
125
127
elif stat == 'downloads' :
@@ -150,12 +152,15 @@ def get(self, pid, stat, record, **kwargs):
150
152
}
151
153
}
152
154
}
153
- results = self .transform (
154
- es .search (index = ES_INDEX , body = query ),
155
- stat ,
156
- key_type )
157
-
158
- # Get timestamp-aggregated pageviews for specific CDS record
155
+ try :
156
+ results = self .transform (
157
+ es .search (index = ES_INDEX , body = query ),
158
+ stat ,
159
+ key_type )
160
+ except Exception :
161
+ return make_response ("Error getting statistics." , 400 )
162
+
163
+ # Get timestamp-aggregated pageviews for specific CDS record
159
164
elif stat == 'pageviews' :
160
165
key_type = 'date'
161
166
query = {
@@ -171,7 +176,8 @@ def get(self, pid, stat, record, **kwargs):
171
176
},
172
177
{
173
178
"match" : {
174
- "_type" : "events.pageviews"
179
+ "_type" :
180
+ "events.cds_videos_pageviews"
175
181
}
176
182
}
177
183
]
@@ -196,13 +202,17 @@ def get(self, pid, stat, record, **kwargs):
196
202
}
197
203
}
198
204
}
199
- results = self .transform (
200
- es .search (index = ES_INDEX , body = query ),
201
- stat ,
202
- key_type )
205
+ try :
206
+ results = self .transform (
207
+ es .search (index = ES_INDEX , body = query ),
208
+ stat ,
209
+ key_type )
210
+ except Exception :
211
+ return make_response ("Error getting statistics." , 400 )
203
212
204
213
return make_response (jsonify (results ), 200 )
205
214
215
+
206
216
# Convert retrieved statistics into 'Invenio-Stats' format
207
217
def transform (self , response , metric , key_type ):
208
218
graph_data = {}
0 commit comments