git.iko.soy/typeable/bloodhound
on master help sign in
Merge branch 'master' of github.com:bitemyapp/bloodhound
commit9c4fc5dab97d67dacbf9670069f2d476885f2857 authorChris Allen <cma@bitemyapp.com> dateThu 3 Mar 2016, 01:07 (11 years ago) parent1fae7d4523e9be
2 files changed+20
src/Database/Bloodhound/Client.hs+14 tests/tests.hs+6
src/Database/Bloodhound/Client.hs+14
@@ -31,6 +31,7 @@ module Database.Bloodhound.Client
3131 , indexExists
3232 , openIndex
3333 , closeIndex
34+ , listIndices
3435 , updateIndexAliases
3536 , getIndexAliases
3637 , putTemplate
@@ -430,6 +431,19 @@ openIndex = openOrCloseIndexes OpenIndex
430431closeIndex :: MonadBH m => IndexName -> m Reply
431432closeIndex = openOrCloseIndexes CloseIndex
432433
434+-- | 'listIndices' returns a list of all index names on a given 'Server'
435+listIndices :: (MonadThrow m, MonadBH m) => m [IndexName]
436+listIndices =
437+ parse . responseBody =<< get =<< url
438+ where
439+ url = joinPath ["_cat/indices?v"]
440+ -- parses the tabular format the indices api provides
441+ parse body = case T.lines (T.decodeUtf8 (L.toStrict body)) of
442+ (hdr:rows) -> let ks = T.words hdr
443+ keyedRows = [ HM.fromList (zip ks (T.words row)) | row <- rows ]
444+ names = catMaybes (HM.lookup "index" <$> keyedRows)
445+ in return (IndexName <$> names)
446+ [] -> throwM (EsProtocolException body)
433447
434448-- | 'updateIndexAliases' updates the server's index alias
435449-- table. Operations are atomic. Explained in further detail at
tests/tests.hs+6
@@ -1426,6 +1426,12 @@ main = hspec $ do
14261426 L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
14271427 Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
14281428
1429+ describe "Index Listing" $ do
1430+ it "returns a list of index names" $ withTestEnv $ do
1431+ _ <- createExampleIndex
1432+ ixns <- listIndices
1433+ liftIO (ixns `shouldContain` [testIndex])
1434+
14291435 describe "Index Settings" $ do
14301436 it "persists settings" $ withTestEnv $ do
14311437 _ <- deleteExampleIndex