@@ -0,0 +1,65 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE OverloadedStrings #-}
4+module Database.Bloodhound.Client where
6+import Control.Applicative
7+import Control.Monad (liftM)
9+import Data.Aeson.TH (deriveJSON)
10+import qualified Data.ByteString.Lazy.Char8 as L
11+import qualified Data.Text as T
12+import Data.Time.Clock as DTC
13+import GHC.Generics (Generic)
14+import Network.HTTP.Conduit
16+data Version = Version { number :: T.Text
17+ , build_hash :: T.Text
18+ , build_timestamp :: DTC.UTCTime
19+ , build_snapshot :: Bool
20+ , lucene_version :: T.Text } deriving (Show, Generic)
22+data (FromJSON a, ToJSON a) => Status a =
27+ , tagline :: T.Text } deriving (Show)
29+instance ToJSON Version
30+instance FromJSON Version
32+instance (FromJSON a, ToJSON a) => FromJSON (Status a) where
33+ parseJSON (Object v) = Status <$>
41+-- instance ToJSON (Status a)
42+-- instance FromJSON (Status a)
44+muhServer = "http://localhost:9200"
46+-- bloo <- (liftM responseBody $ parseUrl "http://localhost:9200/" >>= \r -> withManager (httpLbs r))
49+rootPath = rollUp $ ["/"]
52+pathFromType :: String -> String -> String
53+pathFromType index docType = "/" ++ index ++ docType
55+-- Kinda hate this too.
56+rollUp :: [String] -> String
57+rollUp = Prelude.concat
59+getStatus :: String -> IO (Maybe (Status Version))
61+ request <- parseUrl $ server ++ rootPath
62+ response <- withManager $ httpLbs request
63+ return $ (decode $ responseBody response)
65+main = simpleHttp "http://localhost:9200/events/event/_search?q=hostname:localhost&size=1" >>= L.putStrLn