@@ -47,6 +47,8 @@ module Database.V5.Bloodhound.Types
4747 , mkDateHistogram
4848 , mkCardinalityAggregation
4949 , mkDocVersion
50+ , mkStatsAggregation
51+ , mkExtendedStatsAggregation
5052 , docVersionNumber
5153 , toMissing
5254 , toTerms
@@ -341,6 +343,7 @@ module Database.V5.Bloodhound.Types
341343 , DateMathModifier(..)
342344 , DateMathUnit(..)
343345 , TopHitsAggregation(..)
346+ , StatisticsAggregation(..)
344347
345348 , Highlights(..)
346349 , FieldHighlight(..)
@@ -1715,6 +1718,7 @@ data Aggregation = TermsAgg TermsAggregation
17151718 | DateRangeAgg DateRangeAggregation
17161719 | MissingAgg MissingAggregation
17171720 | TopHitsAgg TopHitsAggregation
1721+ | StatsAgg StatisticsAggregation
17181722 deriving (Eq, Read, Show, Generic, Typeable)
17191723
17201724data TopHitsAggregation = TopHitsAggregation
@@ -1792,6 +1796,14 @@ data ValueCountAggregation = FieldValueCount FieldName
17921796data FilterAggregation = FilterAggregation { faFilter :: Filter
17931797 , faAggs :: Maybe Aggregations} deriving (Eq, Read, Show, Generic, Typeable)
17941798
1799+data StatisticsAggregation = StatisticsAggregation { statsType :: StatsType
1800+ , statsField :: FieldName } deriving (Eq, Read, Show, Generic, Typeable)
1801+
1802+data StatsType
1803+ = Basic
1804+ | Extended
1805+ deriving (Eq, Read, Show, Generic, Typeable)
1806+
17951807mkTermsAggregation :: Text -> TermsAggregation
17961808mkTermsAggregation t = TermsAggregation (Left t) Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
17971809
@@ -1804,6 +1816,12 @@ mkDateHistogram t i = DateHistogramAggregation t i Nothing Nothing Nothing Nothi
18041816mkCardinalityAggregation :: FieldName -> CardinalityAggregation
18051817mkCardinalityAggregation t = CardinalityAggregation t Nothing
18061818
1819+mkStatsAggregation :: FieldName -> StatisticsAggregation
1820+mkStatsAggregation = StatisticsAggregation Basic
1821+
1822+mkExtendedStatsAggregation :: FieldName -> StatisticsAggregation
1823+mkExtendedStatsAggregation = StatisticsAggregation Extended
1824+
18071825instance ToJSON Version where
18081826 toJSON Version {..} = object ["number" .= number
18091827 ,"build_hash" .= build_hash
@@ -1928,6 +1946,12 @@ instance ToJSON Aggregation where
19281946 ]
19291947 ]
19301948
1949+ toJSON (StatsAgg (StatisticsAggregation typ field)) =
1950+ object [stType .= omitNulls [ "field" .= field ]]
1951+ where
1952+ stType | typ == Basic = "stats"
1953+ | otherwise = "extended_stats"
1954+
19311955instance ToJSON DateRangeAggregation where
19321956 toJSON DateRangeAggregation {..} =
19331957 omitNulls [ "field" .= draField