git.iko.soy/typeable/bloodhound
on master help sign in
Use JSON format for parsing indices

This is for #220

commitb6f5b56d7baea1a89bf8c8039c11e5b967e720ac authorMichael Xavier <michael@michaelxavier.net> dateWed 31 Jan 2018, 19:16 (9 years ago) parenta4975b9
2 files changed+22−16
src/Database/V1/Bloodhound/Client.hs+11−8 src/Database/V5/Bloodhound/Client.hs+11−8
src/Database/V1/Bloodhound/Client.hs+11−8
@@ -583,14 +583,17 @@ listIndices :: (MonadThrow m, MonadBH m) => m [IndexName]
583583listIndices =
584584 parse . responseBody =<< get =<< url
585585 where
586− url = joinPath ["_cat/indices?v"]
587− -- parses the tabular format the indices api provides
588− parse body = case T.lines (T.decodeUtf8 (L.toStrict body)) of
589− (hdr:rows) -> let ks = T.words hdr
590− keyedRows = [ HM.fromList (zip ks (T.words row)) | row <- rows ]
591− names = catMaybes (HM.lookup "index" <$> keyedRows)
592− in return (IndexName <$> names)
593− [] -> throwM (EsProtocolException body)
586+ url = joinPath ["_cat/indices?format=json"]
587+ parse body = maybe (throwM (EsProtocolException body)) return $ do
588+ vals <- decode body
589+ forM vals $ \val -> do
590+ case val of
591+ Object obj -> do
592+ indexVal <- HM.lookup "index" obj
593+ case indexVal of
594+ String txt -> Just (IndexName txt)
595+ _ -> Nothing
596+ _ -> Nothing
594597
595598-- | 'updateIndexAliases' updates the server's index alias
596599-- table. Operations are atomic. Explained in further detail at
src/Database/V5/Bloodhound/Client.hs+11−8
@@ -699,14 +699,17 @@ listIndices :: (MonadThrow m, MonadBH m) => m [IndexName]
699699listIndices =
700700 parse . responseBody =<< get =<< url
701701 where
702− url = joinPath ["_cat/indices?v"]
703− -- parses the tabular format the indices api provides
704− parse body = case T.lines (T.decodeUtf8 (L.toStrict body)) of
705− (hdr:rows) -> let ks = T.words hdr
706− keyedRows = [ HM.fromList (zip ks (T.words row)) | row <- rows ]
707− names = catMaybes (HM.lookup "index" <$> keyedRows)
708− in return (IndexName <$> names)
709− [] -> throwM (EsProtocolException body)
702+ url = joinPath ["_cat/indices?format=json"]
703+ parse body = maybe (throwM (EsProtocolException body)) return $ do
704+ vals <- decode body
705+ forM vals $ \val -> do
706+ case val of
707+ Object obj -> do
708+ indexVal <- HM.lookup "index" obj
709+ case indexVal of
710+ String txt -> Just (IndexName txt)
711+ _ -> Nothing
712+ _ -> Nothing
710713
711714-- | 'updateIndexAliases' updates the server's index alias
712715-- table. Operations are atomic. Explained in further detail at