git.iko.soy/typeable/bloodhound
on master help sign in
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.

commitac5d6f68276df166030e22513625e5c3ad8d15ce authorMichael Xavier <michael@michaelxavier.net> dateMon 25 Jul 2016, 09:30 (10 years ago) parentec2bfeb
3 files changed+19−20
src/Database/Bloodhound/Client.hs+15−17 src/Database/Bloodhound/Types.hs+3−2 tests/tests.hs+1−1
src/Database/Bloodhound/Client.hs+15−17
@@ -358,15 +358,16 @@ createSnapshot (SnapshotRepoName repoName)
358358 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName]
359359 params = [("wait_for_completion", Just (boolQP snapWaitForCompletion))]
360360 body = encode $ object prs
361− prs = catMaybes [ ("indices" .=) . renderIndices <$> snapIndices
361+ prs = catMaybes [ ("indices" .=) . indexSelectionName <$> snapIndices
362362 , Just ("ignore_unavailable" .= snapIgnoreUnavailable)
363363 , Just ("ignore_global_state" .= snapIncludeGlobalState)
364364 , Just ("partial" .= snapPartial)
365365 ]
366366
367367
368−renderIndices :: NonEmpty IndexName -> Text
369−renderIndices (i :| is) = T.intercalate "," (renderIndex <$> (i:is))
368+indexSelectionName :: IndexSelection -> Text
369+indexSelectionName AllIndexes = "_all"
370+indexSelectionName (IndexList (i :| is)) = T.intercalate "," (renderIndex <$> (i:is))
370371 where
371372 renderIndex (IndexName n) = n
372373
@@ -425,15 +426,17 @@ restoreSnapshot (SnapshotRepoName repoName)
425426 url = addQuery params <$> joinPath ["_snapshot", repoName, snapName, "_restore"]
426427 params = [("wait_for_completion", Just (boolQP snapRestoreWaitForCompletion))]
427428 body = encode (object prs)
428− prs = catMaybes [ ("indices" .=) . renderIndices <$> snapRestoreIndices
429− , Just ("ignore_unavailable" .= snapRestoreIgnoreUnavailable)
430− , Just ("include_global_state" .= snapRestoreIncludeGlobalState)
431− , ("rename_pattern" .=) <$> snapRestoreRenamePattern
432− , ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
433− , Just ("include_aliases" .= snapRestoreIncludeAliases)
434− , ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
435− , ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
436− ]
429+
430+
431+ prs = catMaybes [ ("indices" .=) . indexSelectionName <$> snapRestoreIndices
432+ , Just ("ignore_unavailable" .= snapRestoreIgnoreUnavailable)
433+ , Just ("include_global_state" .= snapRestoreIncludeGlobalState)
434+ , ("rename_pattern" .=) <$> snapRestoreRenamePattern
435+ , ("rename_replacement" .=) . renderTokens <$> snapRestoreRenameReplacement
436+ , Just ("include_aliases" .= snapRestoreIncludeAliases)
437+ , ("index_settings" .= ) <$> snapRestoreIndexSettingsOverrides
438+ , ("ignore_index_settings" .= ) <$> snapRestoreIgnoreIndexSettings
439+ ]
437440 renderTokens (t :| ts) = mconcat (renderToken <$> (t:ts))
438441 renderToken (RRTLit t) = t
439442 renderToken RRSubWholeMatch = "$0"
@@ -522,11 +525,6 @@ optimizeIndex ixs IndexOptimizationSettings {..} =
522525 body = Nothing
523526
524527
525−-------------------------------------------------------------------------------
526−indexSelectionName :: IndexSelection -> Text
527−indexSelectionName (IndexList names) = renderIndices names
528−indexSelectionName AllIndexes = "_all"
529−
530528deepMerge :: [Object] -> Object
531529deepMerge = LS.foldl' go mempty
532530 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
861861{-| 'IndexSelection' is used for APIs which take a single index, a list of
862862 indexes, or the special @_all@ index.
863863-}
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.
864865data IndexSelection = IndexList (NonEmpty IndexName)
865866 | AllIndexes deriving (Eq, Generic, Show, Typeable)
866867
@@ -3853,7 +3854,7 @@ data SnapshotCreateSettings = SnapshotCreateSettings {
38533854 -- enabled it could wait a long time, so you should adjust your
38543855 -- 'ManagerSettings' accordingly to set long timeouts or
38553856 -- explicitly handle timeouts.
3856− , snapIndices :: Maybe (NonEmpty IndexName)
3857+ , snapIndices :: Maybe IndexSelection
38573858 -- ^ Nothing will snapshot all indices. Just [] is permissable and
38583859 -- will essentially be a no-op snapshot.
38593860 , snapIgnoreUnavailable :: Bool
@@ -3989,7 +3990,7 @@ data SnapshotRestoreSettings = SnapshotRestoreSettings {
39893990 -- enabled, it could wait a long time, so you should adjust your
39903991 -- 'ManagerSettings' accordingly to set long timeouts or
39913992 -- explicitly handle timeouts.
3992− , snapRestoreIndices :: Maybe (NonEmpty IndexName)
3993+ , snapRestoreIndices :: Maybe IndexSelection
39933994 -- ^ Nothing will restore all indices in the snapshot. Just [] is
39943995 -- permissable and will essentially be a no-op restore.
39953996 , snapRestoreIgnoreUnavailable :: Bool
tests/tests.hs+1−1
@@ -358,7 +358,7 @@ withSnapshot srn sn = bracket_ alloc free
358358 liftIO (validateStatus resp 200)
359359 -- We'll make this synchronous for testing purposes
360360 createSettings = defaultSnapshotCreateSettings { snapWaitForCompletion = True
361− , snapIndices = Just (testIndex :| [])
361+ , snapIndices = Just (IndexList (testIndex :| []))
362362 -- We don't actually need to back up any data
363363 }
364364 free = do