@@ -11,6 +11,7 @@ module Database.Bloodhound.Client
11 , getDocument
11 , getDocument
12 , documentExists
12 , documentExists
13 , deleteDocument
13 , deleteDocument
@@ -21,25 +22,25 @@ import Data.Aeson.TH (deriveJSON)
21import qualified Data.ByteString.Lazy.Char8 as L
22import qualified Data.ByteString.Lazy.Char8 as L
22import Data.List (intersperse)
23import Data.List (intersperse)
23import Data.Maybe (fromMaybe)
24import Data.Maybe (fromMaybe)
24−import qualified Data.Text as T
25+import Data.Text (Text)
25−import Data.Time.Clock as DTC
26+import Data.Time.Clock (UTCTime)
26import GHC.Generics (Generic)
27import GHC.Generics (Generic)
27import Network.HTTP.Conduit
28import Network.HTTP.Conduit
28import qualified Network.HTTP.Types.Method as NHTM
29import qualified Network.HTTP.Types.Method as NHTM
29import qualified Network.HTTP.Types.Status as NHTS
30import qualified Network.HTTP.Types.Status as NHTS
31−data Version = Version { number :: T.Text
32+data Version = Version { number :: Text
32− , build_hash :: T.Text
33+ , build_hash :: Text
33− , build_timestamp :: DTC.UTCTime
34+ , build_timestamp :: UTCTime
34 , build_snapshot :: Bool
35 , build_snapshot :: Bool
35− , lucene_version :: T.Text } deriving (Show, Generic)
36+ , lucene_version :: Text } deriving (Show, Generic)
37data (FromJSON a, ToJSON a) => Status a =
38data (FromJSON a, ToJSON a) => Status a =
38 Status { ok :: Bool
39 Status { ok :: Bool
39 , status :: Int
40 , status :: Int
40− , name :: T.Text
41+ , name :: Text
41 , version :: a
42 , version :: a
42− , tagline :: T.Text } deriving (Show)
43+ , tagline :: Text } deriving (Show)
44instance ToJSON Version
45instance ToJSON Version
45instance FromJSON Version
46instance FromJSON Version
@@ -71,7 +72,7 @@ instance (FromJSON a, ToJSON a) => FromJSON (Status a) where
72main = simpleHttp "http://localhost:9200/events/event/_search?q=hostname:localhost&size=1" >>= L.putStrLn
73main = simpleHttp "http://localhost:9200/events/event/_search?q=hostname:localhost&size=1" >>= L.putStrLn
74−-- data Response = Response { blah :: T.Text } deriving (Show)
75+-- data Response = Response { blah :: Text } deriving (Show)
76-- indexDocument :: ToJSON a => a -> IO Response
77-- indexDocument :: ToJSON a => a -> IO Response
77-- indexDocument doc = ToJSON a
78-- indexDocument doc = ToJSON a
@@ -116,7 +117,7 @@ newtype Server = Server String deriving (Show)
117-- data ElasticsearchError = ElasticsearchError
118-- data ElasticsearchError = ElasticsearchError
118-- { status :: Int
119-- { status :: Int
119−-- , error :: T.Text } deriving (Show, Generic)
120+-- , error :: Text } deriving (Show, Generic)
121-- instance FromJSON ElasticsearchError
122-- instance FromJSON ElasticsearchError
@@ -239,6 +240,23 @@ deleteDocument (Server server) indexName mappingName docId =
239 method = NHTM.methodDelete
240 method = NHTM.methodDelete
240 body = Nothing
241 body = Nothing
243+data EsResult a = EsResult { _index :: Text
248+ , _source :: a } deriving (Eq, Show)
250+instance (FromJSON a, ToJSON a) => FromJSON (EsResult a) where
251+ parseJSON (Object v) = EsResult <$>
242getDocument :: Server -> IndexName -> MappingName
260getDocument :: Server -> IndexName -> MappingName
243 -> DocumentID -> IO Reply
261 -> DocumentID -> IO Reply
244getDocument (Server server) indexName mappingName docId =
262getDocument (Server server) indexName mappingName docId =