sinkStoreElasticsearch :: (MonadThrow m, MonadIO m)
                       => Int -> Bool -> H.HashMap T.Text [T.Text] -> Request -> Manager
                       -> Consumer (D.PackageDescription, UTCTime) m ()
sinkStoreElasticsearch cs progress dpr req' mgr = do
    let req = req' { method = "POST" }
    fix $ \loop -> do
        chunk <- CL.take cs
        let cmd i = JSON.object ["index" .= JSON.object ["_id" .= (i :: String)]]
            body = L.unlines . map JSON.encode $ concatMap (\(p,upd) ->
                let pkg = D.display . D.pkgName $ D.package p in
                [ cmd pkg
                , pdToValue p upd (H.lookup (T.pack pkg) dpr)
                ]) chunk
        unless (null chunk) $ do
            _ <- liftIO $ httpLbs req { requestBody = RequestBodyLBS body } mgr
            when progress . liftIO $ putChar '.' >> hFlush stdout
            loop
sinkStoreElasticsearch :: (MonadThrow m, MonadIO m)
                       => Int -> Bool -> H.HashMap T.Text [T.Text] -> Request -> Manager
                       -> Consumer (D.PackageDescription, UTCTime) m ()
sinkStoreElasticsearch cs progress dpr req' mgr = do
    let req = req' { method = "POST" }
    fix $ \loop -> do
        chunk <- CL.take cs
        let cmd i = JSON.object ["index" .= JSON.object ["_id" .= (i :: String)]]
            body = L.unlines . map JSON.encode $ concatMap (\(p,upd) ->
                let pkg = D.display . D.pkgName $ D.package p in
                [ cmd pkg
                , pdToValue p upd (H.lookup (T.pack pkg) dpr)
                ]) chunk
        unless (null chunk) $ do
            _ <- liftIO $ httpLbs req { requestBody = RequestBodyLBS body } mgr
            when progress . liftIO $ putChar '.' >> hFlush stdout
            loop
sinkStoreElasticsearch cs progress dpr req' mgr = do
    let req = req' { method = "POST" }
    fix $ \loop -> do
        chunk <- CL.take cs
        let cmd i = JSON.object ["index" .= JSON.object ["_id" .= (i :: String)]]
            body = L.unlines . map JSON.encode $ concatMap (\(p,upd) ->
                let pkg = D.display . D.pkgName $ D.package p in
                [ cmd pkg
                , pdToValue p upd (H.lookup (T.pack pkg) dpr)
                ]) chunk
        unless (null chunk) $ do
            _ <- liftIO $ httpLbs req { requestBody = RequestBodyLBS body } mgr
            when progress . liftIO $ putChar '.' >> hFlush stdout
            loop