git.iko.soy/typeable/bloodhound
on master help sign in
Drop unnecessary toJSONs
34af7bfMichael Xavier
src/Database/Bloodhound/Client.hs+14−13
@@ -58,6 +58,7 @@ import qualified Data.ByteString.Lazy.Char8 as L
58import Data.List (intercalate)
58import Data.List (intercalate)
59import Data.Maybe (fromMaybe)
59import Data.Maybe (fromMaybe)
60import Data.Text (Text)
60import Data.Text (Text)
61+import qualified Data.Text as T
61import qualified Data.Vector as V
62import qualified Data.Vector as V
62import Network.HTTP.Client
63import Network.HTTP.Client
63import qualified Network.HTTP.Types.Method as NHTM
64import qualified Network.HTTP.Types.Method as NHTM
@@ -136,7 +137,7 @@ mkReplicaCount n
136emptyBody :: L.ByteString
137emptyBody :: L.ByteString
137emptyBody = L.pack ""
138emptyBody = L.pack ""
138
139
139−dispatch :: MonadBH m => Method -> String -> Maybe L.ByteString
140+dispatch :: MonadBH m => Method -> Text -> Maybe L.ByteString
140 -> m Reply
141 -> m Reply
141dispatch dMethod url body = do
142dispatch dMethod url body = do
142 initReq <- liftIO $ parseUrl url
143 initReq <- liftIO $ parseUrl url
@@ -147,10 +148,10 @@ dispatch dMethod url body = do
147 mgr <- bhManager <$> getBHEnv
148 mgr <- bhManager <$> getBHEnv
148 liftIO $ httpLbs req mgr
149 liftIO $ httpLbs req mgr
149
150
150−joinPath' :: [String] -> String
151+joinPath' :: [Text] -> Text
151−joinPath' = intercalate "/"
152+joinPath' = T.intercalate "/"
152
153
153−joinPath :: MonadBH m => [String] -> m String
154+joinPath :: MonadBH m => [Text] -> m Text
154joinPath ps = do
155joinPath ps = do
155 Server s <- bhServer <$> getBHEnv
156 Server s <- bhServer <$> getBHEnv
156 return $ joinPath' (s:ps)
157 return $ joinPath' (s:ps)
@@ -170,15 +171,15 @@ withBH ms s f = withManager ms $ \mgr -> do
170 runBH env f
171 runBH env f
171
172
172-- Shortcut functions for HTTP methods
173-- Shortcut functions for HTTP methods
173−delete :: MonadBH m => String -> m Reply
174+delete :: MonadBH m => Text -> m Reply
174delete = flip (dispatch NHTM.methodDelete) Nothing
175delete = flip (dispatch NHTM.methodDelete) Nothing
175−get :: MonadBH m => String -> m Reply
176+get :: MonadBH m => Text -> m Reply
176get = flip (dispatch NHTM.methodGet) Nothing
177get = flip (dispatch NHTM.methodGet) Nothing
177−head :: MonadBH m => String -> m Reply
178+head :: MonadBH m => Text -> m Reply
178head = flip (dispatch NHTM.methodHead) Nothing
179head = flip (dispatch NHTM.methodHead) Nothing
179−put :: MonadBH m => String -> Maybe L.ByteString -> m Reply
180+put :: MonadBH m => Text -> Maybe L.ByteString -> m Reply
180put = dispatch NHTM.methodPost
181put = dispatch NHTM.methodPost
181−post :: MonadBH m => String -> Maybe L.ByteString -> m Reply
182+post :: MonadBH m => Text -> Maybe L.ByteString -> m Reply
182post = dispatch NHTM.methodPost
183post = dispatch NHTM.methodPost
183
184
184-- indexDocument s ix name doc = put (root </> s </> ix </> name </> doc) (Just encode doc)
185-- indexDocument s ix name doc = put (root </> s </> ix </> name </> doc) (Just encode doc)
@@ -229,7 +230,7 @@ statusCodeIs n resp = NHTS.statusCode (responseStatus resp) == n
229respIsTwoHunna :: Reply -> Bool
230respIsTwoHunna :: Reply -> Bool
230respIsTwoHunna = statusCodeIs 200
231respIsTwoHunna = statusCodeIs 200
231
232
232−existentialQuery :: MonadBH m => String -> m (Reply, Bool)
233+existentialQuery :: MonadBH m => Text -> m (Reply, Bool)
233existentialQuery url = do
234existentialQuery url = do
234 reply <- head url
235 reply <- head url
235 return (reply, respIsTwoHunna reply)
236 return (reply, respIsTwoHunna reply)
@@ -253,7 +254,7 @@ refreshIndex (IndexName indexName) =
253 bindM2 post url (return Nothing)
254 bindM2 post url (return Nothing)
254 where url = joinPath [indexName, "_refresh"]
255 where url = joinPath [indexName, "_refresh"]
255
256
256−stringifyOCIndex :: OpenCloseIndex -> String
257+stringifyOCIndex :: OpenCloseIndex -> Text
257stringifyOCIndex oci = case oci of
258stringifyOCIndex oci = case oci of
258 OpenIndex -> "_open"
259 OpenIndex -> "_open"
259 CloseIndex -> "_close"
260 CloseIndex -> "_close"
@@ -360,7 +361,7 @@ encodeBulkOperations stream = collapsed where
360mash :: Builder -> V.Vector L.ByteString -> Builder
361mash :: Builder -> V.Vector L.ByteString -> Builder
361mash = V.foldl' (\b x -> b `mappend` (byteString "\n") `mappend` (lazyByteString x))
362mash = V.foldl' (\b x -> b `mappend` (byteString "\n") `mappend` (lazyByteString x))
362
363
363−mkBulkStreamValue :: Text -> String -> String -> String -> Value
364+mkBulkStreamValue :: Text -> Text -> Text -> Text -> Value
364mkBulkStreamValue operation indexName mappingName docId =
365mkBulkStreamValue operation indexName mappingName docId =
365 object [operation .=
366 object [operation .=
366 object [ "_index" .= indexName
367 object [ "_index" .= indexName
@@ -422,7 +423,7 @@ documentExists (IndexName indexName)
422 return exists
423 return exists
423 where url = joinPath [indexName, mappingName, docId]
424 where url = joinPath [indexName, mappingName, docId]
424
425
425−dispatchSearch :: MonadBH m => String -> Search -> m Reply
426+dispatchSearch :: MonadBH m => Text -> Search -> m Reply
426dispatchSearch url search = post url (Just (encode search))
427dispatchSearch url search = post url (Just (encode search))
427
428
428-- | 'searchAll', given a 'Search', will perform that search against all indexes
429-- | 'searchAll', given a 'Search', will perform that search against all indexes
src/Database/Bloodhound/Types.hs+149−149
@@ -457,22 +457,22 @@ newtype ReplicaCount = ReplicaCount Int deriving (Eq, Show, Generic)
457
457
458{-| 'Server' is used with the client functions to point at the ES instance
458{-| 'Server' is used with the client functions to point at the ES instance
459-}
459-}
460−newtype Server = Server String deriving (Eq, Show)
460+newtype Server = Server Text deriving (Eq, Show)
461
461
462{-| 'IndexName' is used to describe which index to query/create/delete
462{-| 'IndexName' is used to describe which index to query/create/delete
463-}
463-}
464−newtype IndexName = IndexName String deriving (Eq, Generic, Show)
464+newtype IndexName = IndexName Text deriving (Eq, Generic, Show)
465
465
466{-| 'MappingName' is part of mappings which are how ES describes and schematizes
466{-| 'MappingName' is part of mappings which are how ES describes and schematizes
467 the data in the indices.
467 the data in the indices.
468-}
468-}
469−newtype MappingName = MappingName String deriving (Eq, Generic, Show)
469+newtype MappingName = MappingName Text deriving (Eq, Generic, Show)
470
470
471{-| 'DocId' is a generic wrapper value for expressing unique Document IDs.
471{-| 'DocId' is a generic wrapper value for expressing unique Document IDs.
472 Can be set by the user or created by ES itself. Often used in client
472 Can be set by the user or created by ES itself. Often used in client
473 functions for poking at specific documents.
473 functions for poking at specific documents.
474-}
474-}
475−newtype DocId = DocId String deriving (Eq, Generic, Show)
475+newtype DocId = DocId Text deriving (Eq, Generic, Show)
476
476
477{-| 'QueryString' is used to wrap query text bodies, be they human written or not.
477{-| 'QueryString' is used to wrap query text bodies, be they human written or not.
478-}
478-}
@@ -583,7 +583,7 @@ newtype MaxDocFrequency = MaxDocFrequency Int deriving (Eq, Show, Generic)
583
583
584{-| 'unpackId' is a silly convenience function that gets used once.
584{-| 'unpackId' is a silly convenience function that gets used once.
585-}
585-}
586−unpackId :: DocId -> String
586+unpackId :: DocId -> Text
587unpackId (DocId docId) = docId
587unpackId (DocId docId) = docId
588
588
589type TrackSortScores = Bool
589type TrackSortScores = Bool
@@ -1252,29 +1252,29 @@ instance Show TimeInterval where
1252instance ToJSON Aggregation where
1252instance ToJSON Aggregation where
1253 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1253 toJSON (TermsAgg (TermsAggregation term include exclude order minDocCount size shardSize collectMode executionHint termAggs)) =
1254 omitNulls ["terms" .= omitNulls [ toJSON' term,
1254 omitNulls ["terms" .= omitNulls [ toJSON' term,
1255− "include" .= toJSON include,
1255+ "include" .= include,
1256− "exclude" .= toJSON exclude,
1256+ "exclude" .= exclude,
1257− "order" .= toJSON order,
1257+ "order" .= order,
1258− "min_doc_count" .= toJSON minDocCount,
1258+ "min_doc_count" .= minDocCount,
1259− "size" .= toJSON size,
1259+ "size" .= size,
1260− "shard_size" .= toJSON shardSize,
1260+ "shard_size" .= shardSize,
1261− "collect_mode" .= toJSON collectMode,
1261+ "collect_mode" .= collectMode,
1262− "execution_hint" .= toJSON executionHint
1262+ "execution_hint" .= executionHint
1263 ],
1263 ],
1264− "aggs" .= toJSON termAggs ]
1264+ "aggs" .= termAggs ]
1265 where
1265 where
1266− toJSON' x = case x of { Left y -> "field" .= toJSON y; Right y -> "script" .= toJSON y }
1266+ toJSON' x = case x of { Left y -> "field" .= y; Right y -> "script" .= y }
1267
1267
1268 toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
1268 toJSON (DateHistogramAgg (DateHistogramAggregation field interval format preZone postZone preOffset postOffset dateHistoAggs)) =
1269− omitNulls ["date_histogram" .= omitNulls [ "field" .= toJSON field,
1269+ omitNulls ["date_histogram" .= omitNulls [ "field" .= field,
1270− "interval" .= toJSON interval,
1270+ "interval" .= interval,
1271− "format" .= toJSON format,
1271+ "format" .= format,
1272− "pre_zone" .= toJSON preZone,
1272+ "pre_zone" .= preZone,
1273− "post_zone" .= toJSON postZone,
1273+ "post_zone" .= postZone,
1274− "pre_offset" .= toJSON preOffset,
1274+ "pre_offset" .= preOffset,
1275− "post_offset" .= toJSON postOffset
1275+ "post_offset" .= postOffset
1276 ],
1276 ],
1277− "aggs" .= toJSON dateHistoAggs ]
1277+ "aggs" .= dateHistoAggs ]
1278
1278
1279type AggregationResults = M.Map Text Value
1279type AggregationResults = M.Map Text Value
1280
1280
@@ -1352,7 +1352,7 @@ instance ToJSON Filter where
1352
1352
1353 toJSON (NotFilter notFilter cache) =
1353 toJSON (NotFilter notFilter cache) =
1354 object ["not" .=
1354 object ["not" .=
1355− object ["filter" .= toJSON notFilter
1355+ object ["filter" .= notFilter
1356 , "_cache" .= cache]]
1356 , "_cache" .= cache]]
1357
1357
1358 toJSON (IdentityFilter) =
1358 toJSON (IdentityFilter) =
@@ -1368,26 +1368,26 @@ instance ToJSON Filter where
1368 ["field" .= fieldName]]
1368 ["field" .= fieldName]]
1369
1369
1370 toJSON (BoolFilter boolMatch) =
1370 toJSON (BoolFilter boolMatch) =
1371− object ["bool" .= toJSON boolMatch]
1371+ object ["bool" .= boolMatch]
1372
1372
1373 toJSON (GeoBoundingBoxFilter bbConstraint) =
1373 toJSON (GeoBoundingBoxFilter bbConstraint) =
1374− object ["geo_bounding_box" .= toJSON bbConstraint]
1374+ object ["geo_bounding_box" .= bbConstraint]
1375
1375
1376 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1376 toJSON (GeoDistanceFilter (GeoPoint (FieldName distanceGeoField) geoDistLatLon)
1377 distance distanceType optimizeBbox cache) =
1377 distance distanceType optimizeBbox cache) =
1378 object ["geo_distance" .=
1378 object ["geo_distance" .=
1379− object ["distance" .= toJSON distance
1379+ object ["distance" .= distance
1380− , "distance_type" .= toJSON distanceType
1380+ , "distance_type" .= distanceType
1381 , "optimize_bbox" .= optimizeBbox
1381 , "optimize_bbox" .= optimizeBbox
1382− , distanceGeoField .= toJSON geoDistLatLon
1382+ , distanceGeoField .= geoDistLatLon
1383 , "_cache" .= cache]]
1383 , "_cache" .= cache]]
1384
1384
1385 toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1385 toJSON (GeoDistanceRangeFilter (GeoPoint (FieldName gddrField) drLatLon)
1386 (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1386 (DistanceRange geoDistRangeDistFrom drDistanceTo)) =
1387 object ["geo_distance_range" .=
1387 object ["geo_distance_range" .=
1388− object ["from" .= toJSON geoDistRangeDistFrom
1388+ object ["from" .= geoDistRangeDistFrom
1389− , "to" .= toJSON drDistanceTo
1389+ , "to" .= drDistanceTo
1390− , gddrField .= toJSON drLatLon]]
1390+ , gddrField .= drLatLon]]
1391
1391
1392 toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1392 toJSON (GeoPolygonFilter (FieldName geoPolygonFilterField) latLons) =
1393 object ["geo_polygon" .=
1393 object ["geo_polygon" .=
@@ -1397,7 +1397,7 @@ instance ToJSON Filter where
1397 toJSON (IdsFilter (MappingName mappingName) values) =
1397 toJSON (IdsFilter (MappingName mappingName) values) =
1398 object ["ids" .=
1398 object ["ids" .=
1399 object ["type" .= mappingName
1399 object ["type" .= mappingName
1400− , "values" .= fmap (T.pack . unpackId) values]]
1400+ , "values" .= fmap unpackId values]]
1401
1401
1402 toJSON (LimitFilter limit) =
1402 toJSON (LimitFilter limit) =
1403 object ["limit" .= object ["value" .= limit]]
1403 object ["limit" .= object ["value" .= limit]]
@@ -1416,7 +1416,7 @@ instance ToJSON Filter where
1416 toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1416 toJSON (RangeFilter (FieldName fieldName) rangeValue rangeExecution cache) =
1417 object ["range" .=
1417 object ["range" .=
1418 object [ fieldName .= object (rangeValueToPair rangeValue)
1418 object [ fieldName .= object (rangeValueToPair rangeValue)
1419− , "execution" .= toJSON rangeExecution
1419+ , "execution" .= rangeExecution
1420 , "_cache" .= cache]]
1420 , "_cache" .= cache]]
1421
1421
1422 toJSON (RegexpFilter (FieldName fieldName)
1422 toJSON (RegexpFilter (FieldName fieldName)
@@ -1424,14 +1424,14 @@ instance ToJSON Filter where
1424 object ["regexp" .=
1424 object ["regexp" .=
1425 object [fieldName .=
1425 object [fieldName .=
1426 object ["value" .= regexText
1426 object ["value" .= regexText
1427− , "flags" .= toJSON flags]
1427+ , "flags" .= flags]
1428 , "_name" .= cacheName
1428 , "_name" .= cacheName
1429 , "_cache" .= cache
1429 , "_cache" .= cache
1430 , "_cache_key" .= cacheKey]]
1430 , "_cache_key" .= cacheKey]]
1431
1431
1432instance ToJSON GeoPoint where
1432instance ToJSON GeoPoint where
1433 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1433 toJSON (GeoPoint (FieldName geoPointField) geoPointLatLon) =
1434− object [ geoPointField .= toJSON geoPointLatLon ]
1434+ object [ geoPointField .= geoPointLatLon ]
1435
1435
1436
1436
1437instance ToJSON Query where
1437instance ToJSON Query where
@@ -1451,82 +1451,82 @@ instance ToJSON Query where
1451 getTermValue (Term _ v) = v
1451 getTermValue (Term _ v) = v
1452 toJSON (IdsQuery idsQueryMappingName docIds) =
1452 toJSON (IdsQuery idsQueryMappingName docIds) =
1453 object [ "ids" .= object conjoined ]
1453 object [ "ids" .= object conjoined ]
1454− where conjoined = [ "type" .= toJSON idsQueryMappingName
1454+ where conjoined = [ "type" .= idsQueryMappingName
1455 , "values" .= fmap toJSON docIds ]
1455 , "values" .= fmap toJSON docIds ]
1456
1456
1457 toJSON (QueryQueryStringQuery qQueryStringQuery) =
1457 toJSON (QueryQueryStringQuery qQueryStringQuery) =
1458− object [ "query_string" .= toJSON qQueryStringQuery ]
1458+ object [ "query_string" .= qQueryStringQuery ]
1459
1459
1460 toJSON (QueryMatchQuery matchQuery) =
1460 toJSON (QueryMatchQuery matchQuery) =
1461− object [ "match" .= toJSON matchQuery ]
1461+ object [ "match" .= matchQuery ]
1462
1462
1463 toJSON (QueryMultiMatchQuery multiMatchQuery) =
1463 toJSON (QueryMultiMatchQuery multiMatchQuery) =
1464 toJSON multiMatchQuery
1464 toJSON multiMatchQuery
1465
1465
1466 toJSON (QueryBoolQuery boolQuery) =
1466 toJSON (QueryBoolQuery boolQuery) =
1467− object [ "bool" .= toJSON boolQuery ]
1467+ object [ "bool" .= boolQuery ]
1468
1468
1469 toJSON (QueryBoostingQuery boostingQuery) =
1469 toJSON (QueryBoostingQuery boostingQuery) =
1470− object [ "boosting" .= toJSON boostingQuery ]
1470+ object [ "boosting" .= boostingQuery ]
1471
1471
1472 toJSON (QueryCommonTermsQuery commonTermsQuery) =
1472 toJSON (QueryCommonTermsQuery commonTermsQuery) =
1473− object [ "common" .= toJSON commonTermsQuery ]
1473+ object [ "common" .= commonTermsQuery ]
1474
1474
1475 toJSON (ConstantScoreFilter csFilter boost) =
1475 toJSON (ConstantScoreFilter csFilter boost) =
1476− object [ "constant_score" .= toJSON csFilter
1476+ object [ "constant_score" .= csFilter
1477− , "boost" .= toJSON boost]
1477+ , "boost" .= boost]
1478
1478
1479 toJSON (ConstantScoreQuery query boost) =
1479 toJSON (ConstantScoreQuery query boost) =
1480− object [ "constant_score" .= toJSON query
1480+ object [ "constant_score" .= query
1481− , "boost" .= toJSON boost]
1481+ , "boost" .= boost]
1482
1482
1483 toJSON (QueryDisMaxQuery disMaxQuery) =
1483 toJSON (QueryDisMaxQuery disMaxQuery) =
1484− object [ "dis_max" .= toJSON disMaxQuery ]
1484+ object [ "dis_max" .= disMaxQuery ]
1485
1485
1486 toJSON (QueryFilteredQuery qFilteredQuery) =
1486 toJSON (QueryFilteredQuery qFilteredQuery) =
1487− object [ "filtered" .= toJSON qFilteredQuery ]
1487+ object [ "filtered" .= qFilteredQuery ]
1488
1488
1489 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1489 toJSON (QueryFuzzyLikeThisQuery fuzzyQuery) =
1490− object [ "fuzzy_like_this" .= toJSON fuzzyQuery ]
1490+ object [ "fuzzy_like_this" .= fuzzyQuery ]
1491
1491
1492 toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1492 toJSON (QueryFuzzyLikeFieldQuery fuzzyFieldQuery) =
1493− object [ "fuzzy_like_this_field" .= toJSON fuzzyFieldQuery ]
1493+ object [ "fuzzy_like_this_field" .= fuzzyFieldQuery ]
1494
1494
1495 toJSON (QueryFuzzyQuery fuzzyQuery) =
1495 toJSON (QueryFuzzyQuery fuzzyQuery) =
1496− object [ "fuzzy" .= toJSON fuzzyQuery ]
1496+ object [ "fuzzy" .= fuzzyQuery ]
1497
1497
1498 toJSON (QueryHasChildQuery childQuery) =
1498 toJSON (QueryHasChildQuery childQuery) =
1499− object [ "has_child" .= toJSON childQuery ]
1499+ object [ "has_child" .= childQuery ]
1500
1500
1501 toJSON (QueryHasParentQuery parentQuery) =
1501 toJSON (QueryHasParentQuery parentQuery) =
1502− object [ "has_parent" .= toJSON parentQuery ]
1502+ object [ "has_parent" .= parentQuery ]
1503
1503
1504 toJSON (QueryIndicesQuery qIndicesQuery) =
1504 toJSON (QueryIndicesQuery qIndicesQuery) =
1505− object [ "indices" .= toJSON qIndicesQuery ]
1505+ object [ "indices" .= qIndicesQuery ]
1506
1506
1507 toJSON (MatchAllQuery boost) =
1507 toJSON (MatchAllQuery boost) =
1508 object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1508 object [ "match_all" .= omitNulls [ "boost" .= boost ] ]
1509
1509
1510 toJSON (QueryMoreLikeThisQuery query) =
1510 toJSON (QueryMoreLikeThisQuery query) =
1511− object [ "more_like_this" .= toJSON query ]
1511+ object [ "more_like_this" .= query ]
1512
1512
1513 toJSON (QueryMoreLikeThisFieldQuery query) =
1513 toJSON (QueryMoreLikeThisFieldQuery query) =
1514− object [ "more_like_this_field" .= toJSON query ]
1514+ object [ "more_like_this_field" .= query ]
1515
1515
1516 toJSON (QueryNestedQuery query) =
1516 toJSON (QueryNestedQuery query) =
1517− object [ "nested" .= toJSON query ]
1517+ object [ "nested" .= query ]
1518
1518
1519 toJSON (QueryPrefixQuery query) =
1519 toJSON (QueryPrefixQuery query) =
1520− object [ "prefix" .= toJSON query ]
1520+ object [ "prefix" .= query ]
1521
1521
1522 toJSON (QueryRangeQuery query) =
1522 toJSON (QueryRangeQuery query) =
1523− object [ "range" .= toJSON query ]
1523+ object [ "range" .= query ]
1524
1524
1525 toJSON (QueryRegexpQuery query) =
1525 toJSON (QueryRegexpQuery query) =
1526− object [ "regexp" .= toJSON query ]
1526+ object [ "regexp" .= query ]
1527
1527
1528 toJSON (QuerySimpleQueryStringQuery query) =
1528 toJSON (QuerySimpleQueryStringQuery query) =
1529− object [ "simple_query_string" .= toJSON query ]
1529+ object [ "simple_query_string" .= query ]
1530
1530
1531
1531
1532omitNulls :: [(Text, Value)] -> Value
1532omitNulls :: [(Text, Value)] -> Value
@@ -1539,7 +1539,7 @@ omitNulls = object . filter notNull where
1539instance ToJSON SimpleQueryStringQuery where
1539instance ToJSON SimpleQueryStringQuery where
1540 toJSON SimpleQueryStringQuery {..} =
1540 toJSON SimpleQueryStringQuery {..} =
1541 omitNulls (base ++ maybeAdd)
1541 omitNulls (base ++ maybeAdd)
1542− where base = [ "query" .= toJSON simpleQueryStringQuery ]
1542+ where base = [ "query" .= simpleQueryStringQuery ]
1543 maybeAdd = [ "fields" .= simpleQueryStringField
1543 maybeAdd = [ "fields" .= simpleQueryStringField
1544 , "default_operator" .= simpleQueryStringOperator
1544 , "default_operator" .= simpleQueryStringOperator
1545 , "analyzer" .= simpleQueryStringAnalyzer
1545 , "analyzer" .= simpleQueryStringAnalyzer
@@ -1575,7 +1575,7 @@ instance ToJSON RegexpQuery where
1575 rqQueryBoost) =
1575 rqQueryBoost) =
1576 object [ rqQueryField .= omitNulls base ]
1576 object [ rqQueryField .= omitNulls base ]
1577 where base = [ "value" .= regexpQueryQuery
1577 where base = [ "value" .= regexpQueryQuery
1578− , "flags" .= toJSON rqQueryFlags
1578+ , "flags" .= rqQueryFlags
1579 , "boost" .= rqQueryBoost ]
1579 , "boost" .= rqQueryBoost ]
1580
1580
1581
1581
@@ -1591,7 +1591,7 @@ instance ToJSON QueryStringQuery where
1591 qsLenient qsLocale) =
1591 qsLenient qsLocale) =
1592 omitNulls base
1592 omitNulls base
1593 where
1593 where
1594− base = [ "query" .= toJSON qsQueryString
1594+ base = [ "query" .= qsQueryString
1595 , "default_field" .= qsDefaultField
1595 , "default_field" .= qsDefaultField
1596 , "default_operator" .= qsOperator
1596 , "default_operator" .= qsOperator
1597 , "analyzer" .= qsAnalyzer
1597 , "analyzer" .= qsAnalyzer
@@ -1613,21 +1613,21 @@ instance ToJSON QueryStringQuery where
1613instance ToJSON RangeQuery where
1613instance ToJSON RangeQuery where
1614 toJSON (RangeQuery (FieldName fieldName) range boost) =
1614 toJSON (RangeQuery (FieldName fieldName) range boost) =
1615 object [ fieldName .= conjoined ]
1615 object [ fieldName .= conjoined ]
1616− where conjoined = [ "boost" .= toJSON boost ] ++ (rangeValueToPair range)
1616+ where conjoined = [ "boost" .= boost ] ++ (rangeValueToPair range)
1617
1617
1618
1618
1619instance ToJSON PrefixQuery where
1619instance ToJSON PrefixQuery where
1620 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1620 toJSON (PrefixQuery (FieldName fieldName) queryValue boost) =
1621 object [ fieldName .= omitNulls base ]
1621 object [ fieldName .= omitNulls base ]
1622− where base = [ "value" .= toJSON queryValue
1622+ where base = [ "value" .= queryValue
1623 , "boost" .= boost ]
1623 , "boost" .= boost ]
1624
1624
1625
1625
1626instance ToJSON NestedQuery where
1626instance ToJSON NestedQuery where
1627 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1627 toJSON (NestedQuery nqPath nqScoreType nqQuery) =
1628− object [ "path" .= toJSON nqPath
1628+ object [ "path" .= nqPath
1629− , "score_mode" .= toJSON nqScoreType
1629+ , "score_mode" .= nqScoreType
1630− , "query" .= toJSON nqQuery ]
1630+ , "query" .= nqQuery ]
1631
1631
1632
1632
1633instance ToJSON MoreLikeThisFieldQuery where
1633instance ToJSON MoreLikeThisFieldQuery where
@@ -1635,7 +1635,7 @@ instance ToJSON MoreLikeThisFieldQuery where
1635 percent mtf mqt stopwords mindf maxdf
1635 percent mtf mqt stopwords mindf maxdf
1636 minwl maxwl boostTerms boost analyzer) =
1636 minwl maxwl boostTerms boost analyzer) =
1637 object [ fieldName .= omitNulls base ]
1637 object [ fieldName .= omitNulls base ]
1638− where base = [ "like_text" .= toJSON text
1638+ where base = [ "like_text" .= text
1639 , "percent_terms_to_match" .= percent
1639 , "percent_terms_to_match" .= percent
1640 , "min_term_freq" .= mtf
1640 , "min_term_freq" .= mtf
1641 , "max_query_terms" .= mqt
1641 , "max_query_terms" .= mqt
@@ -1654,7 +1654,7 @@ instance ToJSON MoreLikeThisQuery where
1654 mtf mqt stopwords mindf maxdf
1654 mtf mqt stopwords mindf maxdf
1655 minwl maxwl boostTerms boost analyzer) =
1655 minwl maxwl boostTerms boost analyzer) =
1656 omitNulls base
1656 omitNulls base
1657− where base = [ "like_text" .= toJSON text
1657+ where base = [ "like_text" .= text
1658 , "fields" .= fields
1658 , "fields" .= fields
1659 , "percent_terms_to_match" .= percent
1659 , "percent_terms_to_match" .= percent
1660 , "min_term_freq" .= mtf
1660 , "min_term_freq" .= mtf
@@ -1671,34 +1671,34 @@ instance ToJSON MoreLikeThisQuery where
1671
1671
1672instance ToJSON IndicesQuery where
1672instance ToJSON IndicesQuery where
1673 toJSON (IndicesQuery indices query noMatch) =
1673 toJSON (IndicesQuery indices query noMatch) =
1674− omitNulls [ "indices" .= toJSON indices
1674+ omitNulls [ "indices" .= indices
1675− , "no_match_query" .= toJSON noMatch
1675+ , "no_match_query" .= noMatch
1676− , "query" .= toJSON query ]
1676+ , "query" .= query ]
1677
1677
1678
1678
1679instance ToJSON HasParentQuery where
1679instance ToJSON HasParentQuery where
1680 toJSON (HasParentQuery queryType query scoreType) =
1680 toJSON (HasParentQuery queryType query scoreType) =
1681− omitNulls [ "parent_type" .= toJSON queryType
1681+ omitNulls [ "parent_type" .= queryType
1682− , "score_type" .= toJSON scoreType
1682+ , "score_type" .= scoreType
1683− , "query" .= toJSON query ]
1683+ , "query" .= query ]
1684
1684
1685
1685
1686instance ToJSON HasChildQuery where
1686instance ToJSON HasChildQuery where
1687 toJSON (HasChildQuery queryType query scoreType) =
1687 toJSON (HasChildQuery queryType query scoreType) =
1688− omitNulls [ "query" .= toJSON query
1688+ omitNulls [ "query" .= query
1689− , "score_type" .= toJSON scoreType
1689+ , "score_type" .= scoreType
1690− , "type" .= toJSON queryType ]
1690+ , "type" .= queryType ]
1691
1691
1692
1692
1693instance ToJSON FuzzyQuery where
1693instance ToJSON FuzzyQuery where
1694 toJSON (FuzzyQuery (FieldName fieldName) queryText
1694 toJSON (FuzzyQuery (FieldName fieldName) queryText
1695 prefixLength maxEx fuzziness boost) =
1695 prefixLength maxEx fuzziness boost) =
1696 object [ fieldName .= omitNulls base ]
1696 object [ fieldName .= omitNulls base ]
1697− where base = [ "value" .= toJSON queryText
1697+ where base = [ "value" .= queryText
1698− , "fuzziness" .= toJSON fuzziness
1698+ , "fuzziness" .= fuzziness
1699− , "prefix_length" .= toJSON prefixLength
1699+ , "prefix_length" .= prefixLength
1700− , "boost" .= toJSON boost
1700+ , "boost" .= boost
1701− , "max_expansions" .= toJSON maxEx ]
1701+ , "max_expansions" .= maxEx ]
1702
1702
1703
1703
1704instance ToJSON FuzzyLikeFieldQuery where
1704instance ToJSON FuzzyLikeFieldQuery where
@@ -1706,41 +1706,41 @@ instance ToJSON FuzzyLikeFieldQuery where
1706 fieldText maxTerms ignoreFreq fuzziness prefixLength
1706 fieldText maxTerms ignoreFreq fuzziness prefixLength
1707 boost analyzer) =
1707 boost analyzer) =
1708 object [ fieldName .=
1708 object [ fieldName .=
1709− omitNulls [ "like_text" .= toJSON fieldText
1709+ omitNulls [ "like_text" .= fieldText
1710− , "max_query_terms" .= toJSON maxTerms
1710+ , "max_query_terms" .= maxTerms
1711− , "ignore_tf" .= toJSON ignoreFreq
1711+ , "ignore_tf" .= ignoreFreq
1712− , "fuzziness" .= toJSON fuzziness
1712+ , "fuzziness" .= fuzziness
1713− , "prefix_length" .= toJSON prefixLength
1713+ , "prefix_length" .= prefixLength
1714− , "analyzer" .= toJSON analyzer
1714+ , "analyzer" .= analyzer
1715− , "boost" .= toJSON boost ]]
1715+ , "boost" .= boost ]]
1716
1716
1717
1717
1718instance ToJSON FuzzyLikeThisQuery where
1718instance ToJSON FuzzyLikeThisQuery where
1719 toJSON (FuzzyLikeThisQuery fields text maxTerms
1719 toJSON (FuzzyLikeThisQuery fields text maxTerms
1720 ignoreFreq fuzziness prefixLength boost analyzer) =
1720 ignoreFreq fuzziness prefixLength boost analyzer) =
1721 omitNulls base
1721 omitNulls base
1722− where base = [ "fields" .= toJSON fields
1722+ where base = [ "fields" .= fields
1723− , "like_text" .= toJSON text
1723+ , "like_text" .= text
1724− , "max_query_terms" .= toJSON maxTerms
1724+ , "max_query_terms" .= maxTerms
1725− , "ignore_tf" .= toJSON ignoreFreq
1725+ , "ignore_tf" .= ignoreFreq
1726− , "fuzziness" .= toJSON fuzziness
1726+ , "fuzziness" .= fuzziness
1727− , "prefix_length" .= toJSON prefixLength
1727+ , "prefix_length" .= prefixLength
1728− , "analyzer" .= toJSON analyzer
1728+ , "analyzer" .= analyzer
1729− , "boost" .= toJSON boost ]
1729+ , "boost" .= boost ]
1730
1730
1731
1731
1732instance ToJSON FilteredQuery where
1732instance ToJSON FilteredQuery where
1733 toJSON (FilteredQuery query fFilter) =
1733 toJSON (FilteredQuery query fFilter) =
1734− object [ "query" .= toJSON query
1734+ object [ "query" .= query
1735− , "filter" .= toJSON fFilter ]
1735+ , "filter" .= fFilter ]
1736
1736
1737
1737
1738instance ToJSON DisMaxQuery where
1738instance ToJSON DisMaxQuery where
1739 toJSON (DisMaxQuery queries tiebreaker boost) =
1739 toJSON (DisMaxQuery queries tiebreaker boost) =
1740 omitNulls base
1740 omitNulls base
1741− where base = [ "queries" .= toJSON queries
1741+ where base = [ "queries" .= queries
1742− , "boost" .= toJSON boost
1742+ , "boost" .= boost
1743− , "tie_breaker" .= toJSON tiebreaker ]
1743+ , "tie_breaker" .= tiebreaker ]
1744
1744
1745
1745
1746instance ToJSON CommonTermsQuery where
1746instance ToJSON CommonTermsQuery where
@@ -1748,38 +1748,38 @@ instance ToJSON CommonTermsQuery where
1748 (QueryString query) cf lfo hfo msm
1748 (QueryString query) cf lfo hfo msm
1749 boost analyzer disableCoord) =
1749 boost analyzer disableCoord) =
1750 object [fieldName .= omitNulls base ]
1750 object [fieldName .= omitNulls base ]
1751− where base = [ "query" .= toJSON query
1751+ where base = [ "query" .= query
1752− , "cutoff_frequency" .= toJSON cf
1752+ , "cutoff_frequency" .= cf
1753− , "low_freq_operator" .= toJSON lfo
1753+ , "low_freq_operator" .= lfo
1754− , "minimum_should_match" .= toJSON msm
1754+ , "minimum_should_match" .= msm
1755− , "boost" .= toJSON boost
1755+ , "boost" .= boost
1756− , "analyzer" .= toJSON analyzer
1756+ , "analyzer" .= analyzer
1757− , "disable_coord" .= toJSON disableCoord
1757+ , "disable_coord" .= disableCoord
1758− , "high_freq_operator" .= toJSON hfo ]
1758+ , "high_freq_operator" .= hfo ]
1759
1759
1760
1760
1761instance ToJSON CommonMinimumMatch where
1761instance ToJSON CommonMinimumMatch where
1762 toJSON (CommonMinimumMatch mm) = toJSON mm
1762 toJSON (CommonMinimumMatch mm) = toJSON mm
1763 toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1763 toJSON (CommonMinimumMatchHighLow (MinimumMatchHighLow lowF highF)) =
1764− object [ "low_freq" .= toJSON lowF
1764+ object [ "low_freq" .= lowF
1765− , "high_freq" .= toJSON highF ]
1765+ , "high_freq" .= highF ]
1766
1766
1767instance ToJSON BoostingQuery where
1767instance ToJSON BoostingQuery where
1768 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1768 toJSON (BoostingQuery bqPositiveQuery bqNegativeQuery bqNegativeBoost) =
1769− object [ "positive" .= toJSON bqPositiveQuery
1769+ object [ "positive" .= bqPositiveQuery
1770− , "negative" .= toJSON bqNegativeQuery
1770+ , "negative" .= bqNegativeQuery
1771− , "negative_boost" .= toJSON bqNegativeBoost ]
1771+ , "negative_boost" .= bqNegativeBoost ]
1772
1772
1773
1773
1774instance ToJSON BoolQuery where
1774instance ToJSON BoolQuery where
1775 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1775 toJSON (BoolQuery mustM notM shouldM bqMin boost disableCoord) =
1776 omitNulls base
1776 omitNulls base
1777− where base = [ "must" .= toJSON mustM
1777+ where base = [ "must" .= mustM
1778− , "must_not" .= toJSON notM
1778+ , "must_not" .= notM
1779− , "should" .= toJSON shouldM
1779+ , "should" .= shouldM
1780− , "minimum_should_match" .= toJSON bqMin
1780+ , "minimum_should_match" .= bqMin
1781− , "boost" .= toJSON boost
1781+ , "boost" .= boost
1782− , "disable_coord" .= toJSON disableCoord ]
1782+ , "disable_coord" .= disableCoord ]
1783
1783
1784
1784
1785instance ToJSON MatchQuery where
1785instance ToJSON MatchQuery where
@@ -1789,13 +1789,13 @@ instance ToJSON MatchQuery where
1789 analyzer maxExpansions lenient) =
1789 analyzer maxExpansions lenient) =
1790 object [ fieldName .= omitNulls base ]
1790 object [ fieldName .= omitNulls base ]
1791 where base = [ "query" .= mqQueryString
1791 where base = [ "query" .= mqQueryString
1792− , "operator" .= toJSON booleanOperator
1792+ , "operator" .= booleanOperator
1793− , "zero_terms_query" .= toJSON zeroTermsQuery
1793+ , "zero_terms_query" .= zeroTermsQuery
1794− , "cutoff_frequency" .= toJSON cutoffFrequency
1794+ , "cutoff_frequency" .= cutoffFrequency
1795− , "type" .= toJSON matchQueryType
1795+ , "type" .= matchQueryType
1796− , "analyzer" .= toJSON analyzer
1796+ , "analyzer" .= analyzer
1797− , "max_expansions" .= toJSON maxExpansions
1797+ , "max_expansions" .= maxExpansions
1798− , "lenient" .= toJSON lenient ]
1798+ , "lenient" .= lenient ]
1799
1799
1800
1800
1801instance ToJSON MultiMatchQuery where
1801instance ToJSON MultiMatchQuery where
@@ -1804,14 +1804,14 @@ instance ToJSON MultiMatchQuery where
1804 object ["multi_match" .= omitNulls base]
1804 object ["multi_match" .= omitNulls base]
1805 where base = [ "fields" .= fmap toJSON fields
1805 where base = [ "fields" .= fmap toJSON fields
1806 , "query" .= query
1806 , "query" .= query
1807− , "operator" .= toJSON boolOp
1807+ , "operator" .= boolOp
1808− , "zero_terms_query" .= toJSON ztQ
1808+ , "zero_terms_query" .= ztQ
1809− , "tiebreaker" .= toJSON tb
1809+ , "tiebreaker" .= tb
1810− , "type" .= toJSON mmqt
1810+ , "type" .= mmqt
1811− , "cutoff_frequency" .= toJSON cf
1811+ , "cutoff_frequency" .= cf
1812− , "analyzer" .= toJSON analyzer
1812+ , "analyzer" .= analyzer
1813− , "max_expansions" .= toJSON maxEx
1813+ , "max_expansions" .= maxEx
1814− , "lenient" .= toJSON lenient ]
1814+ , "lenient" .= lenient ]
1815
1815
1816
1816
1817instance ToJSON MultiMatchQueryType where
1817instance ToJSON MultiMatchQueryType where
@@ -1923,7 +1923,7 @@ instance ToJSON FieldHighlight where
1923
1923
1924instance ToJSON Highlights where
1924instance ToJSON Highlights where
1925 toJSON (Highlights global fields) =
1925 toJSON (Highlights global fields) =
1926− omitNulls (("fields" .= toJSON fields)
1926+ omitNulls (("fields" .= fields)
1927 : highlightSettingsPairs global)
1927 : highlightSettingsPairs global)
1928
1928
1929instance ToJSON HighlightSettings where
1929instance ToJSON HighlightSettings where
@@ -2001,16 +2001,16 @@ instance ToJSON SortSpec where
2001 (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
2001 (DefaultSort (FieldName dsSortFieldName) dsSortOrder dsIgnoreUnmapped
2002 dsSortMode dsMissingSort dsNestedFilter)) =
2002 dsSortMode dsMissingSort dsNestedFilter)) =
2003 object [dsSortFieldName .= omitNulls base] where
2003 object [dsSortFieldName .= omitNulls base] where
2004− base = [ "order" .= toJSON dsSortOrder
2004+ base = [ "order" .= dsSortOrder
2005 , "ignore_unmapped" .= dsIgnoreUnmapped
2005 , "ignore_unmapped" .= dsIgnoreUnmapped
2006 , "mode" .= dsSortMode
2006 , "mode" .= dsSortMode
2007 , "missing" .= dsMissingSort
2007 , "missing" .= dsMissingSort
2008 , "nested_filter" .= dsNestedFilter ]
2008 , "nested_filter" .= dsNestedFilter ]
2009
2009
2010 toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
2010 toJSON (GeoDistanceSortSpec gdsSortOrder (GeoPoint (FieldName field) gdsLatLon) units) =
2011− object [ "unit" .= toJSON units
2011+ object [ "unit" .= units
2012− , field .= toJSON gdsLatLon
2012+ , field .= gdsLatLon
2013− , "order" .= toJSON gdsSortOrder ]
2013+ , "order" .= gdsSortOrder ]
2014
2014
2015
2015
2016instance ToJSON SortOrder where
2016instance ToJSON SortOrder where
@@ -2072,7 +2072,7 @@ instance ToJSON OptimizeBbox where
2072instance ToJSON GeoBoundingBoxConstraint where
2072instance ToJSON GeoBoundingBoxConstraint where
2073 toJSON (GeoBoundingBoxConstraint
2073 toJSON (GeoBoundingBoxConstraint
2074 (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2074 (FieldName gbbcGeoBBField) gbbcConstraintBox cache type') =
2075− object [gbbcGeoBBField .= toJSON gbbcConstraintBox
2075+ object [gbbcGeoBBField .= gbbcConstraintBox
2076 , "_cache" .= cache
2076 , "_cache" .= cache
2077 , "type" .= type']
2077 , "type" .= type']
2078
2078
@@ -2084,8 +2084,8 @@ instance ToJSON GeoFilterType where
2084
2084
2085instance ToJSON GeoBoundingBox where
2085instance ToJSON GeoBoundingBox where
2086 toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2086 toJSON (GeoBoundingBox gbbTopLeft gbbBottomRight) =
2087− object ["top_left" .= toJSON gbbTopLeft
2087+ object ["top_left" .= gbbTopLeft
2088− , "bottom_right" .= toJSON gbbBottomRight]
2088+ , "bottom_right" .= gbbBottomRight]
2089
2089
2090
2090
2091instance ToJSON LatLon where
2091instance ToJSON LatLon where
@@ -2118,9 +2118,9 @@ instance ToJSON Term where
2118
2118
2119
2119
2120instance ToJSON BoolMatch where
2120instance ToJSON BoolMatch where
2121− toJSON (MustMatch term cache) = object ["must" .= toJSON term,
2121+ toJSON (MustMatch term cache) = object ["must" .= term,
2122 "_cache" .= cache]
2122 "_cache" .= cache]
2123− toJSON (MustNotMatch term cache) = object ["must_not" .= toJSON term,
2123+ toJSON (MustNotMatch term cache) = object ["must_not" .= term,
2124 "_cache" .= cache]
2124 "_cache" .= cache]
2125 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2125 toJSON (ShouldMatch terms cache) = object ["should" .= fmap toJSON terms,
2126 "_cache" .= cache]
2126 "_cache" .= cache]