   [es index-name doc & {:keys [stream?] :as options}]
   {:pre [(doc-type doc) (or (nil? (doc-id doc)) (valid-id? (doc-id doc)))]}
   (let [body ((if stream? piped-json-body json-body) doc)
-        type (doc-type doc)]
+        type-name (doc-type doc)]
     (if-let [id (doc-id doc)]
-      (http-put (url es index-name type id "_create") body)
-      (http-post (url es index-name type) body))))
+      (http-put (url es index-name type-name id "_create") body)
+      (http-post (url es index-name type-name) body))))
 
 (defn doc-index
   "Index doc in index-name using the ES index operation (creates it if it

            (nil? (get source "_index"))
            (nil? (get source "_type"))
            (nil? (get source "_id"))]}
     {:index (merge {:_type (name type) :_id id :source source}
                    (when index-name
                      {:_index index-name}))}))

(defn doc-bulk-delete
  "Creates a bulk operation to delete a document in ES."
  ([type id]
     {:pre [(valid-type? type) (valid-id? id)]}
     {:delete {:_type type :_id id}})
  ([index-name type id]
     {:pre [(valid-index-name? index-name) (valid-type? type) (valid-id? id)]}
     {:delete {:_index index-name :_type type :_id id}}))

  (http-get (url es (index-list-str index-names) "_mapping")))

(defn mapping-put
  "Puts mapping for index-name and type-name."
  [es index-name type-name mapping]
  {:pre [es (valid-index-name? index-name) (valid-type-name? type-name)]}
  (ok? (http-put (url es index-name type-name "_mapping")
                 (json-body (select-keys mapping [type-name])))))

(defn search-once* [es index-names query options]
  {:pre [es]}
