git.iko.soy/typeable/bloodhound
on master help sign in
bulk ops documentation, better bulk tests
commiteb013371b2462366bce738e4446b213a178eb131 authorChris Allen <cma@bitemyapp.com> dateThu 18 Sep 2014, 20:20 (12 years ago) parent1f6b11c
2 files changed+43−2
README.org+41 tests/tests.hs+2−2
README.org+41
@@ -273,6 +273,47 @@ Right (Tweet {user = "bitemyapp"
273273
274274#+END_SRC
275275
276+** Bulk Operations
277+
278+*** Bulk create, index
279+
280+#+BEGIN_SRC haskell
281+
282+-- don't forget the imports and derive generic setting for ghci
283+-- at the beginning of the examples.
284+
285+:{
286+-- Using the earlier Tweet datatype and exampleTweet data
287+
288+-- just changing up the data a bit.
289+let bulkTest = exampleTweet { user = "blah" }
290+let bulkTestTwo = exampleTweet { message = "woohoo!" }
291+
292+-- create only bulk operation
293+-- BulkCreate :: IndexName -> MappingName -> DocId -> Value -> BulkOperation
294+let firstOp = BulkCreate testIndex
295+ testMapping (DocId "3") (toJSON bulkTest)
296+
297+-- index operation "create or update"
298+let sndOp = BulkIndex testIndex
299+ testMapping (DocId "4") (toJSON bulkTestTwo)
300+
301+-- Some explanation, the final "Value" type that BulkIndex,
302+-- BulkCreate, and BulkUpdate accept is the actual document
303+-- data that your operation applies to. BulkDelete doesn't
304+-- take a value because it's just deleting whatever DocId
305+-- you pass.
306+
307+-- list of bulk operations
308+let stream = [firstDoc, secondDoc]
309+
310+-- Fire off the actual bulk request
311+-- bulk :: Server -> [BulkOperation] -> IO Reply
312+resp <- bulk testServer stream
313+:}
314+
315+#+END_SRC
316+
276317** Search
277318
278319*** Querying
tests/tests.hs+2−2
@@ -160,9 +160,9 @@ main = hspec $ do
160160 let firstTest = BulkTest "blah"
161161 let secondTest = BulkTest "bloo"
162162 let firstDoc = BulkIndex testIndex
163− testMapping (DocId "2") (object ["name" .= String "blah"])
163+ testMapping (DocId "2") (toJSON firstTest)
164164 let secondDoc = BulkCreate testIndex
165− testMapping (DocId "3") (object ["name" .= String "bloo"])
165+ testMapping (DocId "3") (toJSON secondTest)
166166 let stream = [firstDoc, secondDoc]
167167 _ <- bulk testServer stream
168168 _ <- refreshIndex testServer testIndex