@@ -4,6 +4,8 @@ module Database.Bloodhound.Client
4 ( createIndex
4 ( createIndex
5 , deleteIndex
5 , deleteIndex
6 , defaultIndexSettings
6 , defaultIndexSettings
7 , indexDocument
9 , indexDocument
8 , getDocument
10 , getDocument
9 , documentExists
11 , documentExists
@@ -26,6 +28,11 @@ module Database.Bloodhound.Client
26 , Seminearring(..)
28 , Seminearring(..)
27 , BoolMatch(..)
29 , BoolMatch(..)
28 , Term(..)
30 , Term(..)
32+ , GeoBoundingBoxConstraint(..)
@@ -158,6 +165,12 @@ indexExists (Server server) indexName = do
158 return exists where
165 return exists where
159 url = joinPath [server, indexName]
166 url = joinPath [server, indexName]
168+refreshIndex :: Server -> IndexName -> IO Reply
169+refreshIndex (Server server) indexName = dispatch url method body where
170+ url = joinPath [server, indexName, "_refresh"]
171+ method = NHTM.methodPost
161data OpenCloseIndex = OpenIndex | CloseIndex deriving (Show)
174data OpenCloseIndex = OpenIndex | CloseIndex deriving (Show)
163stringifyOCIndex oci = case oci of
176stringifyOCIndex oci = case oci of
@@ -180,6 +193,24 @@ closeIndex = openOrCloseIndexes CloseIndex
181type MappingName = String
194type MappingName = String
196+data FieldType = GeoPointType
202+ | ByteType deriving (Eq, Show)
204+data FieldDefinition =
205+ FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
208+ MappingField { fieldName :: Text
209+ , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
211+data Mapping = Mapping { typeName :: Text
212+ , fields :: [MappingField] } deriving (Eq, Show)
183createMapping :: ToJSON a => Server -> IndexName
214createMapping :: ToJSON a => Server -> IndexName
184 -> MappingName -> a -> IO Reply
215 -> MappingName -> a -> IO Reply
185createMapping (Server server) indexName mappingName mapping =
216createMapping (Server server) indexName mappingName mapping =
@@ -261,12 +292,6 @@ searchByType :: Server -> IndexName -> MappingName -> Search -> IO Reply
261searchByType (Server server) indexName mappingName search = dispatchSearch url search where
292searchByType (Server server) indexName mappingName search = dispatchSearch url search where
262 url = joinPath [server, indexName, mappingName, "_search"]
293 url = joinPath [server, indexName, mappingName, "_search"]
264−refreshIndex :: Server -> IndexName -> IO Reply
265−refreshIndex (Server server) indexName = dispatch url method body where
266− url = joinPath [server, indexName, "_refresh"]
267− method = NHTM.methodPost
270data Search = Search { queryBody :: Maybe Query
295data Search = Search { queryBody :: Maybe Query
271 , filterBody :: Maybe Filter } deriving (Show)
296 , filterBody :: Maybe Filter } deriving (Show)
@@ -340,8 +365,8 @@ data Filter = AndFilter [Filter] Cache
340 | IdentityFilter
365 | IdentityFilter
341 | BoolFilter BoolMatch
366 | BoolFilter BoolMatch
342 | ExistsFilter FieldName -- always cached
367 | ExistsFilter FieldName -- always cached
343− | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType Cache
368+ | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType
344− | GeoDistanceFilter GeoConstraint Distance Cache
369+ | GeoDistanceFilter GeoConstraint Distance
345 deriving (Show)
370 deriving (Show)
347class Monoid a => Seminearring a where
372class Monoid a => Seminearring a where
@@ -374,6 +399,28 @@ instance ToJSON Filter where
374 ["field" .= fieldName]]
399 ["field" .= fieldName]]
375 toJSON (BoolFilter boolMatch) =
400 toJSON (BoolFilter boolMatch) =
376 object ["bool" .= toJSON boolMatch]
401 object ["bool" .= toJSON boolMatch]
402+ toJSON (GeoBoundingBoxFilter bbConstraint filterType) =
403+ object ["geo_bounding_box" .= toJSON bbConstraint
404+ , "type" .= toJSON filterType]
406+instance ToJSON GeoBoundingBoxConstraint where
407+ toJSON (GeoBoundingBoxConstraint geoBBField constraintBox cache) =
408+ object [geoBBField .= toJSON constraintBox
409+ , "_cache" .= cache]
411+instance ToJSON GeoFilterType where
412+ toJSON GeoFilterMemory = "memory"
413+ toJSON GeoFilterIndexed = "indexed"
415+instance ToJSON GeoBoundingBox where
416+ toJSON (GeoBoundingBox topLeft bottomRight) =
417+ object ["top_left" .= toJSON topLeft
418+ , "bottom_right" .= toJSON bottomRight]
420+instance ToJSON LatLon where
421+ toJSON (LatLon lat lon) =
422+ object ["lat" .= lat
378data Term = Term { termField :: Text
425data Term = Term { termField :: Text
379 , termValue :: Text } deriving (Show)
426 , termValue :: Text } deriving (Show)
@@ -397,6 +444,7 @@ instance ToJSON BoolMatch where
397-- "memory" or "indexed"
444-- "memory" or "indexed"
398data GeoFilterType = GeoFilterMemory | GeoFilterIndexed deriving (Show)
445data GeoFilterType = GeoFilterMemory | GeoFilterIndexed deriving (Show)
400data LatLon = LatLon { lat :: Double
448data LatLon = LatLon { lat :: Double
401 , lon :: Double } deriving (Show)
449 , lon :: Double } deriving (Show)
@@ -407,6 +455,7 @@ data GeoBoundingBox =
407data GeoBoundingBoxConstraint =
455data GeoBoundingBoxConstraint =
408 GeoBoundingBoxConstraint { geoBBField :: FieldName
456 GeoBoundingBoxConstraint { geoBBField :: FieldName
409 , constraintBox :: GeoBoundingBox
457 , constraintBox :: GeoBoundingBox
410 } deriving (Show)
459 } deriving (Show)
412data GeoConstraint =
461data GeoConstraint =
@@ -426,7 +475,7 @@ data DistanceUnits = Miles
426data DistanceType = Arc | SloppyArc | Plane deriving (Show)
475data DistanceType = Arc | SloppyArc | Plane deriving (Show)
428-- geo_point?
477-- geo_point?
429−data OptimizeBbox = GeoFilterType | NoOptimizeBbox deriving (Show)
478+data OptimizeBbox = OptimizeGeoFilterType GeoFilterType | NoOptimizeBbox deriving (Show)
431data Distance =
480data Distance =
432 Distance { coefficient :: Double
481 Distance { coefficient :: Double