@@ -1,3 +1,4 @@
1{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
@@ -95,6 +96,9 @@ es15 = Vers.Version [1, 5, 0] []
95es16 :: Vers.Version
96es16 :: Vers.Version
96es16 = Vers.Version [1, 6, 0] []
97es16 = Vers.Version [1, 6, 0] []
100+es20 = Vers.Version [2, 0, 0] []
98getServerVersion :: IO (Maybe Vers.Version)
102getServerVersion :: IO (Maybe Vers.Version)
99getServerVersion = fmap extractVersion <$> withTestEnv getStatus
103getServerVersion = fmap extractVersion <$> withTestEnv getStatus
@@ -173,15 +177,32 @@ data ParentMapping = ParentMapping deriving (Eq, Show)
174instance ToJSON ParentMapping where
178instance ToJSON ParentMapping where
175 toJSON ParentMapping =
179 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)]
178data ChildMapping = ChildMapping deriving (Eq, Show)
191data ChildMapping = ChildMapping deriving (Eq, Show)
180instance ToJSON ChildMapping where
193instance ToJSON ChildMapping where
181 toJSON ChildMapping =
194 toJSON ChildMapping =
182 object ["child" .=
195 object ["child" .=
183− object ["_parent" .= object ["type" .= ("parent" :: Text)]]
196+ object ["_parent" .= object ["type" .= ("parent" :: Text)]
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)]
186data TweetMapping = TweetMapping deriving (Eq, Show)
207data TweetMapping = TweetMapping deriving (Eq, Show)
@@ -585,8 +606,10 @@ noDuplicates xs = nub xs == xs
585instance Arbitrary NominalDiffTime where
606instance Arbitrary NominalDiffTime where
586 arbitrary = fromInteger <$> arbitrary
607 arbitrary = fromInteger <$> arbitrary
609+#if !MIN_VERSION_QuickCheck(2,8,0)
588instance (Arbitrary k, Ord k, Arbitrary v) => Arbitrary (M.Map k v) where
610instance (Arbitrary k, Ord k, Arbitrary v) => Arbitrary (M.Map k v) where
589 arbitrary = M.fromList <$> arbitrary
611 arbitrary = M.fromList <$> arbitrary
591instance Arbitrary Text where
614instance Arbitrary Text where
592 arbitrary = T.pack <$> arbitrary
615 arbitrary = T.pack <$> arbitrary
@@ -882,12 +905,17 @@ main = hspec $ do
882 validateStatus resp 200
905 validateStatus resp 200
883 validateStatus deleteResp 200
906 validateStatus deleteResp 200
885− describe "error parsing" $ do
908+ describe "error parsing" $ do
886− it "can parse EsErrors" $ withTestEnv $ do
909+ it "can parse EsErrors for < 2.0" $ when' (atmost es16) $ withTestEnv $ do
887 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
910 res <- getDocument (IndexName "bogus") (MappingName "also_bogus") (DocId "bogus_as_well")
888 let errorResp = eitherDecode (responseBody res)
911 let errorResp = eitherDecode (responseBody res)
889 liftIO (errorResp `shouldBe` Right (EsError 404 "IndexMissingException[[bogus] missing]"))
912 liftIO (errorResp `shouldBe` Right (EsError 404 "IndexMissingException[[bogus] missing]"))
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"))
891 describe "document API" $ do
919 describe "document API" $ do
892 it "indexes, updates, gets, and then deletes the generated document" $ withTestEnv $ do
920 it "indexes, updates, gets, and then deletes the generated document" $ withTestEnv $ do
893 _ <- insertData
921 _ <- insertData
@@ -921,8 +949,8 @@ main = hspec $ do
922 it "indexes two documents in a parent/child relationship and checks that the child exists" $ withTestEnv $ do
950 it "indexes two documents in a parent/child relationship and checks that the child exists" $ withTestEnv $ do
923 resetIndex
951 resetIndex
924− _ <- putMapping testIndex (MappingName "parent") ParentMapping
925 _ <- putMapping testIndex (MappingName "child") ChildMapping
952 _ <- putMapping testIndex (MappingName "child") ChildMapping
953+ _ <- putMapping testIndex (MappingName "parent") ParentMapping
926 _ <- indexDocument testIndex (MappingName "parent") defaultIndexDocumentSettings exampleTweet (DocId "1")
954 _ <- indexDocument testIndex (MappingName "parent") defaultIndexDocumentSettings exampleTweet (DocId "1")
927 let parent = (Just . DocumentParent . DocId) "1"
955 let parent = (Just . DocumentParent . DocId) "1"
928 ids = IndexDocumentSettings NoVersionControl parent
956 ids = IndexDocumentSettings NoVersionControl parent
@@ -1241,6 +1269,17 @@ main = hspec $ do
1241 searchExpectAggs search
1269 searchExpectAggs search
1242 searchValidBucketAgg search "users" toTerms
1270 searchValidBucketAgg search "users" toTerms
1272+ it "returns cardinality aggregation results" $ withTestEnv $ do
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'
1281+ fmap aggregations res `shouldBe` Right (Just (M.fromList [ docCountPair "users" 1]))
1244 it "can give collection hint parameters to term aggregations" $ when' (atleast es13) $ withTestEnv $ do
1283 it "can give collection hint parameters to term aggregations" $ when' (atleast es13) $ withTestEnv $ do
1245 _ <- insertData
1284 _ <- insertData
1246 let terms = TermsAgg $ (mkTermsAggregation "user") { termCollectMode = Just BreadthFirst }
1285 let terms = TermsAgg $ (mkTermsAggregation "user") { termCollectMode = Just BreadthFirst }