@@ -1,6 +1,11 @@
1−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5+{-# LANGUAGE MultiParamTypeClasses #-}
2−{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE RecordWildCards #-}
7+{-# LANGUAGE RecordWildCards #-}
8+{-# LANGUAGE UndecidableInstances #-}
5-------------------------------------------------------------------------------
10-------------------------------------------------------------------------------
@@ -39,6 +44,10 @@ module Database.Bloodhound.Types
40 , toDateHistogram
45 , toDateHistogram
41 , omitNulls
46 , omitNulls
42 , Version(..)
51 , Version(..)
43 , Status(..)
52 , Status(..)
44 , Existence(..)
53 , Existence(..)
@@ -51,6 +60,9 @@ module Database.Bloodhound.Types
51 , Search(..)
60 , Search(..)
52 , SearchResult(..)
61 , SearchResult(..)
53 , SearchHits(..)
62 , SearchHits(..)
54 , ShardResult(..)
66 , ShardResult(..)
56 , Filter(..)
68 , Filter(..)
@@ -138,6 +150,8 @@ module Database.Bloodhound.Types
138 , IgnoreTermFrequency(..)
150 , IgnoreTermFrequency(..)
139 , MaxQueryTerms(..)
151 , MaxQueryTerms(..)
140 , ScoreType(..)
152 , ScoreType(..)
141 , TypeName(..)
155 , TypeName(..)
142 , BoostTerms(..)
156 , BoostTerms(..)
143 , MaxWordLength(..)
157 , MaxWordLength(..)
@@ -194,13 +208,16 @@ module Database.Bloodhound.Types
196import Control.Applicative
210import Control.Applicative
211+import Control.Monad.Error
212+import Control.Monad.Reader
213+import Control.Monad.State
214+import Control.Monad.Writer
197import Data.Aeson
215import Data.Aeson
198import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
216import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
199import qualified Data.ByteString.Lazy.Char8 as L
217import qualified Data.ByteString.Lazy.Char8 as L
200import Data.List (nub)
218import Data.List (nub)
201−import Data.List.NonEmpty (NonEmpty(..), toList)
219+import Data.List.NonEmpty (NonEmpty (..), toList)
202import qualified Data.Map.Strict as M
220import qualified Data.Map.Strict as M
204import Data.Text (Text)
221import Data.Text (Text)
205import qualified Data.Text as T
222import qualified Data.Text as T
206import Data.Time.Clock (UTCTime)
223import Data.Time.Clock (UTCTime)
@@ -222,6 +239,52 @@ import Database.Bloodhound.Types.Class
222-- defaultIndexSettings is exported by Database.Bloodhound as well
239-- defaultIndexSettings is exported by Database.Bloodhound as well
223-- no trailing slashes in servers, library handles building the path.
240-- no trailing slashes in servers, library handles building the path.
242+{-| Common environment for Elasticsearch calls. Connections will be
243+ pipelined according to the provided HTTP connection manager.
245+data BHEnv = BHEnv { bhServer :: Server
246+ , bhManager :: Manager
249+{-| All API calls to Elasticsearch operate within
250+ MonadBH. The idea is that it can be easily embedded in your
251+ own monad transformer stack. A default instance for a ReaderT and
252+ alias 'BH' is provided for the simple case.
254+class (Functor m, Applicative m, MonadIO m) => MonadBH m where
257+newtype BH m a = BH {
258+ unBH :: ReaderT BHEnv m a
259+ } deriving ( Functor
270+instance MonadTrans BH where
273+instance (MonadReader r m) => MonadReader r (BH m) where
275+ local f (BH (ReaderT m)) = BH $ ReaderT $ \r ->
278+instance (Functor m, Applicative m, MonadIO m) => MonadBH (BH m) where
279+ getBHEnv = BH getBHEnv
282+instance (Functor m, Applicative m, MonadIO m) => MonadBH (ReaderT BHEnv m) where
285+runBH :: BHEnv -> BH m a -> m a
286+runBH e f = runReaderT (unBH f) e
225{-| 'Version' is embedded in 'Status' -}
288{-| 'Version' is embedded in 'Status' -}
226data Version = Version { number :: Text
289data Version = Version { number :: Text
227 , build_hash :: Text
290 , build_hash :: Text
@@ -400,22 +463,22 @@ newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic)
401{-| 'Server' is used with the client functions to point at the ES instance
464{-| 'Server' is used with the client functions to point at the ES instance
403−newtype Server = Server String deriving (Eq, Show)
466+newtype Server = Server Text deriving (Eq, Show)
405{-| 'IndexName' is used to describe which index to query/create/delete
468{-| 'IndexName' is used to describe which index to query/create/delete
407−newtype IndexName = IndexName String deriving (Eq, Generic, Show)
470+newtype IndexName = IndexName Text deriving (Eq, Generic, Show)
409{-| 'MappingName' is part of mappings which are how ES describes and schematizes
472{-| 'MappingName' is part of mappings which are how ES describes and schematizes
410 the data in the indices.
473 the data in the indices.
412−newtype MappingName = MappingName String deriving (Eq, Generic, Show)
475+newtype MappingName = MappingName Text deriving (Eq, Generic, Show)
414{-| 'DocId' is a generic wrapper value for expressing unique Document IDs.
477{-| 'DocId' is a generic wrapper value for expressing unique Document IDs.
415 Can be set by the user or created by ES itself. Often used in client
478 Can be set by the user or created by ES itself. Often used in client
416 functions for poking at specific documents.
479 functions for poking at specific documents.
418−newtype DocId = DocId String deriving (Eq, Generic, Show)
481+newtype DocId = DocId Text deriving (Eq, Generic, Show)
420{-| 'QueryString' is used to wrap query text bodies, be they human written or not.
483{-| 'QueryString' is used to wrap query text bodies, be they human written or not.
@@ -526,12 +589,12 @@ newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic)
527{-| 'unpackId' is a silly convenience function that gets used once.
590{-| 'unpackId' is a silly convenience function that gets used once.
529−unpackId :: DocId -> String
592+unpackId :: DocId -> Text
530unpackId (DocId docId) = docId
593unpackId (DocId docId) = docId
532type TrackSortScores = Bool
595type TrackSortScores = Bool
533−type From = Int
596+newtype From = From Int deriving (Eq, Show, ToJSON)
534−type Size = Int
597+newtype Size = Size Int deriving (Eq, Show, ToJSON)
536data Search = Search { queryBody :: Maybe Query
599data Search = Search { queryBody :: Maybe Query
537 , filterBody :: Maybe Filter
600 , filterBody :: Maybe Filter
@@ -1055,13 +1118,20 @@ data SearchResult a =
1055 , searchHits :: SearchHits a
1118 , searchHits :: SearchHits a
1056 , aggregations :: Maybe AggregationResults } deriving (Eq, Show)
1119 , aggregations :: Maybe AggregationResults } deriving (Eq, Show)
1058−type Score = Double
1121+type Score = Maybe Double
1060data SearchHits a =
1123data SearchHits a =
1061 SearchHits { hitsTotal :: Int
1124 SearchHits { hitsTotal :: Int
1062 , maxScore :: Score
1125 , maxScore :: Score
1063 , hits :: [Hit a] } deriving (Eq, Show)
1126 , hits :: [Hit a] } deriving (Eq, Show)
1129+instance Monoid (SearchHits a) where
1130+ mempty = SearchHits 0 Nothing mempty
1131+ mappend (SearchHits ta ma ha) (SearchHits tb mb hb) =
1132+ SearchHits (ta + tb) (max ma mb) (ha <> hb)
1065data Hit a =
1135data Hit a =
1066 Hit { hitIndex :: IndexName
1136 Hit { hitIndex :: IndexName
1067 , hitType :: MappingName
1137 , hitType :: MappingName
@@ -1195,29 +1265,29 @@ instance Show TimeInterval where
1195instance ToJSON Aggregation where
1265instance ToJSON Aggregation where
1196 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1266 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1197 omitNulls ["terms" .= omitNulls [ toJSON' term,
1267 omitNulls ["terms" .= omitNulls [ toJSON' term,
1198− "include" .= toJSON include,
1268+ "include" .= include,
1199− "exclude" .= toJSON exclude,
1269+ "exclude" .= exclude,
1200− "order" .= toJSON order,
1270+ "order" .= order,
1201− "min_doc_count" .= toJSON minDocCount,
1271+ "min_doc_count" .= minDocCount,
1202− "size" .= toJSON size,
1272+ "size" .= size,
1203− "shard_size" .= toJSON shardSize,
1273+ "shard_size" .= shardSize,
1204− "collect_mode" .= toJSON collectMode,
1274+ "collect_mode" .= collectMode,
1205− "execution_hint" .= toJSON executionHint
1275+ "execution_hint" .= executionHint
1207− "aggs" .= toJSON termAggs ]
1277+ "aggs" .= termAggs ]
1209− toJSON' x = case x of { Left y -> "field" .= toJSON y; Right y -> "script" .= toJSON y }
1279+ toJSON' x = case x of { Left y -> "field" .= y; Right y -> "script" .= y }
1211 toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
1281 toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
1212− omitNulls ["date_histogram" .= omitNulls [ "field" .= toJSON field,
1282+ omitNulls ["date_histogram" .= omitNulls [ "field" .= field,
1213− "interval" .= toJSON interval,
1283+ "interval" .= interval,
1214− "format" .= toJSON format,
1284+ "format" .= format,
1215− "pre_zone" .= toJSON preZone,
1285+ "pre_zone" .= preZone,
1216− "post_zone" .= toJSON postZone,
1286+ "post_zone" .= postZone,
1217− "pre_offset" .= toJSON preOffset,
1287+ "pre_offset" .= preOffset,
1218− "post_offset" .= toJSON postOffset
1288+ "post_offset" .= postOffset
1220− "aggs" .= toJSON dateHistoAggs ]
1290+ "aggs" .= dateHistoAggs ]
1222type AggregationResults = M.Map Text Value
1292type AggregationResults = M.Map Text Value
@@ -1296,7 +1366,7 @@ instance ToJSON Filter where
1297 toJSON (NotFilter notFilter cache) =
1367 toJSON (NotFilter notFilter cache) =
1298 object ["not" .=
1368 object ["not" .=
1299− object ["filter" .= toJSON notFilter
1369+ object ["filter" .= notFilter
1300 , "_cache" .= cache]]
1370 , "_cache" .= cache]]
1302 toJSON (IdentityFilter) =
1372 toJSON (IdentityFilter) =
@@ -1312,26 +1382,26 @@ instance ToJSON Filter where
1312 ["field" .= fieldName]]
1382 ["field" .= fieldName]]
1314 toJSON (BoolFilter boolMatch) =
1384 toJSON (BoolFilter boolMatch) =
1315− object ["bool" .= toJSON boolMatch]
1385+ object ["bool" .= boolMatch]
1317 toJSON (GeoBoundingBoxFilter bbConstraint) =
1387 toJSON (GeoBoundingBoxFilter bbConstraint) =
1318− object ["geo_bounding_box" .= toJSON bbConstraint]
1388+ object ["geo_bounding_box" .= bbConstraint]
1320 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1390 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1321 distance distanceType optimizeBbox cache) =
1391 distance distanceType optimizeBbox cache) =
1322 object ["geo_distance" .=
1392 object ["geo_distance" .=
1323− object ["distance" .= toJSON distance
1393+ object ["distance" .= distance
1324− , "distance_type" .= toJSON distanceType
1394+ , "distance_type" .= distanceType
1325 , "optimize_bbox" .= optimizeBbox
1395 , "optimize_bbox" .= optimizeBbox
1326− , distanceGeoField .= toJSON geoDistLatLon
1396+ , distanceGeoField .= geoDistLatLon
1327 , "_cache" .= cache]]
1397 , "_cache" .= cache]]
1329 toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1399 toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1330 (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1400 (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1331 object ["geo_distance_range" .=
1401 object ["geo_distance_range" .=
1332− object ["from" .= toJSON geoDistRangeDistFrom
1402+ object ["from" .= geoDistRangeDistFrom
1333− , "to" .= toJSON drDistanceTo
1403+ , "to" .= drDistanceTo
1334− , gddrField .= toJSON drLatLon]]
1404+ , gddrField .= drLatLon]]
1336 toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1406 toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1337 object ["geo_polygon" .=
1407 object ["geo_polygon" .=
@@ -1341,7 +1411,7 @@ instance ToJSON Filter where
1341 toJSON (IdsFilter (MappingName mappingName) values) =
1411 toJSON (IdsFilter (MappingName mappingName) values) =
1342 object ["ids" .=
1412 object ["ids" .=
1343 object ["type" .= mappingName
1413 object ["type" .= mappingName
1344− , "values" .= fmap (T.pack . unpackId) values]]
1414+ , "values" .= fmap unpackId values]]
1346 toJSON (LimitFilter limit) =
1416 toJSON (LimitFilter limit) =
1347 object ["limit" .= object ["value" .= limit]]
1417 object ["limit" .= object ["value" .= limit]]
@@ -1360,7 +1430,7 @@ instance ToJSON Filter where
1360 toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1430 toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1361 object ["range" .=
1431 object ["range" .=
1362 object [ fieldName .= object (rangeValueToPair rangeValue)
1432 object [ fieldName .= object (rangeValueToPair rangeValue)
1363− , "execution" .= toJSON rangeExecution
1433+ , "execution" .= rangeExecution
1364 , "_cache" .= cache]]
1434 , "_cache" .= cache]]
1366 toJSON (RegexpFilter (FieldName fieldName)
1436 toJSON (RegexpFilter (FieldName fieldName)
@@ -1368,14 +1438,14 @@ instance ToJSON Filter where
1368 object ["regexp" .=
1438 object ["regexp" .=
1369 object [fieldName .=
1439 object [fieldName .=
1370 object ["value" .= regexText
1440 object ["value" .= regexText
1371− , "flags" .= toJSON flags]
1441+ , "flags" .= flags]
1372 , "_name" .= cacheName
1442 , "_name" .= cacheName
1373 , "_cache" .= cache
1443 , "_cache" .= cache
1374 , "_cache_key" .= cacheKey]]
1444 , "_cache_key" .= cacheKey]]
1376instance ToJSON GeoPoint where
1446instance ToJSON GeoPoint where
1377 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1447 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1378− object [ geoPointField .= toJSON geoPointLatLon ]
1448+ object [ geoPointField .= geoPointLatLon ]
1381instance ToJSON Query where
1451instance ToJSON Query where
@@ -1395,82 +1465,82 @@ instance ToJSON Query where
1395 getTermValue (Term _ v) = v
1465 getTermValue (Term _ v) = v
1396 toJSON (IdsQuery idsQueryMappingName docIds) =
1466 toJSON (IdsQuery idsQueryMappingName docIds) =
1397 object [ "ids" .= object conjoined ]
1467 object [ "ids" .= object conjoined ]
1398− where conjoined = [ "type" .= toJSON idsQueryMappingName
1468+ where conjoined = [ "type" .= idsQueryMappingName
1399 , "values" .= fmap toJSON docIds ]
1469 , "values" .= fmap toJSON docIds ]
1401 toJSON (QueryQueryStringQuery qQueryStringQuery) =
1471 toJSON (QueryQueryStringQuery qQueryStringQuery) =
1402− object [ "query_string" .= toJSON qQueryStringQuery ]
1472+ object [ "query_string" .= qQueryStringQuery ]
1404 toJSON (QueryMatchQuery matchQuery) =
1474 toJSON (QueryMatchQuery matchQuery) =
1405− object [ "match" .= toJSON matchQuery ]
1475+ object [ "match" .= matchQuery ]
1407 toJSON (QueryMultiMatchQuery multiMatchQuery) =
1477 toJSON (QueryMultiMatchQuery multiMatchQuery) =
1408 toJSON multiMatchQuery
1478 toJSON multiMatchQuery
1410 toJSON (QueryBoolQuery boolQuery) =
1480 toJSON (QueryBoolQuery boolQuery) =
1411− object [ "bool" .= toJSON boolQuery ]
1481+ object [ "bool" .= boolQuery ]
1413 toJSON (QueryBoostingQuery boostingQuery) =
1483 toJSON (QueryBoostingQuery boostingQuery) =
1414− object [ "boosting" .= toJSON boostingQuery ]
1484+ object [ "boosting" .= boostingQuery ]
1416 toJSON (QueryCommonTermsQuery commonTermsQuery) =
1486 toJSON (QueryCommonTermsQuery commonTermsQuery) =
1417− object [ "common" .= toJSON commonTermsQuery ]
1487+ object [ "common" .= commonTermsQuery ]
1419 toJSON (ConstantScoreFilter csFilter boost) =
1489 toJSON (ConstantScoreFilter csFilter boost) =
1420− object [ "constant_score" .= toJSON csFilter
1490+ object [ "constant_score" .= csFilter
1421− , "boost" .= toJSON boost]
1491+ , "boost" .= boost]
1423 toJSON (ConstantScoreQuery query boost) =
1493 toJSON (ConstantScoreQuery query boost) =
1424− object [ "constant_score" .= toJSON query
1494+ object [ "constant_score" .= query
1425− , "boost" .= toJSON boost]
1495+ , "boost" .= boost]
1427 toJSON (QueryDisMaxQuery disMaxQuery) =
1497 toJSON (QueryDisMaxQuery disMaxQuery) =
1428− object [ "dis_max" .= toJSON disMaxQuery ]
1498+ object [ "dis_max" .= disMaxQuery ]
1430 toJSON (QueryFilteredQuery qFilteredQuery) =
1500 toJSON (QueryFilteredQuery qFilteredQuery) =
1431− object [ "filtered" .= toJSON qFilteredQuery ]
1501+ object [ "filtered" .= qFilteredQuery ]
1433 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1503 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1434− object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
1504+ object [ "fuzzy_like_this" .= fuzzyQuery ]
1436 toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1506 toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1437− object [ "fuzzy_like_this_field" .= toJSON fuzzyFieldQuery ]
1507+ object [ "fuzzy_like_this_field" .= fuzzyFieldQuery ]
1439 toJSON (QueryFuzzyQuery fuzzyQuery) =
1509 toJSON (QueryFuzzyQuery fuzzyQuery) =
1440− object [ "fuzzy" .= toJSON fuzzyQuery ]
1510+ object [ "fuzzy" .= fuzzyQuery ]
1442 toJSON (QueryHasChildQuery childQuery) =
1512 toJSON (QueryHasChildQuery childQuery) =
1443− object [ "has_child" .= toJSON childQuery ]
1513+ object [ "has_child" .= childQuery ]
1445 toJSON (QueryHasParentQuery parentQuery) =
1515 toJSON (QueryHasParentQuery parentQuery) =
1446− object [ "has_parent" .= toJSON parentQuery ]
1516+ object [ "has_parent" .= parentQuery ]
1448 toJSON (QueryIndicesQuery qIndicesQuery) =
1518 toJSON (QueryIndicesQuery qIndicesQuery) =
1449− object [ "indices" .= toJSON qIndicesQuery ]
1519+ object [ "indices" .= qIndicesQuery ]
1451 toJSON (MatchAllQuery boost) =
1521 toJSON (MatchAllQuery boost) =
1452 object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1522 object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1454 toJSON (QueryMoreLikeThisQuery query) =
1524 toJSON (QueryMoreLikeThisQuery query) =
1455− object [ "more_like_this" .= toJSON query ]
1525+ object [ "more_like_this" .= query ]
1457 toJSON (QueryMoreLikeThisFieldQuery query) =
1527 toJSON (QueryMoreLikeThisFieldQuery query) =
1458− object [ "more_like_this_field" .= toJSON query ]
1528+ object [ "more_like_this_field" .= query ]
1460 toJSON (QueryNestedQuery query) =
1530 toJSON (QueryNestedQuery query) =
1461− object [ "nested" .= toJSON query ]
1531+ object [ "nested" .= query ]
1463 toJSON (QueryPrefixQuery query) =
1533 toJSON (QueryPrefixQuery query) =
1464− object [ "prefix" .= toJSON query ]
1534+ object [ "prefix" .= query ]
1466 toJSON (QueryRangeQuery query) =
1536 toJSON (QueryRangeQuery query) =
1467− object [ "range" .= toJSON query ]
1537+ object [ "range" .= query ]
1469 toJSON (QueryRegexpQuery query) =
1539 toJSON (QueryRegexpQuery query) =
1470− object [ "regexp" .= toJSON query ]
1540+ object [ "regexp" .= query ]
1472 toJSON (QuerySimpleQueryStringQuery query) =
1542 toJSON (QuerySimpleQueryStringQuery query) =
1473− object [ "simple_query_string" .= toJSON query ]
1543+ object [ "simple_query_string" .= query ]
1476omitNulls :: [(Text, Value)] -> Value
1546omitNulls :: [(Text, Value)] -> Value
@@ -1483,7 +1553,7 @@ omitNulls = object . filter notNull where
1483instance ToJSON SimpleQueryStringQuery where
1553instance ToJSON SimpleQueryStringQuery where
1484 toJSON SimpleQueryStringQuery {..} =
1554 toJSON SimpleQueryStringQuery {..} =
1485 omitNulls (base ++ maybeAdd)
1555 omitNulls (base ++ maybeAdd)
1486− where base = [ "query" .= toJSON simpleQueryStringQuery ]
1556+ where base = [ "query" .= simpleQueryStringQuery ]
1487 maybeAdd = [ "fields" .= simpleQueryStringField
1557 maybeAdd = [ "fields" .= simpleQueryStringField
1488 , "default_operator" .= simpleQueryStringOperator
1558 , "default_operator" .= simpleQueryStringOperator
1489 , "analyzer" .= simpleQueryStringAnalyzer
1559 , "analyzer" .= simpleQueryStringAnalyzer
@@ -1519,7 +1589,7 @@ instance ToJSON RegexpQuery where
1519 rqQueryBoost) =
1589 rqQueryBoost) =
1520 object [ rqQueryField .= omitNulls base ]
1590 object [ rqQueryField .= omitNulls base ]
1521 where base = [ "value" .= regexpQueryQuery
1591 where base = [ "value" .= regexpQueryQuery
1522− , "flags" .= toJSON rqQueryFlags
1592+ , "flags" .= rqQueryFlags
1523 , "boost" .= rqQueryBoost ]
1593 , "boost" .= rqQueryBoost ]
@@ -1535,7 +1605,7 @@ instance ToJSON QueryStringQuery where
1535 qsLenient qsLocale) =
1605 qsLenient qsLocale) =
1536 omitNulls base
1606 omitNulls base
1538− base = [ "query" .= toJSON qsQueryString
1608+ base = [ "query" .= qsQueryString
1539 , "default_field" .= qsDefaultField
1609 , "default_field" .= qsDefaultField
1540 , "default_operator" .= qsOperator
1610 , "default_operator" .= qsOperator
1541 , "analyzer" .= qsAnalyzer
1611 , "analyzer" .= qsAnalyzer
@@ -1557,21 +1627,21 @@ instance ToJSON QueryStringQuery where
1557instance ToJSON RangeQuery where
1627instance ToJSON RangeQuery where
1558 toJSON (RangeQuery (FieldName fieldName) range boost) =
1628 toJSON (RangeQuery (FieldName fieldName) range boost) =
1559 object [ fieldName .= conjoined ]
1629 object [ fieldName .= conjoined ]
1560− where conjoined = [ "boost" .= toJSON boost ] ++ (rangeValueToPair range)
1630+ where conjoined = [ "boost" .= boost ] ++ (rangeValueToPair range)
1563instance ToJSON PrefixQuery where
1633instance ToJSON PrefixQuery where
1564 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1634 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1565 object [ fieldName .= omitNulls base ]
1635 object [ fieldName .= omitNulls base ]
1566− where base = [ "value" .= toJSON queryValue
1636+ where base = [ "value" .= queryValue
1567 , "boost" .= boost ]
1637 , "boost" .= boost ]
1570instance ToJSON NestedQuery where
1640instance ToJSON NestedQuery where
1571 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1641 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1572− object [ "path" .= toJSON nqPath
1642+ object [ "path" .= nqPath
1573− , "score_mode" .= toJSON nqScoreType
1643+ , "score_mode" .= nqScoreType
1574− , "query" .= toJSON nqQuery ]
1644+ , "query" .= nqQuery ]
1577instance ToJSON MoreLikeThisFieldQuery where
1647instance ToJSON MoreLikeThisFieldQuery where
@@ -1579,7 +1649,7 @@ instance ToJSON MoreLikeThisFieldQuery where
1579 percent mtf mqt stopwords mindf maxdf
1649 percent mtf mqt stopwords mindf maxdf
1580 minwl maxwl boostTerms boost analyzer) =
1650 minwl maxwl boostTerms boost analyzer) =
1581 object [ fieldName .= omitNulls base ]
1651 object [ fieldName .= omitNulls base ]
1582− where base = [ "like_text" .= toJSON text
1652+ where base = [ "like_text" .= text
1583 , "percent_terms_to_match" .= percent
1653 , "percent_terms_to_match" .= percent
1584 , "min_term_freq" .= mtf
1654 , "min_term_freq" .= mtf
1585 , "max_query_terms" .= mqt
1655 , "max_query_terms" .= mqt
@@ -1598,7 +1668,7 @@ instance ToJSON MoreLikeThisQuery where
1598 mtf mqt stopwords mindf maxdf
1668 mtf mqt stopwords mindf maxdf
1599 minwl maxwl boostTerms boost analyzer) =
1669 minwl maxwl boostTerms boost analyzer) =
1600 omitNulls base
1670 omitNulls base
1601− where base = [ "like_text" .= toJSON text
1671+ where base = [ "like_text" .= text
1602 , "fields" .= fields
1672 , "fields" .= fields
1603 , "percent_terms_to_match" .= percent
1673 , "percent_terms_to_match" .= percent
1604 , "min_term_freq" .= mtf
1674 , "min_term_freq" .= mtf
@@ -1615,34 +1685,34 @@ instance ToJSON MoreLikeThisQuery where
1616instance ToJSON IndicesQuery where
1686instance ToJSON IndicesQuery where
1617 toJSON (IndicesQuery indices query noMatch) =
1687 toJSON (IndicesQuery indices query noMatch) =
1618− omitNulls [ "indices" .= toJSON indices
1688+ omitNulls [ "indices" .= indices
1619− , "no_match_query" .= toJSON noMatch
1689+ , "no_match_query" .= noMatch
1620− , "query" .= toJSON query ]
1690+ , "query" .= query ]
1623instance ToJSON HasParentQuery where
1693instance ToJSON HasParentQuery where
1624 toJSON (HasParentQuery queryType query scoreType) =
1694 toJSON (HasParentQuery queryType query scoreType) =
1625− omitNulls [ "parent_type" .= toJSON queryType
1695+ omitNulls [ "parent_type" .= queryType
1626− , "score_type" .= toJSON scoreType
1696+ , "score_type" .= scoreType
1627− , "query" .= toJSON query ]
1697+ , "query" .= query ]
1630instance ToJSON HasChildQuery where
1700instance ToJSON HasChildQuery where
1631 toJSON (HasChildQuery queryType query scoreType) =
1701 toJSON (HasChildQuery queryType query scoreType) =
1632− omitNulls [ "query" .= toJSON query
1702+ omitNulls [ "query" .= query
1633− , "score_type" .= toJSON scoreType
1703+ , "score_type" .= scoreType
1634− , "type" .= toJSON queryType ]
1704+ , "type" .= queryType ]
1637instance ToJSON FuzzyQuery where
1707instance ToJSON FuzzyQuery where
1638 toJSON (FuzzyQuery (FieldName fieldName) queryText
1708 toJSON (FuzzyQuery (FieldName fieldName) queryText
1639 prefixLength maxEx fuzziness boost) =
1709 prefixLength maxEx fuzziness boost) =
1640 object [ fieldName .= omitNulls base ]
1710 object [ fieldName .= omitNulls base ]
1641− where base = [ "value" .= toJSON queryText
1711+ where base = [ "value" .= queryText
1642− , "fuzziness" .= toJSON fuzziness
1712+ , "fuzziness" .= fuzziness
1643− , "prefix_length" .= toJSON prefixLength
1713+ , "prefix_length" .= prefixLength
1644− , "boost" .= toJSON boost
1714+ , "boost" .= boost
1645− , "max_expansions" .= toJSON maxEx ]
1715+ , "max_expansions" .= maxEx ]
1648instance ToJSON FuzzyLikeFieldQuery where
1718instance ToJSON FuzzyLikeFieldQuery where
@@ -1650,41 +1720,41 @@ instance ToJSON FuzzyLikeFieldQuery where
1650 fieldText maxTerms ignoreFreq fuzziness prefixLength
1720 fieldText maxTerms ignoreFreq fuzziness prefixLength
1651 boost analyzer) =
1721 boost analyzer) =
1652 object [ fieldName .=
1722 object [ fieldName .=
1653− omitNulls [ "like_text" .= toJSON fieldText
1723+ omitNulls [ "like_text" .= fieldText
1654− , "max_query_terms" .= toJSON maxTerms
1724+ , "max_query_terms" .= maxTerms
1655− , "ignore_tf" .= toJSON ignoreFreq
1725+ , "ignore_tf" .= ignoreFreq
1656− , "fuzziness" .= toJSON fuzziness
1726+ , "fuzziness" .= fuzziness
1657− , "prefix_length" .= toJSON prefixLength
1727+ , "prefix_length" .= prefixLength
1658− , "analyzer" .= toJSON analyzer
1728+ , "analyzer" .= analyzer
1659− , "boost" .= toJSON boost ]]
1729+ , "boost" .= boost ]]
1662instance ToJSON FuzzyLikeThisQuery where
1732instance ToJSON FuzzyLikeThisQuery where
1663 toJSON (FuzzyLikeThisQuery fields text maxTerms
1733 toJSON (FuzzyLikeThisQuery fields text maxTerms
1664 ignoreFreq fuzziness prefixLength boost analyzer) =
1734 ignoreFreq fuzziness prefixLength boost analyzer) =
1665 omitNulls base
1735 omitNulls base
1666− where base = [ "fields" .= toJSON fields
1736+ where base = [ "fields" .= fields
1667− , "like_text" .= toJSON text
1737+ , "like_text" .= text
1668− , "max_query_terms" .= toJSON maxTerms
1738+ , "max_query_terms" .= maxTerms
1669− , "ignore_tf" .= toJSON ignoreFreq
1739+ , "ignore_tf" .= ignoreFreq
1670− , "fuzziness" .= toJSON fuzziness
1740+ , "fuzziness" .= fuzziness
1671− , "prefix_length" .= toJSON prefixLength
1741+ , "prefix_length" .= prefixLength
1672− , "analyzer" .= toJSON analyzer
1742+ , "analyzer" .= analyzer
1673− , "boost" .= toJSON boost ]
1743+ , "boost" .= boost ]
1676instance ToJSON FilteredQuery where
1746instance ToJSON FilteredQuery where
1677 toJSON (FilteredQuery query fFilter) =
1747 toJSON (FilteredQuery query fFilter) =
1678− object [ "query" .= toJSON query
1748+ object [ "query" .= query
1679− , "filter" .= toJSON fFilter ]
1749+ , "filter" .= fFilter ]
1682instance ToJSON DisMaxQuery where
1752instance ToJSON DisMaxQuery where
1683 toJSON (DisMaxQuery queries tiebreaker boost) =
1753 toJSON (DisMaxQuery queries tiebreaker boost) =
1684 omitNulls base
1754 omitNulls base
1685− where base = [ "queries" .= toJSON queries
1755+ where base = [ "queries" .= queries
1686− , "boost" .= toJSON boost
1756+ , "boost" .= boost
1687− , "tie_breaker" .= toJSON tiebreaker ]
1757+ , "tie_breaker" .= tiebreaker ]
1690instance ToJSON CommonTermsQuery where
1760instance ToJSON CommonTermsQuery where
@@ -1692,38 +1762,38 @@ instance ToJSON CommonTermsQuery where
1692 (QueryString query) cf lfo hfo msm
1762 (QueryString query) cf lfo hfo msm
1693 boost analyzer disableCoord) =
1763 boost analyzer disableCoord) =
1694 object [fieldName .= omitNulls base ]
1764 object [fieldName .= omitNulls base ]
1695− where base = [ "query" .= toJSON query
1765+ where base = [ "query" .= query
1696− , "cutoff_frequency" .= toJSON cf
1766+ , "cutoff_frequency" .= cf
1697− , "low_freq_operator" .= toJSON lfo
1767+ , "low_freq_operator" .= lfo
1698− , "minimum_should_match" .= toJSON msm
1768+ , "minimum_should_match" .= msm
1699− , "boost" .= toJSON boost
1769+ , "boost" .= boost
1700− , "analyzer" .= toJSON analyzer
1770+ , "analyzer" .= analyzer
1701− , "disable_coord" .= toJSON disableCoord
1771+ , "disable_coord" .= disableCoord
1702− , "high_freq_operator" .= toJSON hfo ]
1772+ , "high_freq_operator" .= hfo ]
1705instance ToJSON CommonMinimumMatch where
1775instance ToJSON CommonMinimumMatch where
1706 toJSON (CommonMinimumMatch mm) = toJSON mm
1776 toJSON (CommonMinimumMatch mm) = toJSON mm
1707 toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1777 toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1708− object [ "low_freq" .= toJSON lowF
1778+ object [ "low_freq" .= lowF
1709− , "high_freq" .= toJSON highF ]
1779+ , "high_freq" .= highF ]
1711instance ToJSON BoostingQuery where
1781instance ToJSON BoostingQuery where
1712 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1782 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1713− object [ "positive" .= toJSON bqPositiveQuery
1783+ object [ "positive" .= bqPositiveQuery
1714− , "negative" .= toJSON bqNegativeQuery
1784+ , "negative" .= bqNegativeQuery
1715− , "negative_boost" .= toJSON bqNegativeBoost ]
1785+ , "negative_boost" .= bqNegativeBoost ]
1718instance ToJSON BoolQuery where
1788instance ToJSON BoolQuery where
1719 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1789 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1720 omitNulls base
1790 omitNulls base
1721− where base = [ "must" .= toJSON mustM
1791+ where base = [ "must" .= mustM
1722− , "must_not" .= toJSON notM
1792+ , "must_not" .= notM
1723− , "should" .= toJSON shouldM
1793+ , "should" .= shouldM
1724− , "minimum_should_match" .= toJSON bqMin
1794+ , "minimum_should_match" .= bqMin
1725− , "boost" .= toJSON boost
1795+ , "boost" .= boost
1726− , "disable_coord" .= toJSON disableCoord ]
1796+ , "disable_coord" .= disableCoord ]
1729instance ToJSON MatchQuery where
1799instance ToJSON MatchQuery where
@@ -1733,13 +1803,13 @@ instance ToJSON MatchQuery where
1733 analyzer maxExpansions lenient) =
1803 analyzer maxExpansions lenient) =
1734 object [ fieldName .= omitNulls base ]
1804 object [ fieldName .= omitNulls base ]
1735 where base = [ "query" .= mqQueryString
1805 where base = [ "query" .= mqQueryString
1736− , "operator" .= toJSON booleanOperator
1806+ , "operator" .= booleanOperator
1737− , "zero_terms_query" .= toJSON zeroTermsQuery
1807+ , "zero_terms_query" .= zeroTermsQuery
1738− , "cutoff_frequency" .= toJSON cutoffFrequency
1808+ , "cutoff_frequency" .= cutoffFrequency
1739− , "type" .= toJSON matchQueryType
1809+ , "type" .= matchQueryType
1740− , "analyzer" .= toJSON analyzer
1810+ , "analyzer" .= analyzer
1741− , "max_expansions" .= toJSON maxExpansions
1811+ , "max_expansions" .= maxExpansions
1742− , "lenient" .= toJSON lenient ]
1812+ , "lenient" .= lenient ]
1745instance ToJSON MultiMatchQuery where
1815instance ToJSON MultiMatchQuery where
@@ -1748,14 +1818,14 @@ instance ToJSON MultiMatchQuery where
1748 object ["multi_match" .= omitNulls base]
1818 object ["multi_match" .= omitNulls base]
1749 where base = [ "fields" .= fmap toJSON fields
1819 where base = [ "fields" .= fmap toJSON fields
1750 , "query" .= query
1820 , "query" .= query
1751− , "operator" .= toJSON boolOp
1821+ , "operator" .= boolOp
1752− , "zero_terms_query" .= toJSON ztQ
1822+ , "zero_terms_query" .= ztQ
1753− , "tiebreaker" .= toJSON tb
1823+ , "tiebreaker" .= tb
1754− , "type" .= toJSON mmqt
1824+ , "type" .= mmqt
1755− , "cutoff_frequency" .= toJSON cf
1825+ , "cutoff_frequency" .= cf
1756− , "analyzer" .= toJSON analyzer
1826+ , "analyzer" .= analyzer
1757− , "max_expansions" .= toJSON maxEx
1827+ , "max_expansions" .= maxEx
1758− , "lenient" .= toJSON lenient ]
1828+ , "lenient" .= lenient ]
1761instance ToJSON MultiMatchQueryType where
1831instance ToJSON MultiMatchQueryType where
@@ -1867,7 +1937,7 @@ instance ToJSON FieldHighlight where
1868instance ToJSON Highlights where
1938instance ToJSON Highlights where
1869 toJSON (Highlights global fields) =
1939 toJSON (Highlights global fields) =
1870− omitNulls (("fields" .= toJSON fields)
1940+ omitNulls (("fields" .= fields)
1871 : highlightSettingsPairs global)
1941 : highlightSettingsPairs global)
1873instance ToJSON HighlightSettings where
1943instance ToJSON HighlightSettings where
@@ -1945,16 +2015,16 @@ instance ToJSON SortSpec where
1945 (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
2015 (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
1946 dsSortMode dsMissingSort dsNestedFilter)) =
2016 dsSortMode dsMissingSort dsNestedFilter)) =
1947 object [dsSortFieldName .= omitNulls base] where
2017 object [dsSortFieldName .= omitNulls base] where
1948− base = [ "order" .= toJSON dsSortOrder
2018+ base = [ "order" .= dsSortOrder
1949 , "ignore_unmapped" .= dsIgnoreUnmapped
2019 , "ignore_unmapped" .= dsIgnoreUnmapped
1950 , "mode" .= dsSortMode
2020 , "mode" .= dsSortMode
1951 , "missing" .= dsMissingSort
2021 , "missing" .= dsMissingSort
1952 , "nested_filter" .= dsNestedFilter ]
2022 , "nested_filter" .= dsNestedFilter ]
1954 toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
2024 toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
1955− object [ "unit" .= toJSON units
2025+ object [ "unit" .= units
1956− , field .= toJSON gdsLatLon
2026+ , field .= gdsLatLon
1957− , "order" .= toJSON gdsSortOrder ]
2027+ , "order" .= gdsSortOrder ]
1960instance ToJSON SortOrder where
2030instance ToJSON SortOrder where
@@ -2016,7 +2086,7 @@ instance ToJSON OptimizeBbox where
2016instance ToJSON GeoBoundingBoxConstraint where
2086instance ToJSON GeoBoundingBoxConstraint where
2017 toJSON (GeoBoundingBoxConstraint
2087 toJSON (GeoBoundingBoxConstraint
2018 (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2088 (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2019− object [gbbcGeoBBField .= toJSON gbbcConstraintBox
2089+ object [gbbcGeoBBField .= gbbcConstraintBox
2020 , "_cache" .= cache
2090 , "_cache" .= cache
2021 , "type" .= type']
2091 , "type" .= type']
@@ -2028,8 +2098,8 @@ instance ToJSON GeoFilterType where
2029instance ToJSON GeoBoundingBox where
2099instance ToJSON GeoBoundingBox where
2030 toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2100 toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2031− object ["top_left" .= toJSON gbbTopLeft
2101+ object ["top_left" .= gbbTopLeft
2032− , "bottom_right" .= toJSON gbbBottomRight]
2102+ , "bottom_right" .= gbbBottomRight]
2035instance ToJSON LatLon where
2105instance ToJSON LatLon where
@@ -2062,9 +2132,9 @@ instance ToJSON Term where
2064instance ToJSON BoolMatch where
2134instance ToJSON BoolMatch where
2065− toJSON (MustMatch term cache) = object ["must" .= toJSON term,
2135+ toJSON (MustMatch term cache) = object ["must" .= term,
2066 "_cache" .= cache]
2136 "_cache" .= cache]
2067− toJSON (MustNotMatch term cache) = object ["must_not" .= toJSON term,
2137+ toJSON (MustNotMatch term cache) = object ["must_not" .= term,
2068 "_cache" .= cache]
2138 "_cache" .= cache]
2069 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2139 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2070 "_cache" .= cache]
2140 "_cache" .= cache]