made elasticsearch parameters configurable

This commit is contained in:
nek0 2015-10-17 21:52:23 +02:00
parent 18dc01b2c3
commit ba8db39c75
3 changed files with 31 additions and 9 deletions

View file

@ -209,13 +209,17 @@ multiFileField = Field
, fieldEnctype = Multipart
}
-- <putIndexES :: ESInput -> Handler ()
putIndexES :: ESInput -> Handler ()
putIndexES input = do
master <- getYesod
shards <- appShards $ appSettings master
replicas <- appReplicas $ appSettings master
let is = return $ IndexSettings (ShardCount shards) (ReplicaCount replicas)
resp <- case input of
ESUser uId user -> do
ex <- runBH' $ indexExists (IndexName "user")
when (not ex) ((\ _ -> do
runBH' $ createIndex singleIndexSettings (IndexName "user")
runBH' $ createIndex is (IndexName "user")
return ()
) ex)
_ <- runBH' $ openIndex (IndexName "user")
@ -223,7 +227,7 @@ putIndexES input = do
ESAlbum aId album -> do
ex <- runBH' $ indexExists (IndexName "album")
when (not ex) ((\ _ -> do
runBH' $ createIndex singleIndexSettings (IndexName "album")
runBH' $ createIndex is (IndexName "album")
return ()
) ex)
_ <- runBH' $ openIndex (IndexName "album")
@ -231,7 +235,7 @@ putIndexES input = do
ESMedium mId medium -> do
ex <- runBH' $ indexExists (IndexName "medium")
when (not ex) ((\ _ -> do
runBH' $ createIndex singleIndexSettings (IndexName "medium")
runBH' $ createIndex is (IndexName "medium")
return ()
) ex)
_ <- runBH' $ openIndex (IndexName "medium")
@ -239,7 +243,7 @@ putIndexES input = do
ESComment cId comment -> do
ex <- runBH' $ indexExists (IndexName "comment")
when (not ex) ((\ _ -> do
runBH' $ createIndex singleIndexSettings (IndexName "comment")
runBH' $ createIndex is (IndexName "comment")
return ()
) ex)
_ <- runBH' $ openIndex (IndexName "comment")
@ -266,9 +270,9 @@ deleteIndexES input = do
_ -> error $ C.unpack $ BL.toStrict $ responseBody resp
runBH' action = do
let server = Server "http://localhost:9200"
master <- getYesod
server <- appSearchHost $ appSettings master
port <- return . show =<< (appSearchPort $ appSettings master)
let server = Server $ server ++ ":" ++ port
manager <- newManager defaultManagerSettings
runBH (BHEnv server manager) action
singleIndexSettings :: IndexSettings
singleIndexSettings = IndexSettings (ShardCount 1) (ReplicaCount 1)

View file

@ -75,6 +75,11 @@ data AppSettings = AppSettings
, appTos1 :: Text
, appTos2 :: Text
-- ^ Terms of Service
, appSearchHost :: Text
, appSearchPort :: Text
, appShards :: Int
, appReplicas :: Int
-- ^ Settings for Elasticsearch
}
instance FromJSON AppSettings where
@ -106,6 +111,11 @@ instance FromJSON AppSettings where
appTos1 <- o .: "tos1"
appTos2 <- o .: "tos2"
appSearchHost <- o .: "searchhost"
appSearchPort <- o .: "searchport"
appShards <- o .: "shards"
appReplicas <- o .: "replicas"
return AppSettings {..}
-- | Settings for 'widgetFile', such as which template languages to support and

View file

@ -47,5 +47,13 @@ copyrightLink: https://github.com/nek0/eidolon
# block signup process
signupBlocked: "_env:SIGNUP_BLOCK:false"
# Terms of Service
tos1: "Terms of Service 1"
tos2: "Terms of Service 2"
# Elasticsearcha settings
searchhost: "localhost"
searchport: 9200
shards: 1
replicas: 2