mirror of
https://github.com/typeable/bloodhound.git
synced 2024-09-11 08:25:32 +03:00
Merge pull request #201 from andrewthad/bulk_create_encoding
bulk create encoding
This commit is contained in:
commit
ac096ce023
@ -892,6 +892,12 @@ encodeBulkOperation (BulkUpdate (IndexName indexName)
|
||||
doc = object ["doc" .= value]
|
||||
blob = encode metadata `mappend` "\n" `mappend` encode doc
|
||||
|
||||
encodeBulkOperation (BulkCreateEncoding (IndexName indexName)
|
||||
(MappingName mappingName)
|
||||
(DocId docId) encoding) = toLazyByteString blob
|
||||
where metadata = toEncoding (mkBulkStreamValue "create" indexName mappingName docId)
|
||||
blob = fromEncoding metadata <> "\n" <> fromEncoding encoding
|
||||
|
||||
-- | 'getDocument' is a straight-forward way to fetch a single document from
|
||||
-- Elasticsearch using a 'Server', 'IndexName', 'MappingName', and a 'DocId'.
|
||||
-- The 'DocId' is the primary key for your Elasticsearch document.
|
||||
|
@ -710,8 +710,9 @@ data Mapping = Mapping { typeName :: TypeName
|
||||
data BulkOperation =
|
||||
BulkIndex IndexName MappingName DocId Value
|
||||
| BulkCreate IndexName MappingName DocId Value
|
||||
| BulkCreateEncoding IndexName MappingName DocId Encoding
|
||||
| BulkDelete IndexName MappingName DocId
|
||||
| BulkUpdate IndexName MappingName DocId Value deriving (Eq, Read, Show, Generic, Typeable)
|
||||
| BulkUpdate IndexName MappingName DocId Value deriving (Eq, Show, Generic, Typeable)
|
||||
|
||||
{-| 'EsResult' describes the standard wrapper JSON document that you see in
|
||||
successful Elasticsearch lookups or lookups that couldn't find the document.
|
||||
|
@ -1028,20 +1028,26 @@ main = hspec $ do
|
||||
_ <- insertData
|
||||
let firstTest = BulkTest "blah"
|
||||
let secondTest = BulkTest "bloo"
|
||||
let thirdTest = BulkTest "graffle"
|
||||
let firstDoc = BulkIndex testIndex
|
||||
testMapping (DocId "2") (toJSON firstTest)
|
||||
let secondDoc = BulkCreate testIndex
|
||||
testMapping (DocId "3") (toJSON secondTest)
|
||||
let stream = V.fromList [firstDoc, secondDoc]
|
||||
let thirdDoc = BulkCreateEncoding testIndex
|
||||
testMapping (DocId "4") (toEncoding thirdTest)
|
||||
let stream = V.fromList [firstDoc, secondDoc, thirdDoc]
|
||||
_ <- bulk stream
|
||||
_ <- refreshIndex testIndex
|
||||
fDoc <- getDocument testIndex testMapping (DocId "2")
|
||||
sDoc <- getDocument testIndex testMapping (DocId "3")
|
||||
tDoc <- getDocument testIndex testMapping (DocId "4")
|
||||
let maybeFirst = eitherDecode $ responseBody fDoc :: Either String (EsResult BulkTest)
|
||||
let maybeSecond = eitherDecode $ responseBody sDoc :: Either String (EsResult BulkTest)
|
||||
let maybeThird = eitherDecode $ responseBody tDoc :: Either String (EsResult BulkTest)
|
||||
liftIO $ do
|
||||
fmap getSource maybeFirst `shouldBe` Right (Just firstTest)
|
||||
fmap getSource maybeSecond `shouldBe` Right (Just secondTest)
|
||||
fmap getSource maybeThird `shouldBe` Right (Just thirdTest)
|
||||
|
||||
|
||||
describe "query API" $ do
|
||||
|
Loading…
Reference in New Issue
Block a user