git.iko.soy/typeable/bloodhound
on master help sign in
Add support for parsing the results of Missing Aggregations
commit6e1e445c4f4de32596776c4d5d00dbe475cb828f authorMHova <mho@sumall.com> dateWed 3 Feb 2016, 17:20 (11 years ago) parent2571bb5
1 file changed+12
src/Database/Bloodhound/Types.hs+12
src/Database/Bloodhound/Types.hs+12
@@ -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)
@@ -1817,6 +1821,10 @@ toDateHistogram :: Text -> AggregationResults -> Maybe (Bucket DateHistogramResu
18171821toDateHistogram t a = M.lookup t a >>= deserialize
18181822 where deserialize = parseMaybe parseJSON
18191823
1824+toMissing :: Text -> AggregationResults -> Maybe MissingResult
1825+toMissing t a = M.lookup t a >>= deserialize
1826+ where deserialize = parseMaybe parseJSON
1827+
18201828instance BucketAggregation TermsResult where
18211829 key = termKey
18221830 docCount = termsDocCount
@@ -1843,6 +1851,10 @@ instance FromJSON BucketValue where
18431851 parseJSON (Bool b) = return $ BoolValue b
18441852 parseJSON _ = mempty
18451853
1854+instance FromJSON MissingResult where
1855+ parseJSON = withObject "MissingResult" parse
1856+ where parse v = MissingResult <$> v .: "doc_count"
1857+
18461858instance FromJSON TermsResult where
18471859 parseJSON (Object v) = TermsResult <$>
18481860 v .: "key" <*>