Merge "no more output elastic docs to stdout/console"
authorMorgan Richomme <morgan.richomme@orange.com>
Wed, 28 Sep 2016 07:42:30 +0000 (07:42 +0000)
committerGerrit Code Review <gerrit@172.30.200.206>
Wed, 28 Sep 2016 07:42:31 +0000 (07:42 +0000)
utils/test/dashboard/dashboard/common/elastic_access.py
utils/test/dashboard/dashboard/mongo2elastic/main.py

index c95a87b..8c6494d 100644 (file)
@@ -43,25 +43,3 @@ def get_docs(url, creds=None, body=None, field='_source'):
     for hit in res_data['hits']['hits']:
         docs.append(hit[field])
     return docs
-
-
-def get_elastic_docs_by_days(elastic_url, creds, days):
-    if days == 0:
-        body = '''{
-            "query": {
-                "match_all": {}
-            }
-        }'''
-    elif days > 0:
-        body = '''{{
-            "query" : {{
-                "range" : {{
-                    "start_date" : {{
-                        "gte" : "now-{}d"
-                    }}
-                }}
-            }}
-        }}'''.format(days)
-    else:
-        raise Exception('Update days must be non-negative')
-    return get_docs(elastic_url, creds, body)
index 33a70e4..76efb14 100644 (file)
@@ -199,7 +199,36 @@ class DocumentsPublisher:
             exit(-1)
 
     def get_existed_docs(self):
-        self.existed_docs = elastic_access.get_elastic_docs_by_days(self.elastic_url, self.creds, self.days)
+        if self.days == 0:
+            body = '''{{
+                        "query": {{
+                            "bool": {{
+                                "must": [
+                                    {{ "match": {{ "project_name": "{}" }} }},
+                                    {{ "match": {{ "case_name": "{}" }} }}
+                                ]
+                            }}
+                        }}
+                    }}'''.format(self.project, self.case)
+        elif self.days > 0:
+            body = '''{{
+                       "query": {{
+                           "bool": {{
+                               "must": [
+                                   {{ "match": {{ "project_name": "{}" }} }},
+                                   {{ "match": {{ "case_name": "{}" }} }}
+                               ],
+                               "filter": {{
+                                   "range": {{
+                                       "start_date": {{ "gte": "now-{}d" }}
+                                   }}
+                               }}
+                           }}
+                       }}
+                   }}'''.format(self.project, self.case, self.days)
+        else:
+            raise Exception('Update days must be non-negative')
+        self.existed_docs = elastic_access.get_docs(self.elastic_url, self.creds, body)
         return self
 
     def publish(self):