@@ -137,7 +137,7 @@ mkReplicaCount n
137emptyBody :: L.ByteString
137emptyBody :: L.ByteString
138emptyBody = L.pack ""
138emptyBody = L.pack ""
140−dispatch :: MonadBloodhound m => Method -> String -> Maybe L.ByteString
140+dispatch :: MonadBH m => Method -> String -> Maybe L.ByteString
141 -> m Reply
141 -> m Reply
142dispatch dMethod url body = do
142dispatch dMethod url body = do
143 initReq <- liftIO $ parseUrl url
143 initReq <- liftIO $ parseUrl url
@@ -151,7 +151,7 @@ dispatch dMethod url body = do
151joinPath' :: [String] -> String
151joinPath' :: [String] -> String
152joinPath' = intercalate "/"
152joinPath' = intercalate "/"
154−joinPath :: MonadBloodhound m => [String] -> m String
154+joinPath :: MonadBH m => [String] -> m String
155joinPath ps = do
155joinPath ps = do
156 Server s <- bhServer <$> getBHEnv
156 Server s <- bhServer <$> getBHEnv
157 return $ joinPath' (s:ps)
157 return $ joinPath' (s:ps)
@@ -169,15 +169,15 @@ withBH ms s f = withManager ms $ \mgr -> do
169 runReaderT f env
169 runReaderT f env
171-- Shortcut functions for HTTP methods
171-- Shortcut functions for HTTP methods
172−delete :: MonadBloodhound m => String -> m Reply
172+delete :: MonadBH m => String -> m Reply
173delete = flip (dispatch NHTM.methodDelete) Nothing
173delete = flip (dispatch NHTM.methodDelete) Nothing
174−get :: MonadBloodhound m => String -> m Reply
174+get :: MonadBH m => String -> m Reply
175get = flip (dispatch NHTM.methodGet) Nothing
175get = flip (dispatch NHTM.methodGet) Nothing
176−head :: MonadBloodhound m => String -> m Reply
176+head :: MonadBH m => String -> m Reply
177head = flip (dispatch NHTM.methodHead) Nothing
177head = flip (dispatch NHTM.methodHead) Nothing
178−put :: MonadBloodhound m => String -> Maybe L.ByteString -> m Reply
178+put :: MonadBH m => String -> Maybe L.ByteString -> m Reply
179put = dispatch NHTM.methodPost
179put = dispatch NHTM.methodPost
180−post :: MonadBloodhound m => String -> Maybe L.ByteString -> m Reply
180+post :: MonadBH m => String -> Maybe L.ByteString -> m Reply
181post = dispatch NHTM.methodPost
181post = dispatch NHTM.methodPost
183-- indexDocument s ix name doc = put (root </> s </> ix </> name </> doc) (Just encode doc)
183-- indexDocument s ix name doc = put (root </> s </> ix </> name </> doc) (Just encode doc)
@@ -189,7 +189,7 @@ post = dispatch NHTM.methodPost
189-- >>> serverStatus <- runBH getStatus
189-- >>> serverStatus <- runBH getStatus
190-- >>> fmap status (serverStatus)
190-- >>> fmap status (serverStatus)
191-- Just 200
191-- Just 200
192−getStatus :: MonadBloodhound m => m (Maybe Status)
192+getStatus :: MonadBH m => m (Maybe Status)
193getStatus = do
193getStatus = do
194 url <- joinPath []
194 url <- joinPath []
195 request <- liftIO $ parseUrl url
195 request <- liftIO $ parseUrl url
@@ -204,7 +204,7 @@ getStatus = do
205-- >>> runBH $ indexExists (IndexName "didimakeanindex")
205-- >>> runBH $ indexExists (IndexName "didimakeanindex")
207−createIndex :: MonadBloodhound m => IndexSettings -> IndexName -> m Reply
207+createIndex :: MonadBH m => IndexSettings -> IndexName -> m Reply
208createIndex indexSettings (IndexName indexName) =
208createIndex indexSettings (IndexName indexName) =
209 bindM2 put url (return body)
209 bindM2 put url (return body)
210 where url = joinPath [indexName]
210 where url = joinPath [indexName]
@@ -218,7 +218,7 @@ createIndex indexSettings (IndexName indexName) =
219-- >>> runBH $ indexExists testIndex
219-- >>> runBH $ indexExists testIndex
221−deleteIndex :: MonadBloodhound m => IndexName -> m Reply
221+deleteIndex :: MonadBH m => IndexName -> m Reply
222deleteIndex (IndexName indexName) =
222deleteIndex (IndexName indexName) =
223 delete =<< joinPath [indexName]
223 delete =<< joinPath [indexName]
@@ -228,7 +228,7 @@ statusCodeIs n resp = NHTS.statusCode (responseStatus resp) == n
228respIsTwoHunna :: Reply -> Bool
228respIsTwoHunna :: Reply -> Bool
229respIsTwoHunna = statusCodeIs 200
229respIsTwoHunna = statusCodeIs 200
231−existentialQuery :: MonadBloodhound m => String -> m (Reply, Bool)
231+existentialQuery :: MonadBH m => String -> m (Reply, Bool)
232existentialQuery url = do
232existentialQuery url = do
233 reply <- head url
233 reply <- head url
234 return (reply, respIsTwoHunna reply)
234 return (reply, respIsTwoHunna reply)
@@ -237,7 +237,7 @@ existentialQuery url = do
239-- >>> exists <- runBH $ indexExists testIndex
239-- >>> exists <- runBH $ indexExists testIndex
240−indexExists :: MonadBloodhound m => IndexName -> m Bool
240+indexExists :: MonadBH m => IndexName -> m Bool
241indexExists (IndexName indexName) = do
241indexExists (IndexName indexName) = do
242 (_, exists) <- existentialQuery =<< joinPath [indexName]
242 (_, exists) <- existentialQuery =<< joinPath [indexName]
243 return exists
243 return exists
@@ -247,7 +247,7 @@ indexExists (IndexName indexName) = do
248-- >>> _ <- runBH $ createIndex defaultIndexSettings testIndex
248-- >>> _ <- runBH $ createIndex defaultIndexSettings testIndex
249-- >>> _ <- runBH $ refreshIndex testIndex
249-- >>> _ <- runBH $ refreshIndex testIndex
250−refreshIndex :: MonadBloodhound m => IndexName -> m Reply
250+refreshIndex :: MonadBH m => IndexName -> m Reply
251refreshIndex (IndexName indexName) =
251refreshIndex (IndexName indexName) =
252 bindM2 post url (return Nothing)
252 bindM2 post url (return Nothing)
253 where url = joinPath [indexName, "_refresh"]
253 where url = joinPath [indexName, "_refresh"]
@@ -257,7 +257,7 @@ stringifyOCIndex oci = case oci of
257 OpenIndex -> "_open"
257 OpenIndex -> "_open"
258 CloseIndex -> "_close"
258 CloseIndex -> "_close"
260−openOrCloseIndexes :: MonadBloodhound m => OpenCloseIndex -> IndexName -> m Reply
260+openOrCloseIndexes :: MonadBH m => OpenCloseIndex -> IndexName -> m Reply
261openOrCloseIndexes oci (IndexName indexName) =
261openOrCloseIndexes oci (IndexName indexName) =
262 bindM2 post url (return Nothing)
262 bindM2 post url (return Nothing)
263 where ociString = stringifyOCIndex oci
263 where ociString = stringifyOCIndex oci
@@ -267,14 +267,14 @@ openOrCloseIndexes oci (IndexName indexName) =
267-- <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
267-- <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
269-- >>> reply <- runBH $ openIndex testIndex
269-- >>> reply <- runBH $ openIndex testIndex
270−openIndex :: MonadBloodhound m => IndexName -> m Reply
270+openIndex :: MonadBH m => IndexName -> m Reply
271openIndex = openOrCloseIndexes OpenIndex
271openIndex = openOrCloseIndexes OpenIndex
273-- | 'closeIndex' closes an index given a 'Server' and an 'IndexName'. Explained in further detail at
273-- | 'closeIndex' closes an index given a 'Server' and an 'IndexName'. Explained in further detail at
274-- <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
274-- <http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-open-close.html>
276-- >>> reply <- runBH $ closeIndex testIndex
276-- >>> reply <- runBH $ closeIndex testIndex
277−closeIndex :: MonadBloodhound m => IndexName -> m Reply
277+closeIndex :: MonadBH m => IndexName -> m Reply
278closeIndex = openOrCloseIndexes CloseIndex
278closeIndex = openOrCloseIndexes CloseIndex
280-- | 'putMapping' is an HTTP PUT and has upsert semantics. Mappings are schemas
280-- | 'putMapping' is an HTTP PUT and has upsert semantics. Mappings are schemas
@@ -284,7 +284,7 @@ closeIndex = openOrCloseIndexes CloseIndex
284-- >>> resp <- runBH $ putMapping testIndex testMapping TweetMapping
284-- >>> resp <- runBH $ putMapping testIndex testMapping TweetMapping
285-- >>> print resp
285-- >>> print resp
286-- Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","21")], responseBody = "{\"acknowledged\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
286-- Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","21")], responseBody = "{\"acknowledged\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
287−putMapping :: (MonadBloodhound m, ToJSON a) => IndexName
287+putMapping :: (MonadBH m, ToJSON a) => IndexName
288 -> MappingName -> a -> m Reply
288 -> MappingName -> a -> m Reply
289putMapping (IndexName indexName) (MappingName mappingName) mapping =
289putMapping (IndexName indexName) (MappingName mappingName) mapping =
290 bindM2 put url (return body)
290 bindM2 put url (return body)
@@ -299,7 +299,7 @@ putMapping (IndexName indexName) (MappingName mappingName) mapping =
299-- >>> resp <- runBH $ deleteMapping testIndex testMapping
299-- >>> resp <- runBH $ deleteMapping testIndex testMapping
300-- >>> print resp
300-- >>> print resp
301-- Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","21")], responseBody = "{\"acknowledged\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
301-- Response {responseStatus = Status {statusCode = 200, statusMessage = "OK"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","21")], responseBody = "{\"acknowledged\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
302−deleteMapping :: MonadBloodhound m => IndexName -> MappingName -> m Reply
302+deleteMapping :: MonadBH m => IndexName -> MappingName -> m Reply
303deleteMapping (IndexName indexName)
303deleteMapping (IndexName indexName)
304 (MappingName mappingName) =
304 (MappingName mappingName) =
305 delete =<< joinPath [indexName, mappingName, "_mapping"]
305 delete =<< joinPath [indexName, mappingName, "_mapping"]
@@ -312,7 +312,7 @@ deleteMapping (IndexName indexName)
312-- >>> resp <- runBH $ indexDocument testIndex testMapping exampleTweet (DocId "1")
312-- >>> resp <- runBH $ indexDocument testIndex testMapping exampleTweet (DocId "1")
313-- >>> print resp
313-- >>> print resp
314-- Response {responseStatus = Status {statusCode = 201, statusMessage = "Created"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","74")], responseBody = "{\"_index\":\"twitter\",\"_type\":\"tweet\",\"_id\":\"1\",\"_version\":1,\"created\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
314-- Response {responseStatus = Status {statusCode = 201, statusMessage = "Created"}, responseVersion = HTTP/1.1, responseHeaders = [("Content-Type","application/json; charset=UTF-8"),("Content-Length","74")], responseBody = "{\"_index\":\"twitter\",\"_type\":\"tweet\",\"_id\":\"1\",\"_version\":1,\"created\":true}", responseCookieJar = CJ {expose = []}, responseClose' = ResponseClose}
315−indexDocument :: (ToJSON doc, MonadBloodhound m) => IndexName -> MappingName
315+indexDocument :: (ToJSON doc, MonadBH m) => IndexName -> MappingName
316 -> doc -> DocId -> m Reply
316 -> doc -> DocId -> m Reply
317indexDocument (IndexName indexName)
317indexDocument (IndexName indexName)
318 (MappingName mappingName) document (DocId docId) =
318 (MappingName mappingName) document (DocId docId) =
@@ -323,7 +323,7 @@ indexDocument (IndexName indexName)
323-- | 'deleteDocument' is the primary way to delete a single document.
323-- | 'deleteDocument' is the primary way to delete a single document.
325-- >>> _ <- runBH $ deleteDocument testIndex testMapping (DocId "1")
325-- >>> _ <- runBH $ deleteDocument testIndex testMapping (DocId "1")
326−deleteDocument :: MonadBloodhound m => IndexName -> MappingName
326+deleteDocument :: MonadBH m => IndexName -> MappingName
327 -> DocId -> m Reply
327 -> DocId -> m Reply
328deleteDocument (IndexName indexName)
328deleteDocument (IndexName indexName)
329 (MappingName mappingName) (DocId docId) =
329 (MappingName mappingName) (DocId docId) =
@@ -339,7 +339,7 @@ deleteDocument (IndexName indexName)
339-- >>> let stream = V.fromList [BulkIndex testIndex testMapping (DocId "2") (toJSON (BulkTest "blah"))]
339-- >>> let stream = V.fromList [BulkIndex testIndex testMapping (DocId "2") (toJSON (BulkTest "blah"))]
340-- >>> _ <- runBH $ bulk stream
340-- >>> _ <- runBH $ bulk stream
341-- >>> _ <- runBH $ refreshIndex testIndex
341-- >>> _ <- runBH $ refreshIndex testIndex
342−bulk :: MonadBloodhound m => V.Vector BulkOperation -> m Reply
342+bulk :: MonadBH m => V.Vector BulkOperation -> m Reply
343bulk bulkOps = bindM2 post url (return body)
343bulk bulkOps = bindM2 post url (return body)
344 where url = joinPath ["_bulk"]
344 where url = joinPath ["_bulk"]
345 body = Just $ encodeBulkOperations bulkOps
345 body = Just $ encodeBulkOperations bulkOps
@@ -403,7 +403,7 @@ encodeBulkOperation (BulkUpdate (IndexName indexName)
403-- The 'DocId' is the primary key for your Elasticsearch document.
403-- The 'DocId' is the primary key for your Elasticsearch document.
405-- >>> yourDoc <- runBH $ getDocument testIndex testMapping (DocId "1")
405-- >>> yourDoc <- runBH $ getDocument testIndex testMapping (DocId "1")
406−getDocument :: MonadBloodhound m => IndexName -> MappingName
406+getDocument :: MonadBH m => IndexName -> MappingName
407 -> DocId -> m Reply
407 -> DocId -> m Reply
408getDocument (IndexName indexName)
408getDocument (IndexName indexName)
409 (MappingName mappingName) (DocId docId) =
409 (MappingName mappingName) (DocId docId) =
@@ -413,7 +413,7 @@ getDocument (IndexName indexName)
415-- >>> exists <- runBH $ documentExists testIndex testMapping (DocId "1")
415-- >>> exists <- runBH $ documentExists testIndex testMapping (DocId "1")
416−documentExists :: MonadBloodhound m => IndexName -> MappingName
416+documentExists :: MonadBH m => IndexName -> MappingName
417 -> DocId -> m Bool
417 -> DocId -> m Bool
418documentExists (IndexName indexName)
418documentExists (IndexName indexName)
419 (MappingName mappingName) (DocId docId) = do
419 (MappingName mappingName) (DocId docId) = do
@@ -421,7 +421,7 @@ documentExists (IndexName indexName)
421 return exists
421 return exists
422 where url = joinPath [indexName, mappingName, docId]
422 where url = joinPath [indexName, mappingName, docId]
424−dispatchSearch :: MonadBloodhound m => String -> Search -> m Reply
424+dispatchSearch :: MonadBH m => String -> Search -> m Reply
425dispatchSearch url search = post url (Just (encode search))
425dispatchSearch url search = post url (Just (encode search))
427-- | 'searchAll', given a 'Search', will perform that search against all indexes
427-- | 'searchAll', given a 'Search', will perform that search against all indexes
@@ -430,7 +430,7 @@ dispatchSearch url search = post url (Just (encode search))
430-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
430-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
431-- >>> let search = mkSearch (Just query) Nothing
431-- >>> let search = mkSearch (Just query) Nothing
432-- >>> reply <- runBH $ searchAll search
432-- >>> reply <- runBH $ searchAll search
433−searchAll :: MonadBloodhound m => Search -> m Reply
433+searchAll :: MonadBH m => Search -> m Reply
434searchAll = bindM2 dispatchSearch url . return
434searchAll = bindM2 dispatchSearch url . return
435 where url = joinPath ["_search"]
435 where url = joinPath ["_search"]
@@ -440,7 +440,7 @@ searchAll = bindM2 dispatchSearch url . return
440-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
440-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
441-- >>> let search = mkSearch (Just query) Nothing
441-- >>> let search = mkSearch (Just query) Nothing
442-- >>> reply <- runBH $ searchByIndex testIndex search
442-- >>> reply <- runBH $ searchByIndex testIndex search
443−searchByIndex :: MonadBloodhound m => IndexName -> Search -> m Reply
443+searchByIndex :: MonadBH m => IndexName -> Search -> m Reply
444searchByIndex (IndexName indexName) = bindM2 dispatchSearch url . return
444searchByIndex (IndexName indexName) = bindM2 dispatchSearch url . return
445 where url = joinPath [indexName, "_search"]
445 where url = joinPath [indexName, "_search"]
@@ -450,7 +450,7 @@ searchByIndex (IndexName indexName) = bindM2 dispatchSearch url . return
450-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
450-- >>> let query = TermQuery (Term "user" "bitemyapp") Nothing
451-- >>> let search = mkSearch (Just query) Nothing
451-- >>> let search = mkSearch (Just query) Nothing
452-- >>> reply <- runBH $ searchByType testIndex testMapping search
452-- >>> reply <- runBH $ searchByType testIndex testMapping search
453−searchByType :: MonadBloodhound m => IndexName -> MappingName -> Search
453+searchByType :: MonadBH m => IndexName -> MappingName -> Search
454 -> m Reply
454 -> m Reply
455searchByType (IndexName indexName)
455searchByType (IndexName indexName)
456 (MappingName mappingName) = bindM2 dispatchSearch url . return
456 (MappingName mappingName) = bindM2 dispatchSearch url . return