@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DeriveGeneric #-}
22{-# LANGUAGE RecordWildCards #-}
33
44{-| Data types for describing actions and data structures performed to interact
@@ -28,6 +28,7 @@ module Database.Bloodhound.Types
2828 , mkDateHistogram
2929 , toTerms
3030 , toDateHistogram
31+ , omitNulls
3132 , Version(..)
3233 , Status(..)
3334 , Existence(..)
@@ -165,22 +166,23 @@ module Database.Bloodhound.Types
165166 , DateHistogramResult
166167 ) where
167168
168−import Control.Applicative
169−import Data.Aeson
170−import Data.Aeson.Types (parseMaybe)
171−import qualified Data.ByteString.Lazy.Char8 as L
172−import Data.List (nub)
173−import Data.List.NonEmpty (NonEmpty(..))
174−import Data.Monoid
175−import Data.Text (Text)
176−import qualified Data.Map.Strict as M
177−import qualified Data.Text as T
178−import Data.Time.Clock (UTCTime)
179−import GHC.Generics (Generic)
180−import Network.HTTP.Client
181−import qualified Network.HTTP.Types.Method as NHTM
182−
183−import Database.Bloodhound.Types.Class
169+import Control.Applicative
170+import Data.Aeson
171+import Data.Aeson.Types (parseMaybe)
172+import qualified Data.ByteString.Lazy.Char8 as L
173+import Data.List (nub)
174+import Data.List.NonEmpty (NonEmpty (..))
175+import Data.Monoid
176+import Data.Text (Text)
177+import qualified Data.Text as T
178+import qualified Data.Map.Strict as M
179+import Data.Time.Clock (UTCTime)
180+import qualified Data.Vector as V
181+import GHC.Generics (Generic)
182+import Network.HTTP.Client
183+import qualified Network.HTTP.Types.Method as NHTM
184+
185+import Database.Bloodhound.Types.Class
184186
185187
186188{-| 'Version' is embedded in 'Status' -}
@@ -238,8 +240,8 @@ data FieldDefinition =
238240 FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
239241
240242data MappingField =
241− MappingField { mappingFieldName :: FieldName
242− , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
243+ MappingField { mappingFieldName :: FieldName
244+ , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
243245
244246{-| Support for type reification of 'Mapping's is currently incomplete, for
245247 now the mapping API verbiage expects a 'ToJSON'able blob.
@@ -497,11 +499,11 @@ type Size = Int
497499data Search = Search { queryBody :: Maybe Query
498500 , filterBody :: Maybe Filter
499501 , sortBody :: Maybe Sort
500− , aggBody :: Maybe Aggregations
502+ , aggBody :: Maybe Aggregations
501503 -- default False
502504 , trackSortScores :: TrackSortScores
503− , from :: From
504− , size :: Size } deriving (Eq, Show)
505+ , from :: From
506+ , size :: Size } deriving (Eq, Show)
505507
506508data Query =
507509 TermQuery Term (Maybe Boost)
@@ -534,10 +536,10 @@ data Query =
534536 deriving (Eq, Show)
535537
536538data RegexpQuery =
537− RegexpQuery { regexpQueryField :: FieldName
538− , regexpQuery :: Regexp
539− , regexpQueryFlags :: RegexpFlags
540− , regexpQueryBoost :: Maybe Boost
539+ RegexpQuery { regexpQueryField :: FieldName
540+ , regexpQuery :: Regexp
541+ , regexpQueryFlags :: RegexpFlags
542+ , regexpQueryBoost :: Maybe Boost
541543 } deriving (Eq, Show)
542544
543545data RangeQuery =
@@ -657,9 +659,9 @@ data MoreLikeThisQuery =
657659data IndicesQuery =
658660 IndicesQuery
659661 { indicesQueryIndices :: [IndexName]
660− , indicesQuery :: Query
662+ , indicesQuery :: Query
661663 -- default "all"
662− , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
664+ , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
663665
664666data HasParentQuery =
665667 HasParentQuery
@@ -776,15 +778,15 @@ data MultiMatchQueryType =
776778 | MultiMatchPhrasePrefix deriving (Eq, Show)
777779
778780data BoolQuery =
779− BoolQuery { boolQueryMustMatch :: Maybe Query
780− , boolQueryMustNotMatch :: Maybe Query
781− , boolQueryShouldMatch :: Maybe [Query]
781+ BoolQuery { boolQueryMustMatch :: [Query]
782+ , boolQueryMustNotMatch :: [Query]
783+ , boolQueryShouldMatch :: [Query]
782784 , boolQueryMinimumShouldMatch :: Maybe MinimumMatch
783785 , boolQueryBoost :: Maybe Boost
784786 , boolQueryDisableCoord :: Maybe DisableCoord
785787 } deriving (Eq, Show)
786788
787−mkBoolQuery :: Maybe Query -> Maybe Query -> Maybe [Query] -> BoolQuery
789+mkBoolQuery :: [Query] -> [Query] -> [Query] -> BoolQuery
788790mkBoolQuery must mustNot should =
789791 BoolQuery must mustNot should Nothing Nothing Nothing
790792
@@ -811,7 +813,7 @@ data CommonMinimumMatch =
811813 deriving (Eq, Show)
812814
813815data MinimumMatchHighLow =
814− MinimumMatchHighLow { lowFreq :: MinimumMatch
816+ MinimumMatchHighLow { lowFreq :: MinimumMatch
815817 , highFreq :: MinimumMatch } deriving (Eq, Show)
816818
817819data Filter = AndFilter [Filter] Cache
@@ -951,11 +953,11 @@ data FromJSON a => SearchHits a =
951953 , hits :: [Hit a] } deriving (Eq, Show)
952954
953955data FromJSON a => Hit a =
954− Hit { hitIndex :: IndexName
955− , hitType :: MappingName
956− , hitDocId :: DocId
957− , hitScore :: Score
958− , hitSource :: a } deriving (Eq, Show)
956+ Hit { hitIndex :: IndexName
957+ , hitType :: MappingName
958+ , hitDocId :: DocId
959+ , hitScore :: Score
960+ , hitSource :: a } deriving (Eq, Show)
959961
960962data ShardResult =
961963 ShardResult { shardTotal :: Int
@@ -1370,8 +1372,9 @@ instance ToJSON Query where
13701372
13711373omitNulls :: [(Text, Value)] -> Value
13721374omitNulls = object . filter notNull where
1373− notNull (_, Null) = False
1374− notNull _ = True
1375+ notNull (_, Null) = False
1376+ notNull (_, (Array a)) = (not . V.null) a
1377+ notNull _ = True
13751378
13761379
13771380instance ToJSON SimpleQueryStringQuery where