Add an update_field_in_doc method
authorJonathan Griffin <jgriffin@mozilla.com>
Mon, 16 May 2011 13:43:49 -0700
changeset 27 6663e2d811b469f20d00432272e9b78b38395ee8
parent 26 222935a2a23a04d927ea6272b018f1924cb8638d
child 28 ccb8ae2df8567fbbb3ae1ff9e7286450f1a12fa1
push id28
push userjgriffin@mozilla.com
push dateMon, 16 May 2011 20:44:07 +0000
Add an update_field_in_doc method
mozautoeslib/autolog.py
mozautoeslib/eslib.py
--- a/mozautoeslib/autolog.py
+++ b/mozautoeslib/autolog.py
@@ -394,20 +394,22 @@ class AutologTestGroup(object):
 
         # gzip the contents into a string buffer
         buffer = StringIO.StringIO()
         gzip_fh = gzip.GzipFile(fileobj=buffer, mode='w+b')
         gzip_fh.write(contents)
         gzip_fh.close()
 
         # post the gzipped buffer to the autolog server
-        host = "%s/savelog?id=%s&index=%s&doc_type=%s" % (self.restserver,
-                                              logfile[0].id,
-                                              self.index,
-                                              logfile[0].doc_type)
+        host = "%s/savelog?id=%s&index=%s&doc_type=%s&server=%s" % \
+            (self.restserver,
+             logfile[0].id,
+             self.index,
+             logfile[0].doc_type,
+             self.server)
         req = urllib2.Request(host,
                               buffer.getvalue(),
                               {'content-type': 'application/gzip'})
         response_stream = urllib2.urlopen(req)
         response = json.loads(response_stream.read())
         buffer.close()
 
   def _elasticsearch_submit(self):
--- a/mozautoeslib/eslib.py
+++ b/mozautoeslib/eslib.py
@@ -232,16 +232,22 @@ class ESLib(object):
 
     raise Exception("Key 'facets' not found in response data")
 
   def delete_doc(self, id, doc_type=None):
     if doc_type:
       self.doc_type = doc_type
     self.connection.delete(self.index, self.doc_type[0], id)
 
+  def update_field_in_doc(self, id, doc_type, field, value):
+    doc = self.connection.get(self.index, doc_type, id)
+    doc = doc.get('_source')
+    doc[field] = value
+    self.add_doc(doc, id=id, doc_type=doc_type)
+
   def add_doc(self, doc, id=None, doc_type=None):
     if doc_type:
       self.doc_type = doc_type
     return self.connection.index(doc, self.index, self.doc_type[0], id)
 
   def delete_index(self):
     try:
       return self.connection.delete_index(self.index)