@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE DefaultSignatures #-}
23{-# LANGUAGE DeriveGeneric #-}
34{-# LANGUAGE FlexibleContexts #-}
@@ -95,6 +96,9 @@ es15 = Vers.Version [1, 5, 0] []
9596es16 :: Vers.Version
9697es16 = Vers.Version [1, 6, 0] []
9798
99+es20 :: Vers.Version
100+es20 = Vers.Version [2, 0, 0] []
101+
98102getServerVersion :: IO (Maybe Vers.Version)
99103getServerVersion = fmap extractVersion <$> withTestEnv getStatus
100104 where
@@ -173,15 +177,32 @@ data ParentMapping = ParentMapping deriving (Eq, Show)
173177
174178instance ToJSON ParentMapping where
175179 toJSON ParentMapping =
176− object ["parent" .= Null ]
180+ object ["parent" .=
181+ object ["properties" .=
182+ object [ "user" .= object ["type" .= ("string" :: Text)]
183+ -- Serializing the date as a date is breaking other tests, mysteriously.
184+ -- , "postDate" .= object [ "type" .= ("date" :: Text)
185+ -- , "format" .= ("YYYY-MM-dd`T`HH:mm:ss.SSSZZ" :: Text)]
186+ , "message" .= object ["type" .= ("string" :: Text)]
187+ , "age" .= object ["type" .= ("integer" :: Text)]
188+ , "location" .= object ["type" .= ("geo_point" :: Text)]
189+ ]]]
177190
178191data ChildMapping = ChildMapping deriving (Eq, Show)
179192
180193instance ToJSON ChildMapping where
181194 toJSON ChildMapping =
182195 object ["child" .=
183− object ["_parent" .= object ["type" .= ("parent" :: Text)]]
184− ]
196+ object ["_parent" .= object ["type" .= ("parent" :: Text)]
197+ , "properties" .=
198+ object [ "user" .= object ["type" .= ("string" :: Text)]
199+ -- Serializing the date as a date is breaking other tests, mysteriously.
200+ -- , "postDate" .= object [ "type" .= ("date" :: Text)
201+ -- , "format" .= ("YYYY-MM-dd`T`HH:mm:ss.SSSZZ" :: Text)]
202+ , "message" .= object ["type" .= ("string" :: Text)]
203+ , "age" .= object ["type" .= ("integer" :: Text)]
204+ , "location" .= object ["type" .= ("geo_point" :: Text)]
205+ ]]]
185206
186207data TweetMapping = TweetMapping deriving (Eq, Show)
187208
@@ -585,8 +606,10 @@ noDuplicates xs = nub xs == xs
585606instance Arbitrary NominalDiffTime where
586607 arbitrary = fromInteger <$> arbitrary
587608
609+#if !MIN_VERSION_QuickCheck(2,8,0)
588610instance (Arbitrary k, Ord k, Arbitrary v) => Arbitrary (M.Map k v) where
589611 arbitrary = M.fromList <$> arbitrary
612+#endif
590613
591614instance Arbitrary Text where
592615 arbitrary = T.pack <$> arbitrary
@@ -882,12 +905,17 @@ main = hspec $ do
882905 validateStatus resp 200
883906 validateStatus deleteResp 200
884907
885− describe "error parsing" $ do
886− it "can parse EsErrors" $ withTestEnv $ do
908+ describe "error parsing" $ do
909+ it "can parse EsErrors for < 2.0" $ when' (atmost es16) $ withTestEnv $ do
887910 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
888911 let errorResp = eitherDecode (responseBody res)
889912 liftIO (errorResp `shouldBe` Right (EsError 404 "IndexMissingException[[bogus] missing]"))
890913
914+ it "can parse EsErrors for >= 2.0" $ when' (atleast es20) $ withTestEnv $ do
915+ res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
916+ let errorResp = eitherDecode (responseBody res)
917+ liftIO (errorResp `shouldBe` Right (EsError 404 "no such index"))
918+
891919 describe "document API" $ do
892920 it "indexes, updates, gets, and then deletes the generated document" $ withTestEnv $ do
893921 _ <- insertData
@@ -921,8 +949,8 @@ main = hspec $ do
921949
922950 it "indexes two documents in a parent/child relationship and checks that the child exists" $ withTestEnv $ do
923951 resetIndex
924− _ <- putMapping testIndex (MappingName "parent") ParentMapping
925952 _ <- putMapping testIndex (MappingName "child") ChildMapping
953+ _ <- putMapping testIndex (MappingName "parent") ParentMapping
926954 _ <- indexDocument testIndex (MappingName "parent") defaultIndexDocumentSettings exampleTweet (DocId "1")
927955 let parent = (Just . DocumentParent . DocId) "1"
928956 ids = IndexDocumentSettings NoVersionControl parent
@@ -1241,6 +1269,17 @@ main = hspec $ do
12411269 searchExpectAggs search
12421270 searchValidBucketAgg search "users" toTerms
12431271
1272+ it "returns cardinality aggregation results" $ withTestEnv $ do
1273+ _ <- insertData
1274+ let cardinality = CardinalityAgg $ mkCardinalityAggregation $ FieldName "user"
1275+ let search = mkAggregateSearch Nothing $ mkAggregations "users" cardinality
1276+ let search' = search { Database.Bloodhound.from = From 0, size = Size 0 }
1277+ searchExpectAggs search'
1278+ let docCountPair k n = (k, object ["value" .= Number n])
1279+ res <- searchTweets search'
1280+ liftIO $
1281+ fmap aggregations res `shouldBe` Right (Just (M.fromList [ docCountPair "users" 1]))
1282+
12441283 it "can give collection hint parameters to term aggregations" $ when' (atleast es13) $ withTestEnv $ do
12451284 _ <- insertData
12461285 let terms = TermsAgg $ (mkTermsAggregation "user") { termCollectMode = Just BreadthFirst }