git.iko.soy/typeable/bloodhound
on master help sign in
WIP: squashme
1241ec3Michael Xavier
src/Database/Bloodhound/Client.hs+10−1
@@ -260,6 +260,7 @@ createIndex indexSettings (IndexName indexName) =
260 where url = joinPath [indexName]
260 where url = joinPath [indexName]
261 body = Just $ encode indexSettings
261 body = Just $ encode indexSettings
262
262
263+
263-- | 'deleteIndex' will delete an index given a 'Server', and an 'IndexName'.
264-- | 'deleteIndex' will delete an index given a 'Server', and an 'IndexName'.
264--
265--
265-- >>> _ <- runBH' $ createIndex defaultIndexSettings (IndexName "didimakeanindex")
266-- >>> _ <- runBH' $ createIndex defaultIndexSettings (IndexName "didimakeanindex")
@@ -278,13 +279,21 @@ deleteIndex (IndexName indexName) =
278-- >>> response <- runBH' $ updateIndexSettings (BlocksWrite False :| []) (IndexName "unconfiguredindex")
279-- >>> response <- runBH' $ updateIndexSettings (BlocksWrite False :| []) (IndexName "unconfiguredindex")
279-- >>> respIsTwoHunna response
280-- >>> respIsTwoHunna response
280-- True
281-- True
281−updateIndexSettings :: MonadBH m => NonEmpty IndexSettingUpdate -> IndexName -> m Reply
282+updateIndexSettings :: MonadBH m => NonEmpty UpdatableIndexSetting -> IndexName -> m Reply
282updateIndexSettings updates (IndexName indexName) =
283updateIndexSettings updates (IndexName indexName) =
283 bindM2 put url (return body)
284 bindM2 put url (return body)
284 where url = joinPath [indexName, "_settings"]
285 where url = joinPath [indexName, "_settings"]
285 body = Just (encode jsonBody)
286 body = Just (encode jsonBody)
286 jsonBody = Object (deepMerge [u | Object u <- toJSON <$> toList updates])
287 jsonBody = Object (deepMerge [u | Object u <- toJSON <$> toList updates])
287
288
289+
290+--TODO: This feels a little nicer than returning a reply and coyly
291+--implying that it *should* be an IndexSettingsSummary
292+getIndexSettings :: MonadBH m => IndexName -> m (Either EsError IndexSettingsSummary)
293+getIndexSettings (IndexName indexName) = undefined
294+
295+
296+
288deepMerge :: [Object] -> Object
297deepMerge :: [Object] -> Object
289deepMerge = LS.foldl' go mempty
298deepMerge = LS.foldl' go mempty
290 where go acc = LS.foldl' go' acc . HM.toList
299 where go acc = LS.foldl' go' acc . HM.toList
src/Database/Bloodhound/Types.hs+63−55
@@ -56,7 +56,8 @@ module Database.Bloodhound.Types
56 , Existence(..)
56 , Existence(..)
57 , NullValue(..)
57 , NullValue(..)
58 , IndexSettings(..)
58 , IndexSettings(..)
59− , IndexSettingUpdate(..)
59+ , UpdatableIndexSetting(..)
60+ , IndexSettingsSummary(..)
60 , AllocationPolicy(..)
61 , AllocationPolicy(..)
61 , ReplicaBounds(..)
62 , ReplicaBounds(..)
62 , Bytes(..)
63 , Bytes(..)
@@ -357,58 +358,59 @@ data IndexSettings =
357defaultIndexSettings :: IndexSettings
358defaultIndexSettings :: IndexSettings
358defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
359defaultIndexSettings = IndexSettings (ShardCount 3) (ReplicaCount 2)
359
360
360−{-| 'IndexSettingUpdate' is used to update an index' settings piecemeal.
361+{-| 'UpdatableIndexSetting' are settings which may be updated after an index is created.
361
362
362 <https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html>
363 <https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html>
363-}
364-}
364−data IndexSettingUpdate = NumberOfReplicas Int
365+data UpdatableIndexSetting = NumberOfReplicas ReplicaCount
365− -- ^ The number of replicas each shard has.
366+ -- ^ The number of replicas each shard has.
366− | AutoExpandReplicas ReplicaBounds
367+ | AutoExpandReplicas ReplicaBounds
367− | BlocksReadOnly Bool
368+ | BlocksReadOnly Bool
368− -- ^ Set to True to have the index read only. False to allow writes and metadata changes.
369+ -- ^ Set to True to have the index read only. False to allow writes and metadata changes.
369− | BlocksRead Bool
370+ | BlocksRead Bool
370− -- ^ Set to True to disable read operations against the index.
371+ -- ^ Set to True to disable read operations against the index.
371− | BlocksWrite Bool
372+ | BlocksWrite Bool
372− -- ^ Set to True to disable write operations against the index.
373+ -- ^ Set to True to disable write operations against the index.
373− | BlocksMetaData Bool
374+ | BlocksMetaData Bool
374− -- ^ Set to True to disable metadata operations against the index.
375+ -- ^ Set to True to disable metadata operations against the index.
375− | RefreshInterval NominalDiffTime
376+ | RefreshInterval NominalDiffTime
376− -- ^ The async refresh interval of a shard
377+ -- ^ The async refresh interval of a shard
377− | IndexConcurrency Int
378+ | IndexConcurrency Int
378− | FailOnMergeFailure Bool
379+ | FailOnMergeFailure Bool
379− | TranslogFlushThresholdOps Int
380+ | TranslogFlushThresholdOps Int
380− -- ^ When to flush on operations.
381+ -- ^ When to flush on operations.
381− | TranslogFlushThresholdSize Bytes
382+ | TranslogFlushThresholdSize Bytes
382− -- ^ When to flush based on translog (bytes) size.
383+ -- ^ When to flush based on translog (bytes) size.
383− | TranslogFlushThresholdPeriod NominalDiffTime
384+ | TranslogFlushThresholdPeriod NominalDiffTime
384− -- ^ When to flush based on a period of not flushing.
385+ -- ^ When to flush based on a period of not flushing.
385− | TranslogDisableFlush Bool
386+ | TranslogDisableFlush Bool
386− -- ^ Disables flushing. Note, should be set for a short interval and then enabled.
387+ -- ^ Disables flushing. Note, should be set for a short interval and then enabled.
387− | CacheFilterMaxSize (Maybe Bytes)
388+ | CacheFilterMaxSize (Maybe Bytes)
388− -- ^ The maximum size of filter cache (per segment in shard).
389+ -- ^ The maximum size of filter cache (per segment in shard).
389− | CacheFilterExpire (Maybe NominalDiffTime)
390+ | CacheFilterExpire (Maybe NominalDiffTime)
390− -- ^ The expire after access time for filter cache.
391+ -- ^ The expire after access time for filter cache.
391− | GatewaySnapshotInterval NominalDiffTime
392+ | GatewaySnapshotInterval NominalDiffTime
392− -- ^ The gateway snapshot interval (only applies to shared gateways).
393+ -- ^ The gateway snapshot interval (only applies to shared gateways).
393− | RoutingAllocationInclude (NonEmpty NodeAttrFilter)
394+ | RoutingAllocationInclude (NonEmpty NodeAttrFilter)
394− -- ^ A node matching any rule will be allowed to host shards from the index.
395+ -- ^ A node matching any rule will be allowed to host shards from the index.
395− | RoutingAllocationExclude (NonEmpty NodeAttrFilter)
396+ | RoutingAllocationExclude (NonEmpty NodeAttrFilter)
396− -- ^ A node matching any rule will NOT be allowed to host shards from the index.
397+ -- ^ A node matching any rule will NOT be allowed to host shards from the index.
397− | RoutingAllocationRequire (NonEmpty NodeAttrFilter)
398+ | RoutingAllocationRequire (NonEmpty NodeAttrFilter)
398− -- ^ Only nodes matching all rules will be allowed to host shards from the index.
399+ -- ^ Only nodes matching all rules will be allowed to host shards from the index.
399− | RoutingAllocationEnable AllocationPolicy
400+ | RoutingAllocationEnable AllocationPolicy
400− -- ^ Enables shard allocation for a specific index.
401+ -- ^ Enables shard allocation for a specific index.
401− | RoutingAllocationShardsPerNode ShardCount
402+ | RoutingAllocationShardsPerNode ShardCount
402− -- ^ Controls the total number of shards (replicas and primaries) allowed to be allocated on a single node.
403+ -- ^ Controls the total number of shards (replicas and primaries) allowed to be allocated on a single node.
403− | RecoveryInitialShards InitialShardCount
404+ | RecoveryInitialShards InitialShardCount
404− -- ^ When using local gateway a particular shard is recovered only if there can be allocated quorum shards in the cluster.
405+ -- ^ When using local gateway a particular shard is recovered only if there can be allocated quorum shards in the cluster.
405− | GCDeletes NominalDiffTime
406+ | GCDeletes NominalDiffTime
406− | TTLDisablePurge Bool
407+ | TTLDisablePurge Bool
407− -- ^ Disables temporarily the purge of expired docs.
408+ -- ^ Disables temporarily the purge of expired docs.
408− | TranslogFSType FSType
409+ | TranslogFSType FSType
409− | IndexCompoundFormat CompoundFormat
410+ | IndexCompoundFormat CompoundFormat
410− | IndexCompoundOnFlush Bool
411+ | IndexCompoundOnFlush Bool
411− | WarmerEnabled Bool
412+ | WarmerEnabled Bool
413+ deriving (Eq, Show)
412
414
413data AllocationPolicy = AllocAll
415data AllocationPolicy = AllocAll
414 -- ^ Allows shard allocation for all shards.
416 -- ^ Allows shard allocation for all shards.
@@ -418,10 +420,12 @@ data AllocationPolicy = AllocAll
418 -- ^ Allows shard allocation only for primary shards for new indices.
420 -- ^ Allows shard allocation only for primary shards for new indices.
419 | AllocNone
421 | AllocNone
420 -- ^ No shard allocation is allowed
422 -- ^ No shard allocation is allowed
423+ deriving (Eq, Show)
421
424
422data ReplicaBounds = ReplicasBounded Int Int
425data ReplicaBounds = ReplicasBounded Int Int
423 | ReplicasLowerBounded Int
426 | ReplicasLowerBounded Int
424 | ReplicasUnbounded
427 | ReplicasUnbounded
428+ deriving (Eq, Show)
425
429
426newtype Bytes = Bytes Int deriving (Eq, Show, Ord, ToJSON)
430newtype Bytes = Bytes Int deriving (Eq, Show, Ord, ToJSON)
427
431
@@ -433,18 +437,25 @@ data InitialShardCount = QuorumShards
433 | FullShards
437 | FullShards
434 | FullMinus1Shards
438 | FullMinus1Shards
435 | ExplicitShards Int
439 | ExplicitShards Int
440+ deriving (Eq, Show)
436
441
437data NodeAttrFilter = NodeAttrFilter { nodeAttrFilterName :: NodeAttrName
442data NodeAttrFilter = NodeAttrFilter { nodeAttrFilterName :: NodeAttrName
438 , nodeAttrFilterValues :: NonEmpty Text}
443 , nodeAttrFilterValues :: NonEmpty Text}
444+ deriving (Eq, Show)
439
445
440−newtype NodeAttrName = NodeAttrName Text
446+newtype NodeAttrName = NodeAttrName Text deriving (Eq, Show)
441
447
442data CompoundFormat = CompoundFileFormat Bool
448data CompoundFormat = CompoundFileFormat Bool
443 | MergeSegmentVsTotalIndex Double
449 | MergeSegmentVsTotalIndex Double
444 -- ^ percentage between 0 and 1 where 0 is false, 1 is true
450 -- ^ percentage between 0 and 1 where 0 is false, 1 is true
451+ deriving (Eq, Show)
445
452
446newtype NominalDiffTimeJSON = NominalDiffTimeJSON NominalDiffTime
453newtype NominalDiffTimeJSON = NominalDiffTimeJSON NominalDiffTime
447
454
455+data IndexSettingsSummary = IndexSettingsSummary { sSummaryShardCount :: ShardCount
456+ , sSummaryUpdateable :: [UpdatableIndexSetting]}
457+ deriving (Eq, Show)
458+
448{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
459{-| 'Reply' and 'Method' are type synonyms from 'Network.HTTP.Types.Method.Method' -}
449type Reply = Network.HTTP.Client.Response L.ByteString
460type Reply = Network.HTTP.Client.Response L.ByteString
450type Method = NHTM.Method
461type Method = NHTM.Method
@@ -2250,7 +2261,7 @@ instance ToJSON IndexSettings where
2250 ]
2261 ]
2251 ]
2262 ]
2252
2263
2253−instance ToJSON IndexSettingUpdate where
2264+instance ToJSON UpdatableIndexSetting where
2254 toJSON (NumberOfReplicas x) = oPath ("index" :| ["number_of_replicas"]) x
2265 toJSON (NumberOfReplicas x) = oPath ("index" :| ["number_of_replicas"]) x
2255 toJSON (AutoExpandReplicas x) = oPath ("index" :| ["auto_expand_replicas"]) x
2266 toJSON (AutoExpandReplicas x) = oPath ("index" :| ["auto_expand_replicas"]) x
2256 toJSON (BlocksReadOnly x) = oPath ("blocks" :| ["read_only"]) x
2267 toJSON (BlocksReadOnly x) = oPath ("blocks" :| ["read_only"]) x
@@ -2270,9 +2281,6 @@ instance ToJSON IndexSettingUpdate where
2270 toJSON (RoutingAllocationInclude fs) = oPath ("index" :| ["routing", "allocation", "include"]) (attrFilterJSON fs)
2281 toJSON (RoutingAllocationInclude fs) = oPath ("index" :| ["routing", "allocation", "include"]) (attrFilterJSON fs)
2271 toJSON (RoutingAllocationExclude fs) = oPath ("index" :| ["routing", "allocation", "exclude"]) (attrFilterJSON fs)
2282 toJSON (RoutingAllocationExclude fs) = oPath ("index" :| ["routing", "allocation", "exclude"]) (attrFilterJSON fs)
2272 toJSON (RoutingAllocationRequire fs) = oPath ("index" :| ["routing", "allocation", "require"]) (attrFilterJSON fs)
2283 toJSON (RoutingAllocationRequire fs) = oPath ("index" :| ["routing", "allocation", "require"]) (attrFilterJSON fs)
2273− toJSON (RoutingAllocationDisable x) = oPath ("index" :| ["routing", "allocation", "disable_allocation"]) x
2274− toJSON (RoutingAllocationDisableNew x) = oPath ("index" :| ["routing", "allocation", "disable_new_allocation"]) x
2275− toJSON (RoutingAllocationDisableReplica x) = oPath ("index" :| ["routing", "allocation", "disable_replica_allocation"]) x
2276 toJSON (RoutingAllocationEnable x) = oPath ("index" :| ["routing", "allocation", "enable"]) x
2284 toJSON (RoutingAllocationEnable x) = oPath ("index" :| ["routing", "allocation", "enable"]) x
2277 toJSON (RoutingAllocationShardsPerNode x) = oPath ("index" :| ["routing", "allocation", "total_shards_per_node"]) x
2285 toJSON (RoutingAllocationShardsPerNode x) = oPath ("index" :| ["routing", "allocation", "total_shards_per_node"]) x
2278 toJSON (RecoveryInitialShards x) = oPath ("index" :| ["recovery", "initial_shards"]) x
2286 toJSON (RecoveryInitialShards x) = oPath ("index" :| ["recovery", "initial_shards"]) x