@@ -47,6 +47,7 @@ module Database.Bloodhound.Types
4747 , mkDateHistogram
4848 , mkDocVersion
4949 , docVersionNumber
50+ , toMissing
5051 , toTerms
5152 , toDateHistogram
5253 , omitNulls
@@ -265,6 +266,7 @@ module Database.Bloodhound.Types
265266 , HighlightTag(..)
266267 , HitHighlight
267268
269+ , MissingResult(..)
268270 , TermsResult(..)
269271 , DateHistogramResult(..)
270272 , DateRangeResult(..)
@@ -1792,6 +1794,8 @@ data BucketValue = TextValue Text
17921794 | ScientificValue Scientific
17931795 | BoolValue Bool deriving (Show)
17941796
1797+data MissingResult = MissingResult { missingDocCount :: Int } deriving (Show)
1798+
17951799data TermsResult = TermsResult { termKey :: BucketValue
17961800 , termsDocCount :: Int
17971801 , termsAggs :: Maybe AggregationResults } deriving (Show)
@@ -1810,11 +1814,16 @@ data DateRangeResult = DateRangeResult { dateRangeKey :: Text
18101814 , dateRangeAggs :: Maybe AggregationResults } deriving (Show, Eq, Generic, Typeable)
18111815
18121816toTerms :: Text -> AggregationResults -> Maybe (Bucket TermsResult)
1813−toTerms t a = M.lookup t a >>= deserialize
1814− where deserialize = parseMaybe parseJSON
1817+toTerms = toAggResult
18151818
18161819toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResult)
1817−toDateHistogram t a = M.lookup t a >>= deserialize
1820+toDateHistogram = toAggResult
1821+
1822+toMissing :: Text -> AggregationResults -> Maybe MissingResult
1823+toMissing = toAggResult
1824+
1825+toAggResult :: (FromJSON a) => Text -> AggregationResults -> Maybe a
1826+toAggResult t a = M.lookup t a >>= deserialize
18181827 where deserialize = parseMaybe parseJSON
18191828
18201829instance BucketAggregation TermsResult where
@@ -1843,6 +1852,10 @@ instance FromJSON BucketValue where
18431852 parseJSON (Bool b) = return $ BoolValue b
18441853 parseJSON _ = mempty
18451854
1855+instance FromJSON MissingResult where
1856+ parseJSON = withObject "MissingResult" parse
1857+ where parse v = MissingResult <$> v .: "doc_count"
1858+
18461859instance FromJSON TermsResult where
18471860 parseJSON (Object v) = TermsResult <$>
18481861 v .: "key" <*>