git.iko.soy/typeable/bloodhound
on master help sign in
Use JSON format for parsing indices
b6f5b56Michael Xavier
src/Database/V1/Bloodhound/Client.hs+11−8
@@ -583,14 +583,17 @@ listIndices :: (MonadThrow m, MonadBH m) => m [IndexName]
583listIndices =
583listIndices =
584 parse . responseBody =<< get =<< url
584 parse . responseBody =<< get =<< url
585 where
585 where
586− url = joinPath ["_cat/indices?v"]
586+ url = joinPath ["_cat/indices?format=json"]
587− -- parses the tabular format the indices api provides
587+ parse body = maybe (throwM (EsProtocolException body)) return $ do
588− parse body = case T.lines (T.decodeUtf8 (L.toStrict body)) of
588+ vals <- decode body
589− (hdr:rows) -> let ks = T.words hdr
589+ forM vals $ \val -> do
590− keyedRows = [ HM.fromList (zip ks (T.words row)) | row <- rows ]
590+ case val of
591+ Object obj -> do
591− names = catMaybes (HM.lookup "index" <$> keyedRows)
592+ indexVal <- HM.lookup "index" obj
592− in return (IndexName <$> names)
593+ case indexVal of
593− [] -> throwM (EsProtocolException body)
594+ String txt -> Just (IndexName txt)
595+ _ -> Nothing
596+ _ -> Nothing
594
597
595-- | 'updateIndexAliases' updates the server's index alias
598-- | 'updateIndexAliases' updates the server's index alias
596-- table. Operations are atomic. Explained in further detail at
599-- 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]
699listIndices =
699listIndices =
700 parse . responseBody =<< get =<< url
700 parse . responseBody =<< get =<< url
701 where
701 where
702− url = joinPath ["_cat/indices?v"]
702+ url = joinPath ["_cat/indices?format=json"]
703− -- parses the tabular format the indices api provides
703+ parse body = maybe (throwM (EsProtocolException body)) return $ do
704− parse body = case T.lines (T.decodeUtf8 (L.toStrict body)) of
704+ vals <- decode body
705− (hdr:rows) -> let ks = T.words hdr
705+ forM vals $ \val -> do
706− keyedRows = [ HM.fromList (zip ks (T.words row)) | row <- rows ]
706+ case val of
707+ Object obj -> do
707− names = catMaybes (HM.lookup "index" <$> keyedRows)
708+ indexVal <- HM.lookup "index" obj
708− in return (IndexName <$> names)
709+ case indexVal of
709− [] -> throwM (EsProtocolException body)
710+ String txt -> Just (IndexName txt)
711+ _ -> Nothing
712+ _ -> Nothing
710
713
711-- | 'updateIndexAliases' updates the server's index alias
714-- | 'updateIndexAliases' updates the server's index alias
712-- table. Operations are atomic. Explained in further detail at
715-- table. Operations are atomic. Explained in further detail at