   [tile-spec]
   (log/debugf "appending additional tags to tile-spec")
   (let [ubid-tags (str/split (:ubid tile-spec) #"/|_")]
-    (log/tracef "====> for tile-spec: %s" tile-spec)
     (if (> (count ubid-tags) 1)
       (update tile-spec :tags conj ubid-tags)
       tile-spec)))


  ([api-url query]
   (log/debugf "querying the index")
   (log/debugf "====> api-url: %s query: %s" api-url query)
   (es/search api-url query (get-in config [:search :max-result-size]))))

(defn result
  "Extracts tile-specs from search results"
  [search-results]
  (log/debugf "extracting tile-specs from search results")
  (log/tracef "====> for search-results: %s" search-results)
  (map #(get % "_source")
       (get-in search-results ["hits" "hits"])))

(defn save
  "Saves tile-specs to the ElasticSearch index."
  [tile-specs]
  (log/infof "saving index entries")
  (log/tracef "====> for tile-spec: %s" tile-specs)
  (es/load! (get-in config [:search :bulk-api-url])
            (pmap #(->> % +tags index-entry) (vectorize tile-specs)))
  tile-specs)

   "Converts a tile-spec to an index entry."
  [tile-spec]
  (log/debugf "converting tile-spec to index entry")
  (str (json/write-str {"index" {"_retry_on_conflict" 3}}) "\n"
       (json/write-str tile-spec) "\n"))

