    [cmr.common.services.errors :as errors]
    [cmr.common.time-keeper :as tk]
    [cmr.common.util :as util]
+   [cmr.elastic-utils.es-helper :as es-helper]
    [cmr.indexer.data.elasticsearch :as es]
    [cmr.indexer.services.index-service :as index-service]
    [cmr.redis-utils.redis-cache :as redis-cache]
+   [cmr.transmit.cache.consistent-cache :as consistent-cache]
    [cmr.transmit.metadata-db :as meta-db]))
 
 (def coll-gran-aggregate-cache-key

   [clj-time.core :as t]
   [clj-time.format :as f]
   [clojurewerkz.elastisch.query :as esq]
   [clojurewerkz.elastisch.rest.document :as esd]
   [cmr.transmit.cache.consistent-cache :as consistent-cache]
   [cmr.common-app.services.search.datetime-helper :as datetime-helper]
   [cmr.common.cache :as c]
   [cmr.common.cache.fallback-cache :as fallback-cache]

  "Searches across all the granule indexes to aggregate by collection. Returns a map of collection
   concept id to collection information. The collection will only be in the map if it has granules."
  [context]
  (-> (es-helper/search (es/context->conn context)
                        "1_small_collections,1_c*" ;; Searching all granule indexes
                        ["granule"] ;; With the granule type.
                        {:query (esq/match-all)
                         :size 0
                         :aggs collection-aggregations})
      parse-aggregations))

(defn- fetch-coll-gran-aggregates-updated-in-last-n
