@@ -215,6 +215,7 @@ dispatch dMethod url body = do
215 $ setRequestIgnoreStatus
215 $ setRequestIgnoreStatus
216 $ initReq { method = dMethod
216 $ initReq { method = dMethod
217 , requestHeaders =
217 , requestHeaders =
218+ -- "application/x-ndjson" for bulk
218 ("Content-Type", "application/json") : requestHeaders initReq
219 ("Content-Type", "application/json") : requestHeaders initReq
219 , requestBody = reqBody }
220 , requestBody = reqBody }
220 -- req <- liftIO $ reqHook $ setRequestIgnoreStatus $ initReq { method = dMethod
221 -- req <- liftIO $ reqHook $ setRequestIgnoreStatus $ initReq { method = dMethod
@@ -856,7 +857,9 @@ deleteDocument (IndexName indexName)
856-- >>> _ <- runBH' $ bulk stream
857-- >>> _ <- runBH' $ bulk stream
857-- >>> _ <- runBH' $ refreshIndex testIndex
858-- >>> _ <- runBH' $ refreshIndex testIndex
858bulk :: MonadBH m => V.Vector BulkOperation -> m Reply
859bulk :: MonadBH m => V.Vector BulkOperation -> m Reply
859−bulk bulkOps = bindM2 post url (return body)
862+ bindM2 post url (return body)
860 where url = joinPath ["_bulk"]
863 where url = joinPath ["_bulk"]
861 body = Just $ encodeBulkOperations bulkOps
864 body = Just $ encodeBulkOperations bulkOps
@@ -868,9 +871,12 @@ bulk bulkOps = bindM2 post url (return body)
868-- "\n{\"index\":{\"_type\":\"tweet\",\"_id\":\"2\",\"_index\":\"twitter\"}}\n{\"name\":\"blah\"}\n"
871-- "\n{\"index\":{\"_type\":\"tweet\",\"_id\":\"2\",\"_index\":\"twitter\"}}\n{\"name\":\"blah\"}\n"
869encodeBulkOperations :: V.Vector BulkOperation -> L.ByteString
872encodeBulkOperations :: V.Vector BulkOperation -> L.ByteString
870encodeBulkOperations stream = collapsed where
873encodeBulkOperations stream = collapsed where
871− blobs = fmap encodeBulkOperation stream
875+ fmap encodeBulkOperation stream
872− mashedTaters = mash (mempty :: Builder) blobs
877+ mash (mempty :: Builder) blobs
873− collapsed = toLazyByteString $ mappend mashedTaters (byteString "\n")
879+ toLazyByteString $ mappend mashedTaters (byteString "\n")
875mash :: Builder -> V.Vector L.ByteString -> Builder
881mash :: Builder -> V.Vector L.ByteString -> Builder
876mash = V.foldl' (\b x -> b `mappend` (byteString "\n") `mappend` (lazyByteString x))
882mash = V.foldl' (\b x -> b `mappend` (byteString "\n") `mappend` (lazyByteString x))