git.iko.soy/typeable/bloodhound
on master help sign in
Merge pull request #201 from andrewthad/bulk_create_encoding

bulk create encoding

commitac096ce02359f7948faac50191f84d18e90837ce authorChris Allen <cma@bitemyapp.com> dateWed 30 Aug 2017, 17:21 (9 years ago) parenta49fd8e2a44ce4
3 files changed+15−2
src/Database/V5/Bloodhound/Client.hs+6 src/Database/V5/Bloodhound/Types.hs+2−1 tests/V5/tests.hs+7−1
src/Database/V5/Bloodhound/Client.hs+6
@@ -892,6 +892,12 @@ encodeBulkOperation (BulkUpdate (IndexName indexName)
892892 doc = object ["doc" .= value]
893893 blob = encode metadata `mappend` "\n" `mappend` encode doc
894894
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+
895901-- | 'getDocument' is a straight-forward way to fetch a single document from
896902-- Elasticsearch using a 'Server', 'IndexName', 'MappingName', and a 'DocId'.
897903-- 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
710710data BulkOperation =
711711 BulkIndex IndexName MappingName DocId Value
712712 | BulkCreate IndexName MappingName DocId Value
713+ | BulkCreateEncoding IndexName MappingName DocId Encoding
713714 | 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)
715716
716717{-| 'EsResult' describes the standard wrapper JSON document that you see in
717718 successful Elasticsearch lookups or lookups that couldn't find the document.
tests/V5/tests.hs+7−1
@@ -1028,20 +1028,26 @@ main = hspec $ do
10281028 _ <- insertData
10291029 let firstTest = BulkTest "blah"
10301030 let secondTest = BulkTest "bloo"
1031+ let thirdTest = BulkTest "graffle"
10311032 let firstDoc = BulkIndex testIndex
10321033 testMapping (DocId "2") (toJSON firstTest)
10331034 let secondDoc = BulkCreate testIndex
10341035 testMapping (DocId "3") (toJSON secondTest)
1035− let stream = V.fromList [firstDoc, secondDoc]
1036+ let thirdDoc = BulkCreateEncoding testIndex
1037+ testMapping (DocId "4") (toEncoding thirdTest)
1038+ let stream = V.fromList [firstDoc, secondDoc, thirdDoc]
10361039 _ <- bulk stream
10371040 _ <- refreshIndex testIndex
10381041 fDoc <- getDocument testIndex testMapping (DocId "2")
10391042 sDoc <- getDocument testIndex testMapping (DocId "3")
1043+ tDoc <- getDocument testIndex testMapping (DocId "4")
10401044 let maybeFirst = eitherDecode $ responseBody fDoc :: Either String (EsResult BulkTest)
10411045 let maybeSecond = eitherDecode $ responseBody sDoc :: Either String (EsResult BulkTest)
1046+ let maybeThird = eitherDecode $ responseBody tDoc :: Either String (EsResult BulkTest)
10421047 liftIO $ do
10431048 fmap getSource maybeFirst `shouldBe` Right (Just firstTest)
10441049 fmap getSource maybeSecond `shouldBe` Right (Just secondTest)
1050+ fmap getSource maybeThird `shouldBe` Right (Just thirdTest)
10451051
10461052
10471053 describe "query API" $ do