@@ -47,7 +47,7 @@ module Database.Bloodhound.Types
48 , toDateHistogram
48 , toDateHistogram
49 , omitNulls
49 , omitNulls
52 , BHEnv(..)
52 , BHEnv(..)
53 , MonadBH(..)
53 , MonadBH(..)
@@ -75,6 +75,11 @@ module Database.Bloodhound.Types
75 , TrackSortScores
75 , TrackSortScores
76 , From(..)
76 , From(..)
77 , Size(..)
77 , Size(..)
79+ , PatternOrPatterns(..)
78 , ShardResult(..)
83 , ShardResult(..)
80 , Filter(..)
85 , Filter(..)
@@ -225,6 +230,7 @@ module Database.Bloodhound.Types
227import Control.Applicative
232import Control.Applicative
233+import Control.Monad.Catch
228import Control.Monad.Error
234import Control.Monad.Error
229import Control.Monad.Reader
235import Control.Monad.Reader
230import Control.Monad.State
236import Control.Monad.State
@@ -232,9 +238,9 @@ import Control.Monad.Writer
232import Data.Aeson
238import Data.Aeson
233import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
239import Data.Aeson.Types (Pair, emptyObject, parseMaybe)
234import qualified Data.ByteString.Lazy.Char8 as L
240import qualified Data.ByteString.Lazy.Char8 as L
235−import Data.List (nub, foldl')
236−import Data.List.NonEmpty (NonEmpty (..), toList)
237import qualified Data.HashMap.Strict as HM (union)
241import qualified Data.HashMap.Strict as HM (union)
242+import Data.List (foldl', nub)
243+import Data.List.NonEmpty (NonEmpty (..), toList)
238import qualified Data.Map.Strict as M
244import qualified Data.Map.Strict as M
239import Data.Maybe
245import Data.Maybe
240import Data.Text (Text)
246import Data.Text (Text)
@@ -285,7 +291,10 @@ newtype BH m a = BH {
285 , MonadError e
291 , MonadError e
286 , Alternative
292 , Alternative
287 , MonadPlus
293 , MonadPlus
288− , MonadFix)
294+ , MonadFix
290instance MonadTrans BH where
299instance MonadTrans BH where
291 lift = BH . lift
300 lift = BH . lift
@@ -368,7 +377,7 @@ data FieldDefinition =
368 https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices-templates.html
377 https://www.elastic.co/guide/en/elasticsearch/reference/1.7/indices-templates.html
370data IndexTemplate =
379data IndexTemplate =
371− IndexTemplate { templatePattern :: TemplatePattern
380+ IndexTemplate { templatePattern :: TemplatePattern
372 , templateSettings :: Maybe IndexSettings
381 , templateSettings :: Maybe IndexSettings
373 , templateMappings :: [Value]
382 , templateMappings :: [Value]
@@ -402,9 +411,9 @@ data BulkOperation =
402{-| 'EsResult' describes the standard wrapper JSON document that you see in
411{-| 'EsResult' describes the standard wrapper JSON document that you see in
403 successful Elasticsearch lookups or lookups that couldn't find the document.
412 successful Elasticsearch lookups or lookups that couldn't find the document.
405−data EsResult a = EsResult { _index :: Text
414+data EsResult a = EsResult { _index :: Text
406− , _type :: Text
415+ , _type :: Text
407− , _id :: Text
416+ , _id :: Text
408 , foundResult :: Maybe (EsResultFound a)} deriving (Eq, Show)
417 , foundResult :: Maybe (EsResultFound a)} deriving (Eq, Show)
@@ -412,7 +421,7 @@ data EsResult a = EsResult { _index :: Text
412 'EsResult' when the document was successfully found.
421 'EsResult' when the document was successfully found.
414data EsResultFound a = EsResultFound { _version :: DocVersion
423data EsResultFound a = EsResultFound { _version :: DocVersion
415− , _source :: a } deriving (Eq, Show)
424+ , _source :: a } deriving (Eq, Show)
@@ -733,11 +742,12 @@ data Search = Search { queryBody :: Maybe Query
733 -- default False
742 -- default False
734 , trackSortScores :: TrackSortScores
743 , trackSortScores :: TrackSortScores
735 , from :: From
744 , from :: From
736− , size :: Size
745+ , size :: Size
737 , searchType :: SearchType
746 , searchType :: SearchType
738− , fields :: Maybe [FieldName] } deriving (Eq, Show)
747+ , fields :: Maybe [FieldName]
748+ , source :: Maybe Source } deriving (Eq, Show)
740−data SearchType = SearchTypeQueryThenFetch
750+data SearchType = SearchTypeQueryThenFetch
741 | SearchTypeDfsQueryThenFetch
751 | SearchTypeDfsQueryThenFetch
742 | SearchTypeCount
752 | SearchTypeCount
743 | SearchTypeScan
753 | SearchTypeScan
@@ -745,6 +755,20 @@ data SearchType = SearchTypeQueryThenFetch
745 | SearchTypeDfsQueryAndFetch
755 | SearchTypeDfsQueryAndFetch
746 deriving (Eq, Show)
756 deriving (Eq, Show)
760+ | SourcePatterns PatternOrPatterns
761+ | SourceIncludeExclude Include Exclude
764+data PatternOrPatterns = PopPattern Pattern
765+ | PopPatterns [Pattern] deriving (Eq, Show)
767+data Include = Include [Pattern] deriving (Eq, Show)
768+data Exclude = Exclude [Pattern] deriving (Eq, Show)
770+newtype Pattern = Pattern Text deriving (Eq, Show)
748data Highlights = Highlights { globalsettings :: Maybe HighlightSettings
772data Highlights = Highlights { globalsettings :: Maybe HighlightSettings
749 , highlightFields :: [FieldHighlight]
773 , highlightFields :: [FieldHighlight]
750 } deriving (Show, Eq)
774 } deriving (Show, Eq)
@@ -1031,13 +1055,14 @@ data MatchQuery =
1031 , matchQueryMatchType :: Maybe MatchQueryType
1055 , matchQueryMatchType :: Maybe MatchQueryType
1032 , matchQueryAnalyzer :: Maybe Analyzer
1056 , matchQueryAnalyzer :: Maybe Analyzer
1033 , matchQueryMaxExpansions :: Maybe MaxExpansions
1057 , matchQueryMaxExpansions :: Maybe MaxExpansions
1034− , matchQueryLenient :: Maybe Lenient } deriving (Eq, Show)
1058+ , matchQueryLenient :: Maybe Lenient
1059+ , matchQueryBoost :: Maybe Boost } deriving (Eq, Show)
1036{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
1061{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
1037 enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
1062 enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
1039mkMatchQuery :: FieldName -> QueryString -> MatchQuery
1064mkMatchQuery :: FieldName -> QueryString -> MatchQuery
1040−mkMatchQuery field query = MatchQuery field query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing
1065+mkMatchQuery field query = MatchQuery field query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
1042data MatchQueryType =
1067data MatchQueryType =
1043 MatchPhrase
1068 MatchPhrase
@@ -1256,7 +1281,7 @@ data SearchResult a =
1256 , timedOut :: Bool
1281 , timedOut :: Bool
1257 , shards :: ShardResult
1282 , shards :: ShardResult
1258 , searchHits :: SearchHits a
1283 , searchHits :: SearchHits a
1259− , aggregations :: Maybe AggregationResults
1284+ , aggregations :: Maybe AggregationResults
1260 , scrollId :: Maybe ScrollId } deriving (Eq, Show)
1285 , scrollId :: Maybe ScrollId } deriving (Eq, Show)
1262type ScrollId = Text -- Fixme: Newtype
1287type ScrollId = Text -- Fixme: Newtype
@@ -1367,7 +1392,7 @@ data ValueCountAggregation = FieldValueCount FieldName
1368-- | Single-bucket filter aggregations. See <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html#search-aggregations-bucket-filter-aggregation> for more information.
1393-- | Single-bucket filter aggregations. See <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html#search-aggregations-bucket-filter-aggregation> for more information.
1369data FilterAggregation = FilterAggregation { faFilter :: Filter
1394data FilterAggregation = FilterAggregation { faFilter :: Filter
1370− , faAggs :: Maybe Aggregations} deriving (Eq, Show)
1395+ , faAggs :: Maybe Aggregations} deriving (Eq, Show)
1372mkTermsAggregation :: Text -> TermsAggregation
1397mkTermsAggregation :: Text -> TermsAggregation
1373mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1398mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
@@ -1967,7 +1992,7 @@ instance ToJSON MatchQuery where
1967 toJSON (MatchQuery (FieldName fieldName)
1992 toJSON (MatchQuery (FieldName fieldName)
1968 (QueryString mqQueryString) booleanOperator
1993 (QueryString mqQueryString) booleanOperator
1969 zeroTermsQuery cutoffFrequency matchQueryType
1994 zeroTermsQuery cutoffFrequency matchQueryType
1970− analyzer maxExpansions lenient) =
1995+ analyzer maxExpansions lenient boost) =
1971 object [ fieldName .= omitNulls base ]
1996 object [ fieldName .= omitNulls base ]
1972 where base = [ "query" .= mqQueryString
1997 where base = [ "query" .= mqQueryString
1973 , "operator" .= booleanOperator
1998 , "operator" .= booleanOperator
@@ -1976,7 +2001,8 @@ instance ToJSON MatchQuery where
1976 , "type" .= matchQueryType
2001 , "type" .= matchQueryType
1977 , "analyzer" .= analyzer
2002 , "analyzer" .= analyzer
1978 , "max_expansions" .= maxExpansions
2003 , "max_expansions" .= maxExpansions
1979− , "lenient" .= lenient ]
2004+ , "lenient" .= lenient
2005+ , "boost" .= boost ]
1982instance ToJSON MultiMatchQuery where
2008instance ToJSON MultiMatchQuery where
@@ -2108,7 +2134,7 @@ instance (FromJSON a) => FromJSON (EsResultFound a) where
2108 parseJSON _ = empty
2134 parseJSON _ = empty
2110instance ToJSON Search where
2136instance ToJSON Search where
2111− toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize _ sFields) =
2137+ toJSON (Search query sFilter sort searchAggs highlight sTrackSortScores sFrom sSize _ sFields sSource) =
2112 omitNulls [ "query" .= query
2138 omitNulls [ "query" .= query
2113 , "filter" .= sFilter
2139 , "filter" .= sFilter
2114 , "sort" .= sort
2140 , "sort" .= sort
@@ -2117,7 +2143,27 @@ instance ToJSON Search where
2117 , "from" .= sFrom
2143 , "from" .= sFrom
2118 , "size" .= sSize
2144 , "size" .= sSize
2119 , "track_scores" .= sTrackSortScores
2145 , "track_scores" .= sTrackSortScores
2120− , "fields" .= sFields]
2146+ , "fields" .= sFields
2147+ , "_source" .= sSource]
2150+instance ToJSON Source where
2151+ toJSON NoSource = toJSON False
2152+ toJSON (SourcePatterns patterns) = toJSON patterns
2153+ toJSON (SourceIncludeExclude incl excl) = object [ "include" .= incl, "exclude" .= excl ]
2155+instance ToJSON PatternOrPatterns where
2156+ toJSON (PopPattern pattern) = toJSON pattern
2157+ toJSON (PopPatterns patterns) = toJSON patterns
2159+instance ToJSON Include where
2160+ toJSON (Include patterns) = toJSON patterns
2162+instance ToJSON Exclude where
2163+ toJSON (Exclude patterns) = toJSON patterns
2165+instance ToJSON Pattern where
2166+ toJSON (Pattern pattern) = toJSON pattern
2123instance ToJSON FieldHighlight where
2169instance ToJSON FieldHighlight where