@@ -4,6 +4,8 @@ module Database.Bloodhound.Client
44 ( createIndex
55 , deleteIndex
66 , defaultIndexSettings
7+ , createMapping
8+ , deleteMapping
79 , indexDocument
810 , getDocument
911 , documentExists
@@ -26,6 +28,11 @@ module Database.Bloodhound.Client
2628 , Seminearring(..)
2729 , BoolMatch(..)
2830 , Term(..)
31+ , GeoConstraint(..)
32+ , GeoBoundingBoxConstraint(..)
33+ , GeoBoundingBox(..)
34+ , GeoFilterType(..)
35+ , LatLon(..)
2936 )
3037 where
3138
@@ -158,6 +165,12 @@ indexExists (Server server) indexName = do
158165 return exists where
159166 url = joinPath [server, indexName]
160167
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
172+ body = Nothing
173+
161174data OpenCloseIndex = OpenIndex | CloseIndex deriving (Show)
162175
163176stringifyOCIndex oci = case oci of
@@ -180,6 +193,24 @@ closeIndex = openOrCloseIndexes CloseIndex
180193
181194type MappingName = String
182195
196+data FieldType = GeoPointType
197+ | GeoShapeType
198+ | FloatType
199+ | IntegerType
200+ | LongType
201+ | ShortType
202+ | ByteType deriving (Eq, Show)
203+
204+data FieldDefinition =
205+ FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
206+
207+data MappingField =
208+ MappingField { fieldName :: Text
209+ , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
210+
211+data Mapping = Mapping { typeName :: Text
212+ , fields :: [MappingField] } deriving (Eq, Show)
213+
183214createMapping :: ToJSON a => Server -> IndexName
184215 -> MappingName -> a -> IO Reply
185216createMapping (Server server) indexName mappingName mapping =
@@ -261,12 +292,6 @@ searchByType :: Server -> IndexName -> MappingName -> Search -> IO Reply
261292searchByType (Server server) indexName mappingName search = dispatchSearch url search where
262293 url = joinPath [server, indexName, mappingName, "_search"]
263294
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
268− body = Nothing
269−
270295data Search = Search { queryBody :: Maybe Query
271296 , filterBody :: Maybe Filter } deriving (Show)
272297
@@ -340,8 +365,8 @@ data Filter = AndFilter [Filter] Cache
340365 | IdentityFilter
341366 | BoolFilter BoolMatch
342367 | ExistsFilter FieldName -- always cached
343− | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType Cache
344− | GeoDistanceFilter GeoConstraint Distance Cache
368+ | GeoBoundingBoxFilter GeoBoundingBoxConstraint GeoFilterType
369+ | GeoDistanceFilter GeoConstraint Distance
345370 deriving (Show)
346371
347372class Monoid a => Seminearring a where
@@ -374,6 +399,28 @@ instance ToJSON Filter where
374399 ["field" .= fieldName]]
375400 toJSON (BoolFilter boolMatch) =
376401 object ["bool" .= toJSON boolMatch]
402+ toJSON (GeoBoundingBoxFilter bbConstraint filterType) =
403+ object ["geo_bounding_box" .= toJSON bbConstraint
404+ , "type" .= toJSON filterType]
405+
406+instance ToJSON GeoBoundingBoxConstraint where
407+ toJSON (GeoBoundingBoxConstraint geoBBField constraintBox cache) =
408+ object [geoBBField .= toJSON constraintBox
409+ , "_cache" .= cache]
410+
411+instance ToJSON GeoFilterType where
412+ toJSON GeoFilterMemory = "memory"
413+ toJSON GeoFilterIndexed = "indexed"
414+
415+instance ToJSON GeoBoundingBox where
416+ toJSON (GeoBoundingBox topLeft bottomRight) =
417+ object ["top_left" .= toJSON topLeft
418+ , "bottom_right" .= toJSON bottomRight]
419+
420+instance ToJSON LatLon where
421+ toJSON (LatLon lat lon) =
422+ object ["lat" .= lat
423+ , "lon" .= lon]
377424
378425data Term = Term { termField :: Text
379426 , termValue :: Text } deriving (Show)
@@ -397,6 +444,7 @@ instance ToJSON BoolMatch where
397444-- "memory" or "indexed"
398445data GeoFilterType = GeoFilterMemory | GeoFilterIndexed deriving (Show)
399446
447+
400448data LatLon = LatLon { lat :: Double
401449 , lon :: Double } deriving (Show)
402450
@@ -407,6 +455,7 @@ data GeoBoundingBox =
407455data GeoBoundingBoxConstraint =
408456 GeoBoundingBoxConstraint { geoBBField :: FieldName
409457 , constraintBox :: GeoBoundingBox
458+ , cache :: Cache
410459 } deriving (Show)
411460
412461data GeoConstraint =
@@ -426,7 +475,7 @@ data DistanceUnits = Miles
426475data DistanceType = Arc | SloppyArc | Plane deriving (Show)
427476
428477-- geo_point?
429−data OptimizeBbox = GeoFilterType | NoOptimizeBbox deriving (Show)
478+data OptimizeBbox = OptimizeGeoFilterType GeoFilterType | NoOptimizeBbox deriving (Show)
430479
431480data Distance =
432481 Distance { coefficient :: Double