graphite: Reorganize the elastic search code so we can put it in chromite.

This change reorganizes the elastic search integration code so that it's
separate from the code that, for instance, reads config information from the
autotest global config. That way, it can be moved from chromite without
breaking any dependencies.

BUG=chromium:446291
TEST=Ran stats_es_functionaltest.py. Ran unit tests. Ran a butterfly-paladin
tryjob with --hwtest.

Change-Id: I0dbf135c4f1732d633e5fc9d5edb9e1f4f7199d5
Reviewed-on: https://chromium-review.googlesource.com/242701
Reviewed-by: Dan Shi <dshi@chromium.org>
Tested-by: Gabe Black <gabeblack@chromium.org>
Commit-Queue: Gabe Black <gabeblack@chromium.org>
diff --git a/site_utils/es_reindex.py b/site_utils/es_reindex.py
index 887a207..8a21a38 100755
--- a/site_utils/es_reindex.py
+++ b/site_utils/es_reindex.py
@@ -26,7 +26,7 @@
 import common
 from elasticsearch import Elasticsearch
 from elasticsearch import helpers
-from autotest_lib.client.common_lib.cros.graphite import es_utils
+from autotest_lib.client.common_lib.cros.graphite import autotest_es
 
 
 def main():
@@ -48,10 +48,10 @@
     query = {'query' : {'match_all' : {}},
              'size': 1}
 
-    result = es_utils.execute_query(query, options.old, options.host,
-                                    options.port)
-    count = result['hits']['total']
-    print 'Total number of records in index %s: %d' % (options.old, count)
+    result = autotest_es.execute_query(index=options.old, host=options.host,
+                                       port=options.port, query)
+    print 'Total number of records in index %s: %d' % (options.old,
+                                                       result.total)
 
     print ('Re-index: %s to index: %s for server %s:%s' %
            (options.old, options.new, options.host, options.port))
@@ -61,11 +61,10 @@
     print 'reindex completed.'
 
     print 'Checking records in the new index...'
-    result = es_utils.execute_query(query, options.new, options.host,
-                                    options.port)
-    count_new = result['hits']['total']
+    result = es.execute_query(index=options.new, host=options.host,
+                              port=options.port, query)
     print 'Total number of records in index %s: %d' % (options.new,
-                                                       count_new)
+                                                       result.total)
 
     # count_new can be larger than count if new records are added during
     # reindexing. This check only tries to make sure no record was lost.