@@ -130,7 +130,8 @@ data Tweet = Tweet { user :: Text
130130 , postDate :: UTCTime
131131 , message :: Text
132132 , age :: Int
133− , location :: Location }
133+ , location :: Location
134+ , extra :: Maybe Text }
134135 deriving (Eq, Generic, Show)
135136
136137instance ToJSON Tweet where
@@ -178,7 +179,18 @@ exampleTweet = Tweet { user = "bitemyapp"
178179 (secondsToDiffTime 10)
179180 , message = "Use haskell!"
180181 , age = 10000
181− , location = Location 40.12 (-71.34) }
182+ , location = Location 40.12 (-71.34)
183+ , extra = Nothing }
184+
185+tweetWithExtra :: Tweet
186+tweetWithExtra = Tweet { user = "bitemyapp"
187+ , postDate = UTCTime
188+ (ModifiedJulianDay 55000)
189+ (secondsToDiffTime 10)
190+ , message = "Use haskell!"
191+ , age = 10000
192+ , location = Location 40.12 (-71.34)
193+ , extra = Just "blah blah" }
182194
183195newAge :: Int
184196newAge = 31337
@@ -202,7 +214,8 @@ otherTweet = Tweet { user = "notmyapp"
202214 (secondsToDiffTime 11)
203215 , message = "Use haskell!"
204216 , age = 1000
205− , location = Location 40.12 (-71.34) }
217+ , location = Location 40.12 (-71.34)
218+ , extra = Nothing }
206219
207220resetIndex :: BH IO ()
208221resetIndex = do
@@ -234,6 +247,12 @@ insertOther = do
234247 _ <- refreshIndex testIndex
235248 return ()
236249
250+insertExtra :: BH IO ()
251+insertExtra = do
252+ _ <- indexDocument testIndex testMapping defaultIndexDocumentSettings tweetWithExtra (DocId "4")
253+ _ <- refreshIndex testIndex
254+ return ()
255+
237256insertWithSpaceInId :: BH IO ()
238257insertWithSpaceInId = do
239258 _ <- indexDocument testIndex testMapping defaultIndexDocumentSettings exampleTweet (DocId "Hello World")
@@ -1236,6 +1255,16 @@ main = hspec $ do
12361255 forM_ intervals expect
12371256 forM_ intervals valid
12381257
1258+ it "can execute missing aggregations" $ withTestEnv $ do
1259+ _ <- insertData
1260+ _ <- insertExtra
1261+ let ags = mkAggregations "missing_agg" (MissingAgg (MissingAggregation "extra"))
1262+ let search = mkAggregateSearch Nothing ags
1263+ let docCountPair k n = (k, object ["doc_count" .= Number n])
1264+ res <- searchTweets search
1265+ liftIO $
1266+ fmap aggregations res `shouldBe` Right (Just (M.fromList [docCountPair "missing_agg" 1]))
1267+
12391268 describe "Highlights API" $ do
12401269
12411270 it "returns highlight from query when there should be one" $ withTestEnv $ do
@@ -1284,7 +1313,8 @@ main = hspec $ do
12841313
12851314 it "excludes source patterns" $ withTestEnv $ do
12861315 searchExpectSource
1287− (SourceIncludeExclude (Include []) (Exclude [Pattern "l*", Pattern "*ge", Pattern "postDate"]))
1316+ (SourceIncludeExclude (Include [])
1317+ (Exclude [Pattern "l*", Pattern "*ge", Pattern "postDate", Pattern "extra"]))
12881318 (Right (Object (HM.fromList [("user",String "bitemyapp")])))
12891319
12901320 describe "ToJSON RegexpFlags" $ do