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

            (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}}))

  "Creates a bulk operation to index a document in ES."
  ([source]
     (doc-bulk-index (:_type source) (:_id source) source))
  ([type-name id source]
     (doc-bulk-index (:_index source) type-name id source))
  ([index-name type-name id source]
     {:pre [(or (nil? index-name)
                (valid-index-name? index-name))
            (or (nil? (:_index source))
                (and (valid-index-name? (:_index source))
                     (or (nil? index-name)
                         (= index-name (:_index source)))))
            (valid-type-name? type-name)
            (or (nil? (:_type source))
                (and (valid-type-name? (:_type source))
                     (= (name type-name) (:_type source))))
            (valid-id? id)
            (or (nil? (:_id source))
                (and (valid-id? (:_id source))
