@@ -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
@@ -1195,29 +1258,29 @@ instance Show TimeInterval where
1195instance ToJSON Aggregation where
1258instance ToJSON Aggregation where
1196 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1259 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1197 omitNulls ["terms" .= omitNulls [ toJSON' term,
1260 omitNulls ["terms" .= omitNulls [ toJSON' term,
1198− "include" .= toJSON include,
1261+ "include" .= include,
1199− "exclude" .= toJSON exclude,
1262+ "exclude" .= exclude,
1200− "order" .= toJSON order,
1263+ "order" .= order,
1201− "min_doc_count" .= toJSON minDocCount,
1264+ "min_doc_count" .= minDocCount,
1202− "size" .= toJSON size,
1265+ "size" .= size,
1203− "shard_size" .= toJSON shardSize,
1266+ "shard_size" .= shardSize,
1204− "collect_mode" .= toJSON collectMode,
1267+ "collect_mode" .= collectMode,
1205− "execution_hint" .= toJSON executionHint
1268+ "execution_hint" .= executionHint
1207− "aggs" .= toJSON termAggs ]
1270+ "aggs" .= termAggs ]
1209− toJSON' x = case x of { Left y -> "field" .= toJSON y; Right y -> "script" .= toJSON y }
1272+ 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)) =
1274 toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
1212− omitNulls ["date_histogram" .= omitNulls [ "field" .= toJSON field,
1275+ omitNulls ["date_histogram" .= omitNulls [ "field" .= field,
1213− "interval" .= toJSON interval,
1276+ "interval" .= interval,
1214− "format" .= toJSON format,
1277+ "format" .= format,
1215− "pre_zone" .= toJSON preZone,
1278+ "pre_zone" .= preZone,
1216− "post_zone" .= toJSON postZone,
1279+ "post_zone" .= postZone,
1217− "pre_offset" .= toJSON preOffset,
1280+ "pre_offset" .= preOffset,
1218− "post_offset" .= toJSON postOffset
1281+ "post_offset" .= postOffset
1220− "aggs" .= toJSON dateHistoAggs ]
1283+ "aggs" .= dateHistoAggs ]
1222type AggregationResults = M.Map Text Value
1285type AggregationResults = M.Map Text Value
@@ -1295,7 +1358,7 @@ instance ToJSON Filter where
1296 toJSON (NotFilter notFilter cache) =
1359 toJSON (NotFilter notFilter cache) =
1297 object ["not" .=
1360 object ["not" .=
1298− object ["filter" .= toJSON notFilter
1361+ object ["filter" .= notFilter
1299 , "_cache" .= cache]]
1362 , "_cache" .= cache]]
1301 toJSON (IdentityFilter) =
1364 toJSON (IdentityFilter) =
@@ -1311,26 +1374,26 @@ instance ToJSON Filter where
1311 ["field" .= fieldName]]
1374 ["field" .= fieldName]]
1313 toJSON (BoolFilter boolMatch) =
1376 toJSON (BoolFilter boolMatch) =
1314− object ["bool" .= toJSON boolMatch]
1377+ object ["bool" .= boolMatch]
1316 toJSON (GeoBoundingBoxFilter bbConstraint) =
1379 toJSON (GeoBoundingBoxFilter bbConstraint) =
1317− object ["geo_bounding_box" .= toJSON bbConstraint]
1380+ object ["geo_bounding_box" .= bbConstraint]
1319 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1382 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1320 distance distanceType optimizeBbox cache) =
1383 distance distanceType optimizeBbox cache) =
1321 object ["geo_distance" .=
1384 object ["geo_distance" .=
1322− object ["distance" .= toJSON distance
1385+ object ["distance" .= distance
1323− , "distance_type" .= toJSON distanceType
1386+ , "distance_type" .= distanceType
1324 , "optimize_bbox" .= optimizeBbox
1387 , "optimize_bbox" .= optimizeBbox
1325− , distanceGeoField .= toJSON geoDistLatLon
1388+ , distanceGeoField .= geoDistLatLon
1326 , "_cache" .= cache]]
1389 , "_cache" .= cache]]
1328 toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1391 toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1329 (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1392 (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1330 object ["geo_distance_range" .=
1393 object ["geo_distance_range" .=
1331− object ["from" .= toJSON geoDistRangeDistFrom
1394+ object ["from" .= geoDistRangeDistFrom
1332− , "to" .= toJSON drDistanceTo
1395+ , "to" .= drDistanceTo
1333− , gddrField .= toJSON drLatLon]]
1396+ , gddrField .= drLatLon]]
1335 toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1398 toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1336 object ["geo_polygon" .=
1399 object ["geo_polygon" .=
@@ -1340,7 +1403,7 @@ instance ToJSON Filter where
1340 toJSON (IdsFilter (MappingName mappingName) values) =
1403 toJSON (IdsFilter (MappingName mappingName) values) =
1341 object ["ids" .=
1404 object ["ids" .=
1342 object ["type" .= mappingName
1405 object ["type" .= mappingName
1343− , "values" .= fmap (T.pack . unpackId) values]]
1406+ , "values" .= fmap unpackId values]]
1345 toJSON (LimitFilter limit) =
1408 toJSON (LimitFilter limit) =
1346 object ["limit" .= object ["value" .= limit]]
1409 object ["limit" .= object ["value" .= limit]]
@@ -1359,7 +1422,7 @@ instance ToJSON Filter where
1359 toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1422 toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1360 object ["range" .=
1423 object ["range" .=
1361 object [ fieldName .= object (rangeValueToPair rangeValue)
1424 object [ fieldName .= object (rangeValueToPair rangeValue)
1362− , "execution" .= toJSON rangeExecution
1425+ , "execution" .= rangeExecution
1363 , "_cache" .= cache]]
1426 , "_cache" .= cache]]
1365 toJSON (RegexpFilter (FieldName fieldName)
1428 toJSON (RegexpFilter (FieldName fieldName)
@@ -1367,14 +1430,14 @@ instance ToJSON Filter where
1367 object ["regexp" .=
1430 object ["regexp" .=
1368 object [fieldName .=
1431 object [fieldName .=
1369 object ["value" .= regexText
1432 object ["value" .= regexText
1370− , "flags" .= toJSON flags]
1433+ , "flags" .= flags]
1371 , "_name" .= cacheName
1434 , "_name" .= cacheName
1372 , "_cache" .= cache
1435 , "_cache" .= cache
1373 , "_cache_key" .= cacheKey]]
1436 , "_cache_key" .= cacheKey]]
1375instance ToJSON GeoPoint where
1438instance ToJSON GeoPoint where
1376 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1439 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1377− object [ geoPointField .= toJSON geoPointLatLon ]
1440+ object [ geoPointField .= geoPointLatLon ]
1380instance ToJSON Query where
1443instance ToJSON Query where
@@ -1394,82 +1457,82 @@ instance ToJSON Query where
1394 getTermValue (Term _ v) = v
1457 getTermValue (Term _ v) = v
1395 toJSON (IdsQuery idsQueryMappingName docIds) =
1458 toJSON (IdsQuery idsQueryMappingName docIds) =
1396 object [ "ids" .= object conjoined ]
1459 object [ "ids" .= object conjoined ]
1397− where conjoined = [ "type" .= toJSON idsQueryMappingName
1460+ where conjoined = [ "type" .= idsQueryMappingName
1398 , "values" .= fmap toJSON docIds ]
1461 , "values" .= fmap toJSON docIds ]
1400 toJSON (QueryQueryStringQuery qQueryStringQuery) =
1463 toJSON (QueryQueryStringQuery qQueryStringQuery) =
1401− object [ "query_string" .= toJSON qQueryStringQuery ]
1464+ object [ "query_string" .= qQueryStringQuery ]
1403 toJSON (QueryMatchQuery matchQuery) =
1466 toJSON (QueryMatchQuery matchQuery) =
1404− object [ "match" .= toJSON matchQuery ]
1467+ object [ "match" .= matchQuery ]
1406 toJSON (QueryMultiMatchQuery multiMatchQuery) =
1469 toJSON (QueryMultiMatchQuery multiMatchQuery) =
1407 toJSON multiMatchQuery
1470 toJSON multiMatchQuery
1409 toJSON (QueryBoolQuery boolQuery) =
1472 toJSON (QueryBoolQuery boolQuery) =
1410− object [ "bool" .= toJSON boolQuery ]
1473+ object [ "bool" .= boolQuery ]
1412 toJSON (QueryBoostingQuery boostingQuery) =
1475 toJSON (QueryBoostingQuery boostingQuery) =
1413− object [ "boosting" .= toJSON boostingQuery ]
1476+ object [ "boosting" .= boostingQuery ]
1415 toJSON (QueryCommonTermsQuery commonTermsQuery) =
1478 toJSON (QueryCommonTermsQuery commonTermsQuery) =
1416− object [ "common" .= toJSON commonTermsQuery ]
1479+ object [ "common" .= commonTermsQuery ]
1418 toJSON (ConstantScoreFilter csFilter boost) =
1481 toJSON (ConstantScoreFilter csFilter boost) =
1419− object [ "constant_score" .= toJSON csFilter
1482+ object [ "constant_score" .= csFilter
1420− , "boost" .= toJSON boost]
1483+ , "boost" .= boost]
1422 toJSON (ConstantScoreQuery query boost) =
1485 toJSON (ConstantScoreQuery query boost) =
1423− object [ "constant_score" .= toJSON query
1486+ object [ "constant_score" .= query
1424− , "boost" .= toJSON boost]
1487+ , "boost" .= boost]
1426 toJSON (QueryDisMaxQuery disMaxQuery) =
1489 toJSON (QueryDisMaxQuery disMaxQuery) =
1427− object [ "dis_max" .= toJSON disMaxQuery ]
1490+ object [ "dis_max" .= disMaxQuery ]
1429 toJSON (QueryFilteredQuery qFilteredQuery) =
1492 toJSON (QueryFilteredQuery qFilteredQuery) =
1430− object [ "filtered" .= toJSON qFilteredQuery ]
1493+ object [ "filtered" .= qFilteredQuery ]
1432 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1495 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1433− object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
1496+ object [ "fuzzy_like_this" .= fuzzyQuery ]
1435 toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1498 toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1436− object [ "fuzzy_like_this_field" .= toJSON fuzzyFieldQuery ]
1499+ object [ "fuzzy_like_this_field" .= fuzzyFieldQuery ]
1438 toJSON (QueryFuzzyQuery fuzzyQuery) =
1501 toJSON (QueryFuzzyQuery fuzzyQuery) =
1439− object [ "fuzzy" .= toJSON fuzzyQuery ]
1502+ object [ "fuzzy" .= fuzzyQuery ]
1441 toJSON (QueryHasChildQuery childQuery) =
1504 toJSON (QueryHasChildQuery childQuery) =
1442− object [ "has_child" .= toJSON childQuery ]
1505+ object [ "has_child" .= childQuery ]
1444 toJSON (QueryHasParentQuery parentQuery) =
1507 toJSON (QueryHasParentQuery parentQuery) =
1445− object [ "has_parent" .= toJSON parentQuery ]
1508+ object [ "has_parent" .= parentQuery ]
1447 toJSON (QueryIndicesQuery qIndicesQuery) =
1510 toJSON (QueryIndicesQuery qIndicesQuery) =
1448− object [ "indices" .= toJSON qIndicesQuery ]
1511+ object [ "indices" .= qIndicesQuery ]
1450 toJSON (MatchAllQuery boost) =
1513 toJSON (MatchAllQuery boost) =
1451 object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1514 object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1453 toJSON (QueryMoreLikeThisQuery query) =
1516 toJSON (QueryMoreLikeThisQuery query) =
1454− object [ "more_like_this" .= toJSON query ]
1517+ object [ "more_like_this" .= query ]
1456 toJSON (QueryMoreLikeThisFieldQuery query) =
1519 toJSON (QueryMoreLikeThisFieldQuery query) =
1457− object [ "more_like_this_field" .= toJSON query ]
1520+ object [ "more_like_this_field" .= query ]
1459 toJSON (QueryNestedQuery query) =
1522 toJSON (QueryNestedQuery query) =
1460− object [ "nested" .= toJSON query ]
1523+ object [ "nested" .= query ]
1462 toJSON (QueryPrefixQuery query) =
1525 toJSON (QueryPrefixQuery query) =
1463− object [ "prefix" .= toJSON query ]
1526+ object [ "prefix" .= query ]
1465 toJSON (QueryRangeQuery query) =
1528 toJSON (QueryRangeQuery query) =
1466− object [ "range" .= toJSON query ]
1529+ object [ "range" .= query ]
1468 toJSON (QueryRegexpQuery query) =
1531 toJSON (QueryRegexpQuery query) =
1469− object [ "regexp" .= toJSON query ]
1532+ object [ "regexp" .= query ]
1471 toJSON (QuerySimpleQueryStringQuery query) =
1534 toJSON (QuerySimpleQueryStringQuery query) =
1472− object [ "simple_query_string" .= toJSON query ]
1535+ object [ "simple_query_string" .= query ]
1475omitNulls :: [(Text, Value)] -> Value
1538omitNulls :: [(Text, Value)] -> Value
@@ -1482,7 +1545,7 @@ omitNulls = object . filter notNull where
1482instance ToJSON SimpleQueryStringQuery where
1545instance ToJSON SimpleQueryStringQuery where
1483 toJSON SimpleQueryStringQuery {..} =
1546 toJSON SimpleQueryStringQuery {..} =
1484 omitNulls (base ++ maybeAdd)
1547 omitNulls (base ++ maybeAdd)
1485− where base = [ "query" .= toJSON simpleQueryStringQuery ]
1548+ where base = [ "query" .= simpleQueryStringQuery ]
1486 maybeAdd = [ "fields" .= simpleQueryStringField
1549 maybeAdd = [ "fields" .= simpleQueryStringField
1487 , "default_operator" .= simpleQueryStringOperator
1550 , "default_operator" .= simpleQueryStringOperator
1488 , "analyzer" .= simpleQueryStringAnalyzer
1551 , "analyzer" .= simpleQueryStringAnalyzer
@@ -1518,7 +1581,7 @@ instance ToJSON RegexpQuery where
1518 rqQueryBoost) =
1581 rqQueryBoost) =
1519 object [ rqQueryField .= omitNulls base ]
1582 object [ rqQueryField .= omitNulls base ]
1520 where base = [ "value" .= regexpQueryQuery
1583 where base = [ "value" .= regexpQueryQuery
1521− , "flags" .= toJSON rqQueryFlags
1584+ , "flags" .= rqQueryFlags
1522 , "boost" .= rqQueryBoost ]
1585 , "boost" .= rqQueryBoost ]
@@ -1534,7 +1597,7 @@ instance ToJSON QueryStringQuery where
1534 qsLenient qsLocale) =
1597 qsLenient qsLocale) =
1535 omitNulls base
1598 omitNulls base
1537− base = [ "query" .= toJSON qsQueryString
1600+ base = [ "query" .= qsQueryString
1538 , "default_field" .= qsDefaultField
1601 , "default_field" .= qsDefaultField
1539 , "default_operator" .= qsOperator
1602 , "default_operator" .= qsOperator
1540 , "analyzer" .= qsAnalyzer
1603 , "analyzer" .= qsAnalyzer
@@ -1556,21 +1619,21 @@ instance ToJSON QueryStringQuery where
1556instance ToJSON RangeQuery where
1619instance ToJSON RangeQuery where
1557 toJSON (RangeQuery (FieldName fieldName) range boost) =
1620 toJSON (RangeQuery (FieldName fieldName) range boost) =
1558 object [ fieldName .= conjoined ]
1621 object [ fieldName .= conjoined ]
1559− where conjoined = [ "boost" .= toJSON boost ] ++ (rangeValueToPair range)
1622+ where conjoined = [ "boost" .= boost ] ++ (rangeValueToPair range)
1562instance ToJSON PrefixQuery where
1625instance ToJSON PrefixQuery where
1563 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1626 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1564 object [ fieldName .= omitNulls base ]
1627 object [ fieldName .= omitNulls base ]
1565− where base = [ "value" .= toJSON queryValue
1628+ where base = [ "value" .= queryValue
1566 , "boost" .= boost ]
1629 , "boost" .= boost ]
1569instance ToJSON NestedQuery where
1632instance ToJSON NestedQuery where
1570 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1633 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1571− object [ "path" .= toJSON nqPath
1634+ object [ "path" .= nqPath
1572− , "score_mode" .= toJSON nqScoreType
1635+ , "score_mode" .= nqScoreType
1573− , "query" .= toJSON nqQuery ]
1636+ , "query" .= nqQuery ]
1576instance ToJSON MoreLikeThisFieldQuery where
1639instance ToJSON MoreLikeThisFieldQuery where
@@ -1578,7 +1641,7 @@ instance ToJSON MoreLikeThisFieldQuery where
1578 percent mtf mqt stopwords mindf maxdf
1641 percent mtf mqt stopwords mindf maxdf
1579 minwl maxwl boostTerms boost analyzer) =
1642 minwl maxwl boostTerms boost analyzer) =
1580 object [ fieldName .= omitNulls base ]
1643 object [ fieldName .= omitNulls base ]
1581− where base = [ "like_text" .= toJSON text
1644+ where base = [ "like_text" .= text
1582 , "percent_terms_to_match" .= percent
1645 , "percent_terms_to_match" .= percent
1583 , "min_term_freq" .= mtf
1646 , "min_term_freq" .= mtf
1584 , "max_query_terms" .= mqt
1647 , "max_query_terms" .= mqt
@@ -1597,7 +1660,7 @@ instance ToJSON MoreLikeThisQuery where
1597 mtf mqt stopwords mindf maxdf
1660 mtf mqt stopwords mindf maxdf
1598 minwl maxwl boostTerms boost analyzer) =
1661 minwl maxwl boostTerms boost analyzer) =
1599 omitNulls base
1662 omitNulls base
1600− where base = [ "like_text" .= toJSON text
1663+ where base = [ "like_text" .= text
1601 , "fields" .= fields
1664 , "fields" .= fields
1602 , "percent_terms_to_match" .= percent
1665 , "percent_terms_to_match" .= percent
1603 , "min_term_freq" .= mtf
1666 , "min_term_freq" .= mtf
@@ -1614,34 +1677,34 @@ instance ToJSON MoreLikeThisQuery where
1615instance ToJSON IndicesQuery where
1678instance ToJSON IndicesQuery where
1616 toJSON (IndicesQuery indices query noMatch) =
1679 toJSON (IndicesQuery indices query noMatch) =
1617− omitNulls [ "indices" .= toJSON indices
1680+ omitNulls [ "indices" .= indices
1618− , "no_match_query" .= toJSON noMatch
1681+ , "no_match_query" .= noMatch
1619− , "query" .= toJSON query ]
1682+ , "query" .= query ]
1622instance ToJSON HasParentQuery where
1685instance ToJSON HasParentQuery where
1623 toJSON (HasParentQuery queryType query scoreType) =
1686 toJSON (HasParentQuery queryType query scoreType) =
1624− omitNulls [ "parent_type" .= toJSON queryType
1687+ omitNulls [ "parent_type" .= queryType
1625− , "score_type" .= toJSON scoreType
1688+ , "score_type" .= scoreType
1626− , "query" .= toJSON query ]
1689+ , "query" .= query ]
1629instance ToJSON HasChildQuery where
1692instance ToJSON HasChildQuery where
1630 toJSON (HasChildQuery queryType query scoreType) =
1693 toJSON (HasChildQuery queryType query scoreType) =
1631− omitNulls [ "query" .= toJSON query
1694+ omitNulls [ "query" .= query
1632− , "score_type" .= toJSON scoreType
1695+ , "score_type" .= scoreType
1633− , "type" .= toJSON queryType ]
1696+ , "type" .= queryType ]
1636instance ToJSON FuzzyQuery where
1699instance ToJSON FuzzyQuery where
1637 toJSON (FuzzyQuery (FieldName fieldName) queryText
1700 toJSON (FuzzyQuery (FieldName fieldName) queryText
1638 prefixLength maxEx fuzziness boost) =
1701 prefixLength maxEx fuzziness boost) =
1639 object [ fieldName .= omitNulls base ]
1702 object [ fieldName .= omitNulls base ]
1640− where base = [ "value" .= toJSON queryText
1703+ where base = [ "value" .= queryText
1641− , "fuzziness" .= toJSON fuzziness
1704+ , "fuzziness" .= fuzziness
1642− , "prefix_length" .= toJSON prefixLength
1705+ , "prefix_length" .= prefixLength
1643− , "boost" .= toJSON boost
1706+ , "boost" .= boost
1644− , "max_expansions" .= toJSON maxEx ]
1707+ , "max_expansions" .= maxEx ]
1647instance ToJSON FuzzyLikeFieldQuery where
1710instance ToJSON FuzzyLikeFieldQuery where
@@ -1649,41 +1712,41 @@ instance ToJSON FuzzyLikeFieldQuery where
1649 fieldText maxTerms ignoreFreq fuzziness prefixLength
1712 fieldText maxTerms ignoreFreq fuzziness prefixLength
1650 boost analyzer) =
1713 boost analyzer) =
1651 object [ fieldName .=
1714 object [ fieldName .=
1652− omitNulls [ "like_text" .= toJSON fieldText
1715+ omitNulls [ "like_text" .= fieldText
1653− , "max_query_terms" .= toJSON maxTerms
1716+ , "max_query_terms" .= maxTerms
1654− , "ignore_tf" .= toJSON ignoreFreq
1717+ , "ignore_tf" .= ignoreFreq
1655− , "fuzziness" .= toJSON fuzziness
1718+ , "fuzziness" .= fuzziness
1656− , "prefix_length" .= toJSON prefixLength
1719+ , "prefix_length" .= prefixLength
1657− , "analyzer" .= toJSON analyzer
1720+ , "analyzer" .= analyzer
1658− , "boost" .= toJSON boost ]]
1721+ , "boost" .= boost ]]
1661instance ToJSON FuzzyLikeThisQuery where
1724instance ToJSON FuzzyLikeThisQuery where
1662 toJSON (FuzzyLikeThisQuery fields text maxTerms
1725 toJSON (FuzzyLikeThisQuery fields text maxTerms
1663 ignoreFreq fuzziness prefixLength boost analyzer) =
1726 ignoreFreq fuzziness prefixLength boost analyzer) =
1664 omitNulls base
1727 omitNulls base
1665− where base = [ "fields" .= toJSON fields
1728+ where base = [ "fields" .= fields
1666− , "like_text" .= toJSON text
1729+ , "like_text" .= text
1667− , "max_query_terms" .= toJSON maxTerms
1730+ , "max_query_terms" .= maxTerms
1668− , "ignore_tf" .= toJSON ignoreFreq
1731+ , "ignore_tf" .= ignoreFreq
1669− , "fuzziness" .= toJSON fuzziness
1732+ , "fuzziness" .= fuzziness
1670− , "prefix_length" .= toJSON prefixLength
1733+ , "prefix_length" .= prefixLength
1671− , "analyzer" .= toJSON analyzer
1734+ , "analyzer" .= analyzer
1672− , "boost" .= toJSON boost ]
1735+ , "boost" .= boost ]
1675instance ToJSON FilteredQuery where
1738instance ToJSON FilteredQuery where
1676 toJSON (FilteredQuery query fFilter) =
1739 toJSON (FilteredQuery query fFilter) =
1677− object [ "query" .= toJSON query
1740+ object [ "query" .= query
1678− , "filter" .= toJSON fFilter ]
1741+ , "filter" .= fFilter ]
1681instance ToJSON DisMaxQuery where
1744instance ToJSON DisMaxQuery where
1682 toJSON (DisMaxQuery queries tiebreaker boost) =
1745 toJSON (DisMaxQuery queries tiebreaker boost) =
1683 omitNulls base
1746 omitNulls base
1684− where base = [ "queries" .= toJSON queries
1747+ where base = [ "queries" .= queries
1685− , "boost" .= toJSON boost
1748+ , "boost" .= boost
1686− , "tie_breaker" .= toJSON tiebreaker ]
1749+ , "tie_breaker" .= tiebreaker ]
1689instance ToJSON CommonTermsQuery where
1752instance ToJSON CommonTermsQuery where
@@ -1691,38 +1754,38 @@ instance ToJSON CommonTermsQuery where
1691 (QueryString query) cf lfo hfo msm
1754 (QueryString query) cf lfo hfo msm
1692 boost analyzer disableCoord) =
1755 boost analyzer disableCoord) =
1693 object [fieldName .= omitNulls base ]
1756 object [fieldName .= omitNulls base ]
1694− where base = [ "query" .= toJSON query
1757+ where base = [ "query" .= query
1695− , "cutoff_frequency" .= toJSON cf
1758+ , "cutoff_frequency" .= cf
1696− , "low_freq_operator" .= toJSON lfo
1759+ , "low_freq_operator" .= lfo
1697− , "minimum_should_match" .= toJSON msm
1760+ , "minimum_should_match" .= msm
1698− , "boost" .= toJSON boost
1761+ , "boost" .= boost
1699− , "analyzer" .= toJSON analyzer
1762+ , "analyzer" .= analyzer
1700− , "disable_coord" .= toJSON disableCoord
1763+ , "disable_coord" .= disableCoord
1701− , "high_freq_operator" .= toJSON hfo ]
1764+ , "high_freq_operator" .= hfo ]
1704instance ToJSON CommonMinimumMatch where
1767instance ToJSON CommonMinimumMatch where
1705 toJSON (CommonMinimumMatch mm) = toJSON mm
1768 toJSON (CommonMinimumMatch mm) = toJSON mm
1706 toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1769 toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1707− object [ "low_freq" .= toJSON lowF
1770+ object [ "low_freq" .= lowF
1708− , "high_freq" .= toJSON highF ]
1771+ , "high_freq" .= highF ]
1710instance ToJSON BoostingQuery where
1773instance ToJSON BoostingQuery where
1711 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1774 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1712− object [ "positive" .= toJSON bqPositiveQuery
1775+ object [ "positive" .= bqPositiveQuery
1713− , "negative" .= toJSON bqNegativeQuery
1776+ , "negative" .= bqNegativeQuery
1714− , "negative_boost" .= toJSON bqNegativeBoost ]
1777+ , "negative_boost" .= bqNegativeBoost ]
1717instance ToJSON BoolQuery where
1780instance ToJSON BoolQuery where
1718 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1781 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1719 omitNulls base
1782 omitNulls base
1720− where base = [ "must" .= toJSON mustM
1783+ where base = [ "must" .= mustM
1721− , "must_not" .= toJSON notM
1784+ , "must_not" .= notM
1722− , "should" .= toJSON shouldM
1785+ , "should" .= shouldM
1723− , "minimum_should_match" .= toJSON bqMin
1786+ , "minimum_should_match" .= bqMin
1724− , "boost" .= toJSON boost
1787+ , "boost" .= boost
1725− , "disable_coord" .= toJSON disableCoord ]
1788+ , "disable_coord" .= disableCoord ]
1728instance ToJSON MatchQuery where
1791instance ToJSON MatchQuery where
@@ -1732,13 +1795,13 @@ instance ToJSON MatchQuery where
1732 analyzer maxExpansions lenient) =
1795 analyzer maxExpansions lenient) =
1733 object [ fieldName .= omitNulls base ]
1796 object [ fieldName .= omitNulls base ]
1734 where base = [ "query" .= mqQueryString
1797 where base = [ "query" .= mqQueryString
1735− , "operator" .= toJSON booleanOperator
1798+ , "operator" .= booleanOperator
1736− , "zero_terms_query" .= toJSON zeroTermsQuery
1799+ , "zero_terms_query" .= zeroTermsQuery
1737− , "cutoff_frequency" .= toJSON cutoffFrequency
1800+ , "cutoff_frequency" .= cutoffFrequency
1738− , "type" .= toJSON matchQueryType
1801+ , "type" .= matchQueryType
1739− , "analyzer" .= toJSON analyzer
1802+ , "analyzer" .= analyzer
1740− , "max_expansions" .= toJSON maxExpansions
1803+ , "max_expansions" .= maxExpansions
1741− , "lenient" .= toJSON lenient ]
1804+ , "lenient" .= lenient ]
1744instance ToJSON MultiMatchQuery where
1807instance ToJSON MultiMatchQuery where
@@ -1747,14 +1810,14 @@ instance ToJSON MultiMatchQuery where
1747 object ["multi_match" .= omitNulls base]
1810 object ["multi_match" .= omitNulls base]
1748 where base = [ "fields" .= fmap toJSON fields
1811 where base = [ "fields" .= fmap toJSON fields
1749 , "query" .= query
1812 , "query" .= query
1750− , "operator" .= toJSON boolOp
1813+ , "operator" .= boolOp
1751− , "zero_terms_query" .= toJSON ztQ
1814+ , "zero_terms_query" .= ztQ
1752− , "tiebreaker" .= toJSON tb
1815+ , "tiebreaker" .= tb
1753− , "type" .= toJSON mmqt
1816+ , "type" .= mmqt
1754− , "cutoff_frequency" .= toJSON cf
1817+ , "cutoff_frequency" .= cf
1755− , "analyzer" .= toJSON analyzer
1818+ , "analyzer" .= analyzer
1756− , "max_expansions" .= toJSON maxEx
1819+ , "max_expansions" .= maxEx
1757− , "lenient" .= toJSON lenient ]
1820+ , "lenient" .= lenient ]
1760instance ToJSON MultiMatchQueryType where
1823instance ToJSON MultiMatchQueryType where
@@ -1866,7 +1929,7 @@ instance ToJSON FieldHighlight where
1867instance ToJSON Highlights where
1930instance ToJSON Highlights where
1868 toJSON (Highlights global fields) =
1931 toJSON (Highlights global fields) =
1869− omitNulls (("fields" .= toJSON fields)
1932+ omitNulls (("fields" .= fields)
1870 : highlightSettingsPairs global)
1933 : highlightSettingsPairs global)
1872instance ToJSON HighlightSettings where
1935instance ToJSON HighlightSettings where
@@ -1944,16 +2007,16 @@ instance ToJSON SortSpec where
1944 (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
2007 (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
1945 dsSortMode dsMissingSort dsNestedFilter)) =
2008 dsSortMode dsMissingSort dsNestedFilter)) =
1946 object [dsSortFieldName .= omitNulls base] where
2009 object [dsSortFieldName .= omitNulls base] where
1947− base = [ "order" .= toJSON dsSortOrder
2010+ base = [ "order" .= dsSortOrder
1948 , "ignore_unmapped" .= dsIgnoreUnmapped
2011 , "ignore_unmapped" .= dsIgnoreUnmapped
1949 , "mode" .= dsSortMode
2012 , "mode" .= dsSortMode
1950 , "missing" .= dsMissingSort
2013 , "missing" .= dsMissingSort
1951 , "nested_filter" .= dsNestedFilter ]
2014 , "nested_filter" .= dsNestedFilter ]
1953 toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
2016 toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
1954− object [ "unit" .= toJSON units
2017+ object [ "unit" .= units
1955− , field .= toJSON gdsLatLon
2018+ , field .= gdsLatLon
1956− , "order" .= toJSON gdsSortOrder ]
2019+ , "order" .= gdsSortOrder ]
1959instance ToJSON SortOrder where
2022instance ToJSON SortOrder where
@@ -2015,7 +2078,7 @@ instance ToJSON OptimizeBbox where
2015instance ToJSON GeoBoundingBoxConstraint where
2078instance ToJSON GeoBoundingBoxConstraint where
2016 toJSON (GeoBoundingBoxConstraint
2079 toJSON (GeoBoundingBoxConstraint
2017 (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2080 (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2018− object [gbbcGeoBBField .= toJSON gbbcConstraintBox
2081+ object [gbbcGeoBBField .= gbbcConstraintBox
2019 , "_cache" .= cache
2082 , "_cache" .= cache
2020 , "type" .= type']
2083 , "type" .= type']
@@ -2027,8 +2090,8 @@ instance ToJSON GeoFilterType where
2028instance ToJSON GeoBoundingBox where
2091instance ToJSON GeoBoundingBox where
2029 toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2092 toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2030− object ["top_left" .= toJSON gbbTopLeft
2093+ object ["top_left" .= gbbTopLeft
2031− , "bottom_right" .= toJSON gbbBottomRight]
2094+ , "bottom_right" .= gbbBottomRight]
2034instance ToJSON LatLon where
2097instance ToJSON LatLon where
@@ -2061,9 +2124,9 @@ instance ToJSON Term where
2063instance ToJSON BoolMatch where
2126instance ToJSON BoolMatch where
2064− toJSON (MustMatch term cache) = object ["must" .= toJSON term,
2127+ toJSON (MustMatch term cache) = object ["must" .= term,
2065 "_cache" .= cache]
2128 "_cache" .= cache]
2066− toJSON (MustNotMatch term cache) = object ["must_not" .= toJSON term,
2129+ toJSON (MustNotMatch term cache) = object ["must_not" .= term,
2067 "_cache" .= cache]
2130 "_cache" .= cache]
2068 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2131 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2069 "_cache" .= cache]
2132 "_cache" .= cache]