git.iko.soy/typeable/bloodhound
on master help sign in
Use IndexSelection for snapshot/restore
ac5d6f6Michael Xavier
src/Database/Bloodhound/Client.hs+15−17
@@ -358,15 +358,16 @@ createSnapshot (SnapshotRepoName repoName)
358 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName]
358 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName]
359 params = [("wait_for_completion", Just (boolQP snapWaitForCompletion))]
359 params = [("wait_for_completion", Just (boolQP snapWaitForCompletion))]
360 body = encode $ object prs
360 body = encode $ object prs
361− prs = catMaybes [ ("indices" .=) . renderIndices <$> snapIndices
361+ prs = catMaybes [ ("indices" .=) . indexSelectionName <$> snapIndices
362 , Just ("ignore_unavailable" .= snapIgnoreUnavailable)
362 , Just ("ignore_unavailable" .= snapIgnoreUnavailable)
363 , Just ("ignore_global_state" .= snapIncludeGlobalState)
363 , Just ("ignore_global_state" .= snapIncludeGlobalState)
364 , Just ("partial" .= snapPartial)
364 , Just ("partial" .= snapPartial)
365 ]
365 ]
366
366
367
367
368−renderIndices :: NonEmpty IndexName -> Text
368+indexSelectionName :: IndexSelection -> Text
369+indexSelectionName AllIndexes = "_all"
369−renderIndices (i :| is) = T.intercalate "," (renderIndex <$> (i:is))
370+indexSelectionName (IndexList (i :| is)) = T.intercalate "," (renderIndex <$> (i:is))
370 where
371 where
371 renderIndex (IndexName n) = n
372 renderIndex (IndexName n) = n
372
373
@@ -425,15 +426,17 @@ restoreSnapshot (SnapshotRepoName repoName)
425 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
426 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
426 params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
427 params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
427 body = encode (object prs)
428 body = encode (object prs)
429+
430+
428− prs = catMaybes [ ("indices" .=) . renderIndices <$> snapRestoreIndices
431+ prs = catMaybes [ ("indices" .=) . indexSelectionName <$> snapRestoreIndices
429− , Just ("ignore_unavailable" .= snapRestoreIgnoreUnavailable)
432+ , Just ("ignore_unavailable" .= snapRestoreIgnoreUnavailable)
430− , Just ("include_global_state" .= snapRestoreIncludeGlobalState)
433+ , Just ("include_global_state" .= snapRestoreIncludeGlobalState)
431− , ("rename_pattern" .=) <$> snapRestoreRenamePattern
434+ , ("rename_pattern" .=) <$> snapRestoreRenamePattern
432− , ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
435+ , ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
433− , Just ("include_aliases" .= snapRestoreIncludeAliases)
436+ , Just ("include_aliases" .= snapRestoreIncludeAliases)
434− , ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
437+ , ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
435− , ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
438+ , ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
436− ]
439+ ]
437 renderTokens (t :| ts) = mconcat (renderToken <$> (t:ts))
440 renderTokens (t :| ts) = mconcat (renderToken <$> (t:ts))
438 renderToken (RRTLit t) = t
441 renderToken (RRTLit t) = t
439 renderToken RRSubWholeMatch = "$0"
442 renderToken RRSubWholeMatch = "$0"
@@ -522,11 +525,6 @@ optimizeIndex ixs IndexOptimizationSettings {..} =
522 body = Nothing
525 body = Nothing
523
526
524
527
525−-------------------------------------------------------------------------------
526−indexSelectionName :: IndexSelection -> Text
527−indexSelectionName (IndexList names) = renderIndices names
528−indexSelectionName AllIndexes = "_all"
529−
530deepMerge :: [Object] -> Object
528deepMerge :: [Object] -> Object
531deepMerge = LS.foldl' go mempty
529deepMerge = LS.foldl' go mempty
532 where go acc = LS.foldl' go' acc . HM.toList
530 where go acc = LS.foldl' go' acc . HM.toList
src/Database/Bloodhound/Types.hs+3−2
@@ -861,6 +861,7 @@ newtype IndexName = IndexName Text deriving (Eq, Generic, Read, Show, ToJSON, Fr
861{-| 'IndexSelection' is used for APIs which take a single index, a list of
861{-| 'IndexSelection' is used for APIs which take a single index, a list of
862 indexes, or the special @_all@ index.
862 indexes, or the special @_all@ index.
863-}
863-}
864+--TODO: this does not fully support <https://www.elastic.co/guide/en/elasticsearch/reference/1.7/multi-index.html multi-index syntax>. It wouldn't be too hard to implement but you'd have to add the optional parameters (ignore_unavailable, allow_no_indices, expand_wildcards) to any APIs using it. Also would be a breaking API.
864data IndexSelection = IndexList (NonEmpty IndexName)
865data IndexSelection = IndexList (NonEmpty IndexName)
865 | AllIndexes deriving (Eq, Generic, Show, Typeable)
866 | AllIndexes deriving (Eq, Generic, Show, Typeable)
866
867
@@ -3853,7 +3854,7 @@ data SnapshotCreateSettings = SnapshotCreateSettings {
3853 -- enabled it could wait a long time, so you should adjust your
3854 -- enabled it could wait a long time, so you should adjust your
3854 -- 'ManagerSettings' accordingly to set long timeouts or
3855 -- 'ManagerSettings' accordingly to set long timeouts or
3855 -- explicitly handle timeouts.
3856 -- explicitly handle timeouts.
3856− , snapIndices :: Maybe (NonEmpty IndexName)
3857+ , snapIndices :: Maybe IndexSelection
3857 -- ^ Nothing will snapshot all indices. Just [] is permissable and
3858 -- ^ Nothing will snapshot all indices. Just [] is permissable and
3858 -- will essentially be a no-op snapshot.
3859 -- will essentially be a no-op snapshot.
3859 , snapIgnoreUnavailable :: Bool
3860 , snapIgnoreUnavailable :: Bool
@@ -3989,7 +3990,7 @@ data SnapshotRestoreSettings = SnapshotRestoreSettings {
3989 -- enabled, it could wait a long time, so you should adjust your
3990 -- enabled, it could wait a long time, so you should adjust your
3990 -- 'ManagerSettings' accordingly to set long timeouts or
3991 -- 'ManagerSettings' accordingly to set long timeouts or
3991 -- explicitly handle timeouts.
3992 -- explicitly handle timeouts.
3992− , snapRestoreIndices :: Maybe (NonEmpty IndexName)
3993+ , snapRestoreIndices :: Maybe IndexSelection
3993 -- ^ Nothing will restore all indices in the snapshot. Just [] is
3994 -- ^ Nothing will restore all indices in the snapshot. Just [] is
3994 -- permissable and will essentially be a no-op restore.
3995 -- permissable and will essentially be a no-op restore.
3995 , snapRestoreIgnoreUnavailable :: Bool
3996 , snapRestoreIgnoreUnavailable :: Bool
tests/tests.hs+1−1
@@ -358,7 +358,7 @@ withSnapshot srn sn = bracket_ alloc free
358 liftIO (validateStatus resp 200)
358 liftIO (validateStatus resp 200)
359 -- We'll make this synchronous for testing purposes
359 -- We'll make this synchronous for testing purposes
360 createSettings = defaultSnapshotCreateSettings { snapWaitForCompletion = True
360 createSettings = defaultSnapshotCreateSettings { snapWaitForCompletion = True
361− , snapIndices = Just (testIndex :| [])
361+ , snapIndices = Just (IndexList (testIndex :| []))
362 -- We don't actually need to back up any data
362 -- We don't actually need to back up any data
363 }
363 }
364 free = do
364 free = do