 (ns lcmap.aardvark.tile-spec-index
-  "Search index for tile-spec ubids (universal band ids)."
+  "Search index for tile-specs"
   (:require [lcmap.aardvark.config :refer [config]]
             [lcmap.aardvark.es :as es]
             [lcmap.aardvark.tile-spec :as tile-spec]

      tile-spec)))

(defn index-entry
   "Creates an index entry."
  [tile-spec]
  (str (json/write-str {"index" {"_retry_on_conflict" 3}}) "\n"
       (json/write-str tile-spec) "\n"))

(defn clear
  "Clears the tile-spec-index"
  []
  (es/clear! (url)))

(defn search
  "Submits a supplied query to the ubid index, which should conform to the
   elasticsearch query syntax. Returns a clojure dictionary of the raw results"
  ([query]
   (search (search-api-url) query))


  (str (server-url) "/" (index-name)))

(defn bulk-api-url
  "Returns the url to the bulk api"
  []
  (str (url) "/"
       (strip "/" (get-in config [:search :ubid-index-type])) "/_bulk"))
