bloodhound 0.13.0.0 → 0.14.0.0
raw patch · 6 files changed
+86/−4 lines, 6 filesdep ~aesonPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson
API changes (from Hackage documentation)
+ Database.V5.Bloodhound.Client: getInitialSortedScroll :: (FromJSON a, MonadThrow m, MonadBH m) => IndexName -> MappingName -> Search -> m (Either EsError (SearchResult a))
+ Database.V5.Bloodhound.Types: StatisticsAggregation :: StatsType -> FieldName -> StatisticsAggregation
+ Database.V5.Bloodhound.Types: StatsAgg :: StatisticsAggregation -> Aggregation
+ Database.V5.Bloodhound.Types: [statsField] :: StatisticsAggregation -> FieldName
+ Database.V5.Bloodhound.Types: [statsType] :: StatisticsAggregation -> StatsType
+ Database.V5.Bloodhound.Types: data StatisticsAggregation
+ Database.V5.Bloodhound.Types: instance GHC.Classes.Eq Database.V5.Bloodhound.Types.StatisticsAggregation
+ Database.V5.Bloodhound.Types: instance GHC.Classes.Eq Database.V5.Bloodhound.Types.StatsType
+ Database.V5.Bloodhound.Types: instance GHC.Generics.Generic Database.V5.Bloodhound.Types.StatisticsAggregation
+ Database.V5.Bloodhound.Types: instance GHC.Generics.Generic Database.V5.Bloodhound.Types.StatsType
+ Database.V5.Bloodhound.Types: instance GHC.Read.Read Database.V5.Bloodhound.Types.StatisticsAggregation
+ Database.V5.Bloodhound.Types: instance GHC.Read.Read Database.V5.Bloodhound.Types.StatsType
+ Database.V5.Bloodhound.Types: instance GHC.Show.Show Database.V5.Bloodhound.Types.StatisticsAggregation
+ Database.V5.Bloodhound.Types: instance GHC.Show.Show Database.V5.Bloodhound.Types.StatsType
+ Database.V5.Bloodhound.Types: mkExtendedStatsAggregation :: FieldName -> StatisticsAggregation
+ Database.V5.Bloodhound.Types: mkStatsAggregation :: FieldName -> StatisticsAggregation
Files
- bloodhound.cabal +2/−2
- changelog.md +27/−0
- src/Database/V1/Bloodhound/Client.hs +1/−1
- src/Database/V5/Bloodhound/Client.hs +17/−1
- src/Database/V5/Bloodhound/Types.hs +24/−0
- tests/V5/tests.hs +15/−0
bloodhound.cabal view
@@ -1,5 +1,5 @@ name: bloodhound-version: 0.13.0.0+version: 0.14.0.0 synopsis: ElasticSearch client library for Haskell description: ElasticSearch made awesome for Haskell hackers homepage: https://github.com/bitemyapp/bloodhound@@ -44,7 +44,7 @@ build-depends: base >= 4.3 && <5, bytestring >= 0.10.0 && <0.11, containers >= 0.5.0.0 && <0.6,- aeson >= 0.11.1 && <1.2,+ aeson >= 0.11.1 && <1.3, http-client >= 0.4.30 && <0.6, network-uri >= 2.6 && <2.7, semigroups >= 0.15 && <0.19,
changelog.md view
@@ -1,3 +1,30 @@+0.14.0.0+===================++- @bitemyapp+ - Aeson 1.2++- @shmish111+ - #177 Added stats aggregation++- @justinwhite+ - #176 Fixed typo++- @WraithM+ - #175 Sorted version of getInitialScroll for V5 client++0.13.0.0+===================++- @michaelxavier+ - #174 doctests are bad+ - #171 Added Semigroup instances+ - #165 Aeson 1.1++- @bermanjosh+ - #168 Sub-aggregation support+ - #167 Limit QuickCheck to 500 checks+ 0.12.1.0 =================== * @michaelxavier
src/Database/V1/Bloodhound/Client.hs view
@@ -794,7 +794,7 @@ (MappingName mappingName) = bindM2 dispatchSearch url . return where url = joinPath [indexName, mappingName, "_search"] --- | For a given scearch, request a scroll for efficient streaming of+-- | For a given search, request a scroll for efficient streaming of -- search results. Note that the search is put into 'SearchTypeScan' -- mode and thus results will not be sorted. Combine this with -- 'advanceScroll' to efficiently stream through the full result set
src/Database/V5/Bloodhound/Client.hs view
@@ -55,6 +55,7 @@ , searchByType , scanSearch , getInitialScroll+ , getInitialSortedScroll , advanceScroll , refreshIndex , mkSearch@@ -938,7 +939,7 @@ (MappingName mappingName) = bindM2 dispatchSearch url . return where url = joinPath [indexName, mappingName, "_search"] --- | For a given scearch, request a scroll for efficient streaming of+-- | For a given search, request a scroll for efficient streaming of -- search results. Note that the search is put into 'SearchTypeScan' -- mode and thus results will not be sorted. Combine this with -- 'advanceScroll' to efficiently stream through the full result set@@ -952,6 +953,21 @@ params = [("scroll", Just "1m")] sorting = Just [DefaultSortSpec $ mkSort (FieldName "_doc") Descending] search = search' { sortBody = sorting }+ resp' <- bindM2 dispatchSearch url (return search)+ parseEsResponse resp'++-- | For a given search, request a scroll for efficient streaming of+-- search results. Combine this with 'advanceScroll' to efficiently+-- stream through the full result set. Note that this search respects+-- sorting and may be less efficient than 'getInitialScroll'.+getInitialSortedScroll ::+ (FromJSON a, MonadThrow m, MonadBH m) => IndexName ->+ MappingName ->+ Search ->+ m (Either EsError (SearchResult a))+getInitialSortedScroll (IndexName indexName) (MappingName mappingName) search = do+ let url = addQuery params <$> joinPath [indexName, mappingName, "_search"]+ params = [("scroll", Just "1m")] resp' <- bindM2 dispatchSearch url (return search) parseEsResponse resp'
src/Database/V5/Bloodhound/Types.hs view
@@ -47,6 +47,8 @@ , mkDateHistogram , mkCardinalityAggregation , mkDocVersion+ , mkStatsAggregation+ , mkExtendedStatsAggregation , docVersionNumber , toMissing , toTerms@@ -341,6 +343,7 @@ , DateMathModifier(..) , DateMathUnit(..) , TopHitsAggregation(..)+ , StatisticsAggregation(..) , Highlights(..) , FieldHighlight(..)@@ -1715,6 +1718,7 @@ | DateRangeAgg DateRangeAggregation | MissingAgg MissingAggregation | TopHitsAgg TopHitsAggregation+ | StatsAgg StatisticsAggregation deriving (Eq, Read, Show, Generic, Typeable) data TopHitsAggregation = TopHitsAggregation@@ -1792,6 +1796,14 @@ data FilterAggregation = FilterAggregation { faFilter :: Filter , faAggs :: Maybe Aggregations} deriving (Eq, Read, Show, Generic, Typeable) +data StatisticsAggregation = StatisticsAggregation { statsType :: StatsType+ , statsField :: FieldName } deriving (Eq, Read, Show, Generic, Typeable)++data StatsType+ = Basic+ | Extended+ deriving (Eq, Read, Show, Generic, Typeable)+ mkTermsAggregation :: Text -> TermsAggregation mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing @@ -1804,6 +1816,12 @@ mkCardinalityAggregation :: FieldName -> CardinalityAggregation mkCardinalityAggregation t = CardinalityAggregation t Nothing +mkStatsAggregation :: FieldName -> StatisticsAggregation+mkStatsAggregation = StatisticsAggregation Basic++mkExtendedStatsAggregation :: FieldName -> StatisticsAggregation+mkExtendedStatsAggregation = StatisticsAggregation Extended+ instance ToJSON Version where toJSON Version {..} = object ["number" .= number ,"build_hash" .= build_hash@@ -1927,6 +1945,12 @@ , "sort" .= msort ] ]++ toJSON (StatsAgg (StatisticsAggregation typ field)) =+ object [stType .= omitNulls [ "field" .= field ]]+ where+ stType | typ == Basic = "stats"+ | otherwise = "extended_stats" instance ToJSON DateRangeAggregation where toJSON DateRangeAggregation {..} =
tests/V5/tests.hs view
@@ -1144,6 +1144,21 @@ liftIO $ fmap aggregations res `shouldBe` Right (Just (M.fromList [ docCountPair "users" 1])) + it "returns stats aggregation results" $ withTestEnv $ do+ _ <- insertData+ let stats = StatsAgg $ mkStatsAggregation $ FieldName "age"+ let search = mkAggregateSearch Nothing $ mkAggregations "users" stats+ let search' = search { Database.V5.Bloodhound.from = From 0, size = Size 0 }+ searchExpectAggs search'+ let statsAggRes k n = (k, object [ "max" .= Number n+ , "avg" .= Number n+ , "count" .= Number 1+ , "min" .= Number n+ , "sum" .= Number n])+ res <- searchTweets search'+ liftIO $+ fmap aggregations res `shouldBe` Right (Just (M.fromList [ statsAggRes "users" 10000]))+ it "can give collection hint parameters to term aggregations" $ when' (atleast es13) $ withTestEnv $ do _ <- insertData let terms = TermsAgg $ (mkTermsAggregation "user") { termCollectMode = Just BreadthFirst }