mirror of
https://github.com/typeable/bloodhound.git
synced 2025-01-05 21:36:03 +03:00
Use IndexSelection for snapshot/restore
In the future, IndexSelection can fully support multi-index syntax, so we should have any API that supports that syntax using IndexSelection so it gets upgrades for free.
This commit is contained in:
parent
ec2bfeb793
commit
ac5d6f6827
@ -358,15 +358,16 @@ createSnapshot (SnapshotRepoName repoName)
|
||||
url = addQuery params <$> joinPath ["_snapshot", repoName, snapName]
|
||||
params = [("wait_for_completion", Just (boolQP snapWaitForCompletion))]
|
||||
body = encode $ object prs
|
||||
prs = catMaybes [ ("indices" .=) . renderIndices <$> snapIndices
|
||||
prs = catMaybes [ ("indices" .=) . indexSelectionName <$> snapIndices
|
||||
, Just ("ignore_unavailable" .= snapIgnoreUnavailable)
|
||||
, Just ("ignore_global_state" .= snapIncludeGlobalState)
|
||||
, Just ("partial" .= snapPartial)
|
||||
]
|
||||
|
||||
|
||||
renderIndices :: NonEmpty IndexName -> Text
|
||||
renderIndices (i :| is) = T.intercalate "," (renderIndex <$> (i:is))
|
||||
indexSelectionName :: IndexSelection -> Text
|
||||
indexSelectionName AllIndexes = "_all"
|
||||
indexSelectionName (IndexList (i :| is)) = T.intercalate "," (renderIndex <$> (i:is))
|
||||
where
|
||||
renderIndex (IndexName n) = n
|
||||
|
||||
@ -425,15 +426,17 @@ restoreSnapshot (SnapshotRepoName repoName)
|
||||
url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
|
||||
params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
|
||||
body = encode (object prs)
|
||||
prs = catMaybes [ ("indices" .=) . renderIndices <$> snapRestoreIndices
|
||||
, Just ("ignore_unavailable" .= snapRestoreIgnoreUnavailable)
|
||||
, Just ("include_global_state" .= snapRestoreIncludeGlobalState)
|
||||
, ("rename_pattern" .=) <$> snapRestoreRenamePattern
|
||||
, ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
|
||||
, Just ("include_aliases" .= snapRestoreIncludeAliases)
|
||||
, ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
|
||||
, ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
|
||||
]
|
||||
|
||||
|
||||
prs = catMaybes [ ("indices" .=) . indexSelectionName <$> snapRestoreIndices
|
||||
, Just ("ignore_unavailable" .= snapRestoreIgnoreUnavailable)
|
||||
, Just ("include_global_state" .= snapRestoreIncludeGlobalState)
|
||||
, ("rename_pattern" .=) <$> snapRestoreRenamePattern
|
||||
, ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
|
||||
, Just ("include_aliases" .= snapRestoreIncludeAliases)
|
||||
, ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
|
||||
, ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
|
||||
]
|
||||
renderTokens (t :| ts) = mconcat (renderToken <$> (t:ts))
|
||||
renderToken (RRTLit t) = t
|
||||
renderToken RRSubWholeMatch = "$0"
|
||||
@ -522,11 +525,6 @@ optimizeIndex ixs IndexOptimizationSettings {..} =
|
||||
body = Nothing
|
||||
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
indexSelectionName :: IndexSelection -> Text
|
||||
indexSelectionName (IndexList names) = renderIndices names
|
||||
indexSelectionName AllIndexes = "_all"
|
||||
|
||||
deepMerge :: [Object] -> Object
|
||||
deepMerge = LS.foldl' go mempty
|
||||
where go acc = LS.foldl' go' acc . HM.toList
|
||||
|
@ -861,6 +861,7 @@ newtype IndexName = IndexName Text deriving (Eq, Generic, Read, Show, ToJSON, Fr
|
||||
{-| 'IndexSelection' is used for APIs which take a single index, a list of
|
||||
indexes, or the special @_all@ index.
|
||||
-}
|
||||
--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.
|
||||
data IndexSelection = IndexList (NonEmpty IndexName)
|
||||
| AllIndexes deriving (Eq, Generic, Show, Typeable)
|
||||
|
||||
@ -3853,7 +3854,7 @@ data SnapshotCreateSettings = SnapshotCreateSettings {
|
||||
-- enabled it could wait a long time, so you should adjust your
|
||||
-- 'ManagerSettings' accordingly to set long timeouts or
|
||||
-- explicitly handle timeouts.
|
||||
, snapIndices :: Maybe (NonEmpty IndexName)
|
||||
, snapIndices :: Maybe IndexSelection
|
||||
-- ^ Nothing will snapshot all indices. Just [] is permissable and
|
||||
-- will essentially be a no-op snapshot.
|
||||
, snapIgnoreUnavailable :: Bool
|
||||
@ -3989,7 +3990,7 @@ data SnapshotRestoreSettings = SnapshotRestoreSettings {
|
||||
-- enabled, it could wait a long time, so you should adjust your
|
||||
-- 'ManagerSettings' accordingly to set long timeouts or
|
||||
-- explicitly handle timeouts.
|
||||
, snapRestoreIndices :: Maybe (NonEmpty IndexName)
|
||||
, snapRestoreIndices :: Maybe IndexSelection
|
||||
-- ^ Nothing will restore all indices in the snapshot. Just [] is
|
||||
-- permissable and will essentially be a no-op restore.
|
||||
, snapRestoreIgnoreUnavailable :: Bool
|
||||
|
@ -358,7 +358,7 @@ withSnapshot srn sn = bracket_ alloc free
|
||||
liftIO (validateStatus resp 200)
|
||||
-- We'll make this synchronous for testing purposes
|
||||
createSettings = defaultSnapshotCreateSettings { snapWaitForCompletion = True
|
||||
, snapIndices = Just (testIndex :| [])
|
||||
, snapIndices = Just (IndexList (testIndex :| []))
|
||||
-- We don't actually need to back up any data
|
||||
}
|
||||
free = do
|
||||
|
Loading…
Reference in New Issue
Block a user