##// END OF EJS Templates
elasticsearch: replace "filtered" with "bool" clause
ergo -
Show More
@@ -691,14 +691,14 b' def logs_cleanup(resource_id, filter_settings):'
691 request.tm.begin()
691 request.tm.begin()
692 es_query = {
692 es_query = {
693 "query": {
693 "query": {
694 "filtered": {"filter": {"and": [{"term": {"resource_id": resource_id}}]}}
694 "bool": {"filter": {"and": [{"term": {"resource_id": resource_id}}]}}
695 }
695 }
696 }
696 }
697
697
698 query = DBSession.query(Log).filter(Log.resource_id == resource_id)
698 query = DBSession.query(Log).filter(Log.resource_id == resource_id)
699 if filter_settings["namespace"]:
699 if filter_settings["namespace"]:
700 query = query.filter(Log.namespace == filter_settings["namespace"][0])
700 query = query.filter(Log.namespace == filter_settings["namespace"][0])
701 es_query["query"]["filtered"]["filter"]["and"].append(
701 es_query["query"]["bool"]["filter"]["and"].append(
702 {"term": {"namespace": filter_settings["namespace"][0]}}
702 {"term": {"namespace": filter_settings["namespace"][0]}}
703 )
703 )
704 query.delete(synchronize_session=False)
704 query.delete(synchronize_session=False)
@@ -311,7 +311,7 b' class Report(Base, BaseModel):'
311 query = {
311 query = {
312 "size": 1,
312 "size": 1,
313 "query": {
313 "query": {
314 "filtered": {
314 "bool": {
315 "filter": {
315 "filter": {
316 "and": [
316 "and": [
317 {"term": {"group_id": self.group_id}},
317 {"term": {"group_id": self.group_id}},
@@ -332,7 +332,7 b' class Report(Base, BaseModel):'
332 query = {
332 query = {
333 "size": 1,
333 "size": 1,
334 "query": {
334 "query": {
335 "filtered": {
335 "bool": {
336 "filter": {
336 "filter": {
337 "and": [
337 "and": [
338 {"term": {"group_id": self.group_id}},
338 {"term": {"group_id": self.group_id}},
@@ -57,7 +57,7 b' class LogService(BaseService):'
57
57
58 query = {
58 query = {
59 "query": {
59 "query": {
60 "filtered": {
60 "bool": {
61 "filter": {"and": [{"terms": {"resource_id": list(app_ids)}}]}
61 "filter": {"and": [{"terms": {"resource_id": list(app_ids)}}]}
62 }
62 }
63 }
63 }
@@ -65,7 +65,7 b' class LogService(BaseService):'
65
65
66 start_date = filter_settings.get("start_date")
66 start_date = filter_settings.get("start_date")
67 end_date = filter_settings.get("end_date")
67 end_date = filter_settings.get("end_date")
68 filter_part = query["query"]["filtered"]["filter"]["and"]
68 filter_part = query["query"]["bool"]["filter"]["and"]
69
69
70 for tag in filter_settings.get("tags", []):
70 for tag in filter_settings.get("tags", []):
71 tag_values = [v.lower() for v in tag["value"]]
71 tag_values = [v.lower() for v in tag["value"]]
@@ -93,7 +93,7 b' class LogService(BaseService):'
93
93
94 messages = filter_settings.get("message")
94 messages = filter_settings.get("message")
95 if messages:
95 if messages:
96 query["query"]["filtered"]["query"] = {
96 query["query"]["bool"]["must"] = {
97 "match": {"message": {"query": " ".join(messages), "operator": "and"}}
97 "match": {"message": {"query": " ".join(messages), "operator": "and"}}
98 }
98 }
99 return query
99 return query
@@ -132,13 +132,13 b' class LogService(BaseService):'
132
132
133 @classmethod
133 @classmethod
134 def get_search_iterator(
134 def get_search_iterator(
135 cls,
135 cls,
136 app_ids=None,
136 app_ids=None,
137 page=1,
137 page=1,
138 items_per_page=50,
138 items_per_page=50,
139 order_by=None,
139 order_by=None,
140 filter_settings=None,
140 filter_settings=None,
141 limit=None,
141 limit=None,
142 ):
142 ):
143 if not app_ids:
143 if not app_ids:
144 return {}, 0
144 return {}, 0
@@ -171,15 +171,15 b' class LogService(BaseService):'
171
171
172 @classmethod
172 @classmethod
173 def get_paginator_by_app_ids(
173 def get_paginator_by_app_ids(
174 cls,
174 cls,
175 app_ids=None,
175 app_ids=None,
176 page=1,
176 page=1,
177 item_count=None,
177 item_count=None,
178 items_per_page=50,
178 items_per_page=50,
179 order_by=None,
179 order_by=None,
180 filter_settings=None,
180 filter_settings=None,
181 exclude_columns=None,
181 exclude_columns=None,
182 db_session=None,
182 db_session=None,
183 ):
183 ):
184 if not filter_settings:
184 if not filter_settings:
185 filter_settings = {}
185 filter_settings = {}
@@ -74,7 +74,7 b' class ReportGroupService(BaseService):'
74 }
74 }
75 },
75 },
76 "query": {
76 "query": {
77 "filtered": {
77 "bool": {
78 "filter": {
78 "filter": {
79 "and": [
79 "and": [
80 {
80 {
@@ -96,7 +96,7 b' class ReportGroupService(BaseService):'
96 },
96 },
97 }
97 }
98 if tags:
98 if tags:
99 es_query["query"]["filtered"]["filter"]["and"].extend(tags)
99 es_query["query"]["bool"]["filter"]["and"].extend(tags)
100
100
101 result = Datastores.es.search(
101 result = Datastores.es.search(
102 body=es_query, index=index_names, doc_type="log", size=0
102 body=es_query, index=index_names, doc_type="log", size=0
@@ -135,7 +135,9 b' class ReportGroupService(BaseService):'
135 query = {
135 query = {
136 "size": 0,
136 "size": 0,
137 "query": {
137 "query": {
138 "filtered": {
138 "bool": {
139 "must": [],
140 "should": [],
139 "filter": {"and": [{"terms": {"resource_id": list(app_ids)}}]}
141 "filter": {"and": [{"terms": {"resource_id": list(app_ids)}}]}
140 }
142 }
141 },
143 },
@@ -158,7 +160,7 b' class ReportGroupService(BaseService):'
158
160
159 start_date = filter_settings.get("start_date")
161 start_date = filter_settings.get("start_date")
160 end_date = filter_settings.get("end_date")
162 end_date = filter_settings.get("end_date")
161 filter_part = query["query"]["filtered"]["filter"]["and"]
163 filter_part = query["query"]["bool"]["filter"]["and"]
162 date_range = {"range": {"start_time": {}}}
164 date_range = {"range": {"start_time": {}}}
163 if start_date:
165 if start_date:
164 date_range["range"]["start_time"]["gte"] = start_date
166 date_range["range"]["start_time"]["gte"] = start_date
@@ -224,19 +226,19 b' class ReportGroupService(BaseService):'
224 messages = filter_settings.get("message")
226 messages = filter_settings.get("message")
225 if messages:
227 if messages:
226 condition = {"match": {"message": " ".join(messages)}}
228 condition = {"match": {"message": " ".join(messages)}}
227 query["query"]["filtered"]["query"] = condition
229 query["query"]["bool"]["must"].append(condition)
228 errors = filter_settings.get("error")
230 errors = filter_settings.get("error")
229 if errors:
231 if errors:
230 condition = {"match": {"error": " ".join(errors)}}
232 condition = {"match": {"error": " ".join(errors)}}
231 query["query"]["filtered"]["query"] = condition
233 query["query"]["bool"]["must"].append(condition)
232 url_domains = filter_settings.get("url_domain")
234 url_domains = filter_settings.get("url_domain")
233 if url_domains:
235 if url_domains:
234 condition = {"terms": {"url_domain": url_domains}}
236 condition = {"terms": {"url_domain": url_domains}}
235 query["query"]["filtered"]["query"] = condition
237 query["query"]["bool"]["must"].append(condition)
236 url_paths = filter_settings.get("url_path")
238 url_paths = filter_settings.get("url_path")
237 if url_paths:
239 if url_paths:
238 condition = {"terms": {"url_path": url_paths}}
240 condition = {"terms": {"url_path": url_paths}}
239 query["query"]["filtered"]["query"] = condition
241 query["query"]["bool"]["must"].append(condition)
240
242
241 if filter_settings.get("report_status"):
243 if filter_settings.get("report_status"):
242 for status in filter_settings.get("report_status"):
244 for status in filter_settings.get("report_status"):
@@ -464,7 +466,7 b' class ReportGroupService(BaseService):'
464 }
466 }
465 },
467 },
466 "query": {
468 "query": {
467 "filtered": {
469 "bool": {
468 "filter": {
470 "filter": {
469 "and": [
471 "and": [
470 {
472 {
@@ -42,7 +42,7 b' class ReportStatService(BaseService):'
42 }
42 }
43 },
43 },
44 "query": {
44 "query": {
45 "filtered": {
45 "bool": {
46 "filter": {
46 "filter": {
47 "and": [
47 "and": [
48 {"terms": {"resource_id": [resource_id]}},
48 {"terms": {"resource_id": [resource_id]}},
@@ -140,7 +140,7 b' class RequestMetricService(BaseService):'
140 }
140 }
141 },
141 },
142 "query": {
142 "query": {
143 "filtered": {
143 "bool": {
144 "filter": {
144 "filter": {
145 "and": [
145 "and": [
146 {
146 {
@@ -208,7 +208,7 b' class RequestMetricService(BaseService):'
208 }
208 }
209 },
209 },
210 "query": {
210 "query": {
211 "filtered": {
211 "bool": {
212 "filter": {
212 "filter": {
213 "and": [
213 "and": [
214 {
214 {
@@ -287,7 +287,7 b' class RequestMetricService(BaseService):'
287 }
287 }
288 },
288 },
289 "query": {
289 "query": {
290 "filtered": {
290 "bool": {
291 "filter": {
291 "filter": {
292 "and": [
292 "and": [
293 {
293 {
@@ -331,7 +331,7 b' class RequestMetricService(BaseService):'
331 },
331 },
332 }
332 }
333 },
333 },
334 "query": {"filtered": {"filter": {"and": and_part}}},
334 "query": {"bool": {"filter": {"and": and_part}}},
335 }
335 }
336 details = {}
336 details = {}
337 index_names = es_index_name_limiter(ixtypes=["reports"])
337 index_names = es_index_name_limiter(ixtypes=["reports"])
@@ -461,7 +461,7 b' class RequestMetricService(BaseService):'
461 }
461 }
462 },
462 },
463 "query": {
463 "query": {
464 "filtered": {
464 "bool": {
465 "filter": {
465 "filter": {
466 "and": [
466 "and": [
467 {
467 {
@@ -540,7 +540,7 b' class RequestMetricService(BaseService):'
540 }
540 }
541 },
541 },
542 "query": {
542 "query": {
543 "filtered": {
543 "bool": {
544 "filter": {
544 "filter": {
545 "and": [
545 "and": [
546 {
546 {
@@ -67,7 +67,7 b' class SlowCallService(BaseService):'
67 }
67 }
68 },
68 },
69 "query": {
69 "query": {
70 "filtered": {
70 "bool": {
71 "filter": {
71 "filter": {
72 "and": [
72 "and": [
73 {
73 {
@@ -109,7 +109,7 b' class SlowCallService(BaseService):'
109 }
109 }
110 },
110 },
111 "query": {
111 "query": {
112 "filtered": {
112 "bool": {
113 "filter": {
113 "filter": {
114 "and": [
114 "and": [
115 {
115 {
@@ -147,14 +147,14 b' def common_tags(request):'
147 resources = list(filter_settings["resource"])
147 resources = list(filter_settings["resource"])
148 query = {
148 query = {
149 "query": {
149 "query": {
150 "filtered": {
150 "bool": {
151 "filter": {"and": [{"terms": {"resource_id": list(resources)}}]}
151 "filter": {"and": [{"terms": {"resource_id": list(resources)}}]}
152 }
152 }
153 }
153 }
154 }
154 }
155 start_date = filter_settings.get("start_date")
155 start_date = filter_settings.get("start_date")
156 end_date = filter_settings.get("end_date")
156 end_date = filter_settings.get("end_date")
157 filter_part = query["query"]["filtered"]["filter"]["and"]
157 filter_part = query["query"]["bool"]["filter"]["and"]
158
158
159 date_range = {"range": {"timestamp": {}}}
159 date_range = {"range": {"timestamp": {}}}
160 if start_date:
160 if start_date:
@@ -206,7 +206,7 b' def common_values(request):'
206 and_part.append({"terms": {"namespace": filter_settings["namespace"]}})
206 and_part.append({"terms": {"namespace": filter_settings["namespace"]}})
207 query = {
207 query = {
208 "query": {
208 "query": {
209 "filtered": {
209 "bool": {
210 "filter": {
210 "filter": {
211 "and": and_part
211 "and": and_part
212 }
212 }
General Comments 0
You need to be logged in to leave comments. Login now