@@ -1,4 +1,4 @@
1−{-# LANGUAGE DeriveGeneric #-}
1+{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE RecordWildCards #-}
2{-# LANGUAGE RecordWildCards #-}
4{-| Data types for describing actions and data structures performed to interact
4{-| Data types for describing actions and data structures performed to interact
@@ -28,6 +28,7 @@ module Database.Bloodhound.Types
28 , mkDateHistogram
28 , mkDateHistogram
30 , toDateHistogram
30 , toDateHistogram
31 , Version(..)
32 , Version(..)
32 , Status(..)
33 , Status(..)
33 , Existence(..)
34 , Existence(..)
@@ -165,22 +166,23 @@ module Database.Bloodhound.Types
165 , DateHistogramResult
166 , DateHistogramResult
168−import Control.Applicative
169+import Control.Applicative
169−import Data.Aeson
170+import Data.Aeson
170−import Data.Aeson.Types (parseMaybe)
171+import Data.Aeson.Types (parseMaybe)
171−import qualified Data.ByteString.Lazy.Char8 as L
172+import qualified Data.ByteString.Lazy.Char8 as L
172−import Data.List (nub)
173+import Data.List (nub)
173−import Data.List.NonEmpty (NonEmpty(..))
174+import Data.List.NonEmpty (NonEmpty (..))
174−import Data.Monoid
175+import Data.Monoid
175−import Data.Text (Text)
176+import Data.Text (Text)
176−import qualified Data.Map.Strict as M
177+import qualified Data.Text as T
177−import qualified Data.Text as T
178+import qualified Data.Map.Strict as M
178−import Data.Time.Clock (UTCTime)
179+import Data.Time.Clock (UTCTime)
180+import qualified Data.Vector as V
179−import GHC.Generics (Generic)
181+import GHC.Generics (Generic)
180−import Network.HTTP.Client
182+import Network.HTTP.Client
181−import qualified Network.HTTP.Types.Method as NHTM
183+import qualified Network.HTTP.Types.Method as NHTM
183−import Database.Bloodhound.Types.Class
185+import Database.Bloodhound.Types.Class
186{-| 'Version' is embedded in 'Status' -}
188{-| 'Version' is embedded in 'Status' -}
@@ -238,8 +240,8 @@ data FieldDefinition =
238 FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
240 FieldDefinition { fieldType :: FieldType } deriving (Eq, Show)
240data MappingField =
242data MappingField =
241− MappingField { mappingFieldName :: FieldName
243+ MappingField { mappingFieldName :: FieldName
242− , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
244+ , fieldDefinition :: FieldDefinition } deriving (Eq, Show)
244{-| Support for type reification of 'Mapping's is currently incomplete, for
246{-| Support for type reification of 'Mapping's is currently incomplete, for
245 now the mapping API verbiage expects a 'ToJSON'able blob.
247 now the mapping API verbiage expects a 'ToJSON'able blob.
@@ -497,11 +499,11 @@ type Size = Int
497data Search = Search { queryBody :: Maybe Query
499data Search = Search { queryBody :: Maybe Query
498 , filterBody :: Maybe Filter
500 , filterBody :: Maybe Filter
499 , sortBody :: Maybe Sort
501 , sortBody :: Maybe Sort
500− , aggBody :: Maybe Aggregations
502+ , aggBody :: Maybe Aggregations
501 -- default False
503 -- default False
502 , trackSortScores :: TrackSortScores
504 , trackSortScores :: TrackSortScores
503− , from :: From
505+ , from :: From
504− , size :: Size } deriving (Eq, Show)
506+ , size :: Size } deriving (Eq, Show)
506data Query =
508data Query =
507 TermQuery Term (Maybe Boost)
509 TermQuery Term (Maybe Boost)
@@ -534,10 +536,10 @@ data Query =
534 deriving (Eq, Show)
536 deriving (Eq, Show)
536data RegexpQuery =
538data RegexpQuery =
537− RegexpQuery { regexpQueryField :: FieldName
539+ RegexpQuery { regexpQueryField :: FieldName
538− , regexpQuery :: Regexp
540+ , regexpQuery :: Regexp
539− , regexpQueryFlags :: RegexpFlags
541+ , regexpQueryFlags :: RegexpFlags
540− , regexpQueryBoost :: Maybe Boost
542+ , regexpQueryBoost :: Maybe Boost
541 } deriving (Eq, Show)
543 } deriving (Eq, Show)
543data RangeQuery =
545data RangeQuery =
@@ -657,9 +659,9 @@ data MoreLikeThisQuery =
657data IndicesQuery =
659data IndicesQuery =
658 IndicesQuery
660 IndicesQuery
659 { indicesQueryIndices :: [IndexName]
661 { indicesQueryIndices :: [IndexName]
660− , indicesQuery :: Query
662+ , indicesQuery :: Query
661 -- default "all"
663 -- default "all"
662− , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
664+ , indicesQueryNoMatch :: Maybe Query } deriving (Eq, Show)
664data HasParentQuery =
666data HasParentQuery =
665 HasParentQuery
667 HasParentQuery
@@ -776,15 +778,15 @@ data MultiMatchQueryType =
776 | MultiMatchPhrasePrefix deriving (Eq, Show)
778 | MultiMatchPhrasePrefix deriving (Eq, Show)
778data BoolQuery =
780data BoolQuery =
779− BoolQuery { boolQueryMustMatch :: Maybe Query
781+ BoolQuery { boolQueryMustMatch :: [Query]
780− , boolQueryMustNotMatch :: Maybe Query
782+ , boolQueryMustNotMatch :: [Query]
781− , boolQueryShouldMatch :: Maybe [Query]
783+ , boolQueryShouldMatch :: [Query]
782 , boolQueryMinimumShouldMatch :: Maybe MinimumMatch
784 , boolQueryMinimumShouldMatch :: Maybe MinimumMatch
783 , boolQueryBoost :: Maybe Boost
785 , boolQueryBoost :: Maybe Boost
784 , boolQueryDisableCoord :: Maybe DisableCoord
786 , boolQueryDisableCoord :: Maybe DisableCoord
785 } deriving (Eq, Show)
787 } deriving (Eq, Show)
787−mkBoolQuery :: Maybe Query -> Maybe Query -> Maybe [Query] -> BoolQuery
789+mkBoolQuery :: [Query] -> [Query] -> [Query] -> BoolQuery
788mkBoolQuery must mustNot should =
790mkBoolQuery must mustNot should =
789 BoolQuery must mustNot should Nothing Nothing Nothing
791 BoolQuery must mustNot should Nothing Nothing Nothing
@@ -811,7 +813,7 @@ data CommonMinimumMatch =
811 deriving (Eq, Show)
813 deriving (Eq, Show)
813data MinimumMatchHighLow =
815data MinimumMatchHighLow =
814− MinimumMatchHighLow { lowFreq :: MinimumMatch
816+ MinimumMatchHighLow { lowFreq :: MinimumMatch
815 , highFreq :: MinimumMatch } deriving (Eq, Show)
817 , highFreq :: MinimumMatch } deriving (Eq, Show)
817data Filter = AndFilter [Filter] Cache
819data Filter = AndFilter [Filter] Cache
@@ -951,11 +953,11 @@ data FromJSON a => SearchHits a =
951 , hits :: [Hit a] } deriving (Eq, Show)
953 , hits :: [Hit a] } deriving (Eq, Show)
953data FromJSON a => Hit a =
955data FromJSON a => Hit a =
954− Hit { hitIndex :: IndexName
956+ Hit { hitIndex :: IndexName
955− , hitType :: MappingName
957+ , hitType :: MappingName
956− , hitDocId :: DocId
958+ , hitDocId :: DocId
957− , hitScore :: Score
959+ , hitScore :: Score
958− , hitSource :: a } deriving (Eq, Show)
960+ , hitSource :: a } deriving (Eq, Show)
960data ShardResult =
962data ShardResult =
961 ShardResult { shardTotal :: Int
963 ShardResult { shardTotal :: Int
@@ -1370,8 +1372,9 @@ instance ToJSON Query where
1371omitNulls :: [(Text, Value)] -> Value
1373omitNulls :: [(Text, Value)] -> Value
1372omitNulls = object . filter notNull where
1374omitNulls = object . filter notNull where
1373− notNull (_, Null) = False
1375+ notNull (_, Null) = False
1376+ notNull (_, (Array a)) = (not . V.null) a
1374− notNull _ = True
1377+ notNull _ = True
1377instance ToJSON SimpleQueryStringQuery where
1380instance ToJSON SimpleQueryStringQuery where