@@ -46,6 +46,9 @@ import Data.Typeable
46import qualified Data.Vector as V
46import qualified Data.Vector as V
47import qualified Data.Version as Vers
47import qualified Data.Version as Vers
48import Database.V5.Bloodhound
48import Database.V5.Bloodhound
50+import Lens.Micro.Aeson
51+import qualified Lens.Micro.Aeson as LMA
49import Network.HTTP.Client hiding (Proxy)
52import Network.HTTP.Client hiding (Proxy)
50import qualified Network.HTTP.Types.Method as NHTM
53import qualified Network.HTTP.Types.Method as NHTM
51import qualified Network.HTTP.Types.Status as NHTS
54import qualified Network.HTTP.Types.Status as NHTS
@@ -59,7 +62,7 @@ import Test.QuickCheck.Property.Monoid (T (..), eq, prop_Monoid)
59import Test.Hspec.QuickCheck (prop)
62import Test.Hspec.QuickCheck (prop)
60import Test.QuickCheck
63import Test.QuickCheck
61import Test.QuickCheck.TH.Generators
64import Test.QuickCheck.TH.Generators
62−import Text.Pretty.Simple (pPrint)
65+-- import Text.Pretty.Simple (pPrint)
64testServer :: Server
67testServer :: Server
65testServer = Server "http://localhost:9200"
68testServer = Server "http://localhost:9200"
@@ -580,13 +583,13 @@ instance Arbitrary AliasRouting where
580 arbitrary = oneof [allAlias
583 arbitrary = oneof [allAlias
582 ,theOther
585 ,theOther
584 where one = GranularAliasRouting
587 where one = GranularAliasRouting
585 <$> (Just <$> arbitrary)
588 <$> (Just <$> arbitrary)
586 <*> pure Nothing
589 <*> pure Nothing
587 theOther = GranularAliasRouting Nothing
590 theOther = GranularAliasRouting Nothing
588 <$> (Just <$> arbitrary)
591 <$> (Just <$> arbitrary)
589− both = GranularAliasRouting
592+ both' = GranularAliasRouting
590 <$> (Just <$> arbitrary)
593 <$> (Just <$> arbitrary)
591 <*> (Just <$> arbitrary)
594 <*> (Just <$> arbitrary)
592 allAlias = AllAliasRouting <$> arbitrary
595 allAlias = AllAliasRouting <$> arbitrary
@@ -1123,20 +1126,28 @@ main = hspec $ do
1123 let firstTest = BulkTest "blah"
1126 let firstTest = BulkTest "blah"
1124 let secondTest = BulkTest "bloo"
1127 let secondTest = BulkTest "bloo"
1125 let thirdTest = BulkTest "graffle"
1128 let thirdTest = BulkTest "graffle"
1129+ let fourthTest = BulkTest "garabadoo"
1130+ let fifthTest = BulkTest "serenity"
1126 let firstDoc = BulkIndex testIndex
1131 let firstDoc = BulkIndex testIndex
1127 testMapping (DocId "2") (toJSON firstTest)
1132 testMapping (DocId "2") (toJSON firstTest)
1128 let secondDoc = BulkCreate testIndex
1133 let secondDoc = BulkCreate testIndex
1129 testMapping (DocId "3") (toJSON secondTest)
1134 testMapping (DocId "3") (toJSON secondTest)
1130 let thirdDoc = BulkCreateEncoding testIndex
1135 let thirdDoc = BulkCreateEncoding testIndex
1131 testMapping (DocId "4") (toEncoding thirdTest)
1136 testMapping (DocId "4") (toEncoding thirdTest)
1137+ let fourthDoc = BulkIndexAuto testIndex
1138+ testMapping (toJSON fourthTest)
1139+ let fifthDoc = BulkIndexEncodingAuto testIndex
1140+ testMapping (toEncoding fifthTest)
1132− let stream = V.fromList [firstDoc, secondDoc, thirdDoc]
1141+ let stream = V.fromList [firstDoc, secondDoc, thirdDoc, fourthDoc, fifthDoc]
1133− bulkResp <- bulk stream
1142+ _ <- bulk stream
1134− liftIO $ pPrint bulkResp
1143+ -- liftIO $ pPrint bulkResp
1135− refreshResp <- refreshIndex testIndex
1144+ _ <- refreshIndex testIndex
1136− liftIO $ pPrint refreshResp
1145+ -- liftIO $ pPrint refreshResp
1137 fDoc <- getDocument testIndex testMapping (DocId "2")
1146 fDoc <- getDocument testIndex testMapping (DocId "2")
1138 sDoc <- getDocument testIndex testMapping (DocId "3")
1147 sDoc <- getDocument testIndex testMapping (DocId "3")
1139 tDoc <- getDocument testIndex testMapping (DocId "4")
1148 tDoc <- getDocument testIndex testMapping (DocId "4")
1149+ -- note that we cannot query for fourthDoc and fifthDoc since we
1150+ -- do not know their autogenerated ids.
1140 let maybeFirst =
1151 let maybeFirst =
1141 eitherDecode
1152 eitherDecode
1142 $ responseBody fDoc
1153 $ responseBody fDoc
@@ -1149,11 +1160,34 @@ main = hspec $ do
1149 eitherDecode
1160 eitherDecode
1150 $ responseBody tDoc
1161 $ responseBody tDoc
1151 :: Either String (EsResult BulkTest)
1162 :: Either String (EsResult BulkTest)
1152− liftIO $ pPrint [maybeFirst, maybeSecond, maybeThird]
1163+ -- liftIO $ pPrint [maybeFirst, maybeSecond, maybeThird]
1153 liftIO $ do
1164 liftIO $ do
1154 fmap getSource maybeFirst `shouldBe` Right (Just firstTest)
1165 fmap getSource maybeFirst `shouldBe` Right (Just firstTest)
1155 fmap getSource maybeSecond `shouldBe` Right (Just secondTest)
1166 fmap getSource maybeSecond `shouldBe` Right (Just secondTest)
1156 fmap getSource maybeThird `shouldBe` Right (Just thirdTest)
1167 fmap getSource maybeThird `shouldBe` Right (Just thirdTest)
1168+ -- Since we can't get the docs by doc id, we check for their existence in
1169+ -- a match all query.
1170+ let query = MatchAllQuery Nothing
1171+ let search = mkSearch (Just query) Nothing
1172+ resp <- searchByIndex testIndex search
1173+ parsed <- parseEsResponse resp :: BH IO (Either EsError (SearchResult Value))
1176+ liftIO $ expectationFailure ("Expected a script-transformed result but got: " <> show e)
1179+ hitsTotal (searchHits sr) `shouldBe` 6
1180+ let nameList :: [Text]
1182+ (hits (searchHits sr))
1190+ `shouldBe` ["blah","bloo","graffle","garabadoo","serenity"]
1159 describe "query API" $ do
1193 describe "query API" $ do