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