git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #201 from andrewthad/bulk_create_encoding
ac096ceChris Allen
src/Database/V5/Bloodhound/Client.hs+6
@@ -892,6 +892,12 @@ encodeBulkOperation (BulkUpdate (IndexName indexName)
892 doc = object ["doc" .= value]
892 doc = object ["doc" .= value]
893 blob = encode metadata `mappend` "\n" `mappend` encode doc
893 blob = encode metadata `mappend` "\n" `mappend` encode doc
894
894
895+encodeBulkOperation (BulkCreateEncoding (IndexName indexName)
896+ (MappingName mappingName)
897+ (DocId docId) encoding) = toLazyByteString blob
898+ where metadata = toEncoding (mkBulkStreamValue "create" indexName mappingName docId)
899+ blob = fromEncoding metadata <> "\n" <> fromEncoding encoding
900+
895-- | 'getDocument' is a straight-forward way to fetch a single document from
901-- | 'getDocument' is a straight-forward way to fetch a single document from
896-- Elasticsearch using a 'Server', 'IndexName', 'MappingName', and a 'DocId'.
902-- Elasticsearch using a 'Server', 'IndexName', 'MappingName', and a 'DocId'.
897-- The 'DocId' is the primary key for your Elasticsearch document.
903-- The 'DocId' is the primary key for your Elasticsearch document.
src/Database/V5/Bloodhound/Types.hs+2−1
@@ -710,8 +710,9 @@ data Mapping = Mapping { typeName :: TypeName
710data BulkOperation =
710data BulkOperation =
711 BulkIndex IndexName MappingName DocId Value
711 BulkIndex IndexName MappingName DocId Value
712 | BulkCreate IndexName MappingName DocId Value
712 | BulkCreate IndexName MappingName DocId Value
713+ | BulkCreateEncoding IndexName MappingName DocId Encoding
713 | BulkDelete IndexName MappingName DocId
714 | BulkDelete IndexName MappingName DocId
714− | BulkUpdate IndexName MappingName DocId Value deriving (Eq, Read, Show, Generic, Typeable)
715+ | BulkUpdate IndexName MappingName DocId Value deriving (Eq, Show, Generic, Typeable)
715
716
716{-| 'EsResult' describes the standard wrapper JSON document that you see in
717{-| 'EsResult' describes the standard wrapper JSON document that you see in
717 successful Elasticsearch lookups or lookups that couldn't find the document.
718 successful Elasticsearch lookups or lookups that couldn't find the document.
tests/V5/tests.hs+7−1
@@ -1028,20 +1028,26 @@ main = hspec $ do
1028 _ <- insertData
1028 _ <- insertData
1029 let firstTest = BulkTest "blah"
1029 let firstTest = BulkTest "blah"
1030 let secondTest = BulkTest "bloo"
1030 let secondTest = BulkTest "bloo"
1031+ let thirdTest = BulkTest "graffle"
1031 let firstDoc = BulkIndex testIndex
1032 let firstDoc = BulkIndex testIndex
1032 testMapping (DocId "2") (toJSON firstTest)
1033 testMapping (DocId "2") (toJSON firstTest)
1033 let secondDoc = BulkCreate testIndex
1034 let secondDoc = BulkCreate testIndex
1034 testMapping (DocId "3") (toJSON secondTest)
1035 testMapping (DocId "3") (toJSON secondTest)
1036+ let thirdDoc = BulkCreateEncoding testIndex
1037+ testMapping (DocId "4") (toEncoding thirdTest)
1035− let stream = V.fromList [firstDoc, secondDoc]
1038+ let stream = V.fromList [firstDoc, secondDoc, thirdDoc]
1036 _ <- bulk stream
1039 _ <- bulk stream
1037 _ <- refreshIndex testIndex
1040 _ <- refreshIndex testIndex
1038 fDoc <- getDocument testIndex testMapping (DocId "2")
1041 fDoc <- getDocument testIndex testMapping (DocId "2")
1039 sDoc <- getDocument testIndex testMapping (DocId "3")
1042 sDoc <- getDocument testIndex testMapping (DocId "3")
1043+ tDoc <- getDocument testIndex testMapping (DocId "4")
1040 let maybeFirst = eitherDecode $ responseBody fDoc :: Either String (EsResult BulkTest)
1044 let maybeFirst = eitherDecode $ responseBody fDoc :: Either String (EsResult BulkTest)
1041 let maybeSecond = eitherDecode $ responseBody sDoc :: Either String (EsResult BulkTest)
1045 let maybeSecond = eitherDecode $ responseBody sDoc :: Either String (EsResult BulkTest)
1046+ let maybeThird = eitherDecode $ responseBody tDoc :: Either String (EsResult BulkTest)
1042 liftIO $ do
1047 liftIO $ do
1043 fmap getSource maybeFirst `shouldBe` Right (Just firstTest)
1048 fmap getSource maybeFirst `shouldBe` Right (Just firstTest)
1044 fmap getSource maybeSecond `shouldBe` Right (Just secondTest)
1049 fmap getSource maybeSecond `shouldBe` Right (Just secondTest)
1050+ fmap getSource maybeThird `shouldBe` Right (Just thirdTest)
1045
1051
1046
1052
1047 describe "query API" $ do
1053 describe "query API" $ do