@@ -116,6 +116,20 @@ instance FromJSON Tweet
116116instance ToJSON Location
117117instance FromJSON Location
118118
119+data ParentMapping = ParentMapping deriving (Eq, Show)
120+
121+instance ToJSON ParentMapping where
122+ toJSON ParentMapping =
123+ object ["parent" .= Null ]
124+
125+data ChildMapping = ChildMapping deriving (Eq, Show)
126+
127+instance ToJSON ChildMapping where
128+ toJSON ChildMapping =
129+ object ["child" .=
130+ object ["_parent" .= object ["type" .= ("parent" :: Text)]]
131+ ]
132+
119133data TweetMapping = TweetMapping deriving (Eq, Show)
120134
121135instance ToJSON TweetMapping where
@@ -173,11 +187,17 @@ insertOther = do
173187 _ <- refreshIndex testIndex
174188 return ()
175189
190+insertWithSpaceInId :: BH IO ()
191+insertWithSpaceInId = do
192+ _ <- indexDocument testIndex testMapping defaultIndexDocumentSettings exampleTweet (DocId "Hello World")
193+ _ <- refreshIndex testIndex
194+ return ()
195+
176196searchTweet :: Search -> BH IO (Either String Tweet)
177197searchTweet search = do
178198 result <- searchTweets search
179199 let myTweet = fmap (hitSource . head . hits . searchHits) result
180− return myTweet
200+ return (either (Left "myTweet was Nothing") id myTweet)
181201
182202searchTweets :: Search -> BH IO (Either String (SearchResult Tweet))
183203searchTweets search = eitherDecode . responseBody <$> searchByIndex testIndex search
@@ -228,6 +248,7 @@ searchExpectSource src expected = do
228248 reply <- searchAll search
229249 let result = eitherDecode (responseBody reply) :: Either String (SearchResult Value)
230250 let value = fmap (hitSource . head . hits . searchHits) result
251+ liftIO (print value)
231252 liftIO $
232253 value `shouldBe` expected
233254
@@ -315,6 +336,13 @@ main = hspec $ do
315336 (responseBody docInserted) :: Either String (EsResult Tweet)
316337 liftIO $ (fmap getSource newTweet `shouldBe` Right (Just exampleTweet))
317338
339+ it "indexes, gets, and then deletes the generated document with a DocId containing a space" $ withTestEnv $ do
340+ _ <- insertWithSpaceInId
341+ docInserted <- getDocument testIndex testMapping (DocId "Hello World")
342+ let newTweet = eitherDecode
343+ (responseBody docInserted) :: Either String (EsResult Tweet)
344+ liftIO $ (fmap getSource newTweet `shouldBe` Right (Just exampleTweet))
345+
318346 it "produces a parseable result when looking up a bogus document" $ withTestEnv $ do
319347 doc <- getDocument testIndex testMapping (DocId "bogus")
320348 let noTweet = eitherDecode
@@ -330,6 +358,18 @@ main = hspec $ do
330358 res' <- insertData' cfg
331359 liftIO $ isVersionConflict res' `shouldBe` True
332360
361+ it "indexes two documents in a parent/child relationship and checks that the child exists" $ withTestEnv $ do
362+ resetIndex
363+ _ <- putMapping testIndex (MappingName "parent") ParentMapping
364+ _ <- putMapping testIndex (MappingName "child") ChildMapping
365+ _ <- indexDocument testIndex (MappingName "parent") defaultIndexDocumentSettings exampleTweet (DocId "1")
366+ let parent = (Just . DocumentParent . DocId) "1"
367+ ids = IndexDocumentSettings NoVersionControl parent
368+ _ <- indexDocument testIndex (MappingName "child") ids otherTweet (DocId "2")
369+ _ <- refreshIndex testIndex
370+ exists <- documentExists testIndex (MappingName "child") parent (DocId "2")
371+ liftIO $ exists `shouldBe` True
372+
333373 describe "template API" $ do
334374 it "can create a template" $ withTestEnv $ do
335375 let idxTpl = IndexTemplate (TemplatePattern "tweet-*") (Just (IndexSettings (ShardCount 1) (ReplicaCount 1))) [toJSON TweetMapping]
@@ -808,6 +848,6 @@ main = hspec $ do
808848 scan_search' <- scanSearch testIndex testMapping search :: BH IO [Hit Tweet]
809849 let scan_search = map hitSource scan_search'
810850 liftIO $
811− regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
851+ regular_search `shouldBe` Right exampleTweet -- Check that the size restrtiction is being honored
812852 liftIO $
813853 scan_search `shouldMatchList` [exampleTweet, otherTweet]