@@ -116,6 +116,20 @@ instance FromJSON Tweet
116instance ToJSON Location
116instance ToJSON Location
117instance FromJSON Location
117instance FromJSON Location
119+data ParentMapping = ParentMapping deriving (Eq, Show)
121+instance ToJSON ParentMapping where
122+ toJSON ParentMapping =
123+ object ["parent" .= Null ]
125+data ChildMapping = ChildMapping deriving (Eq, Show)
127+instance ToJSON ChildMapping where
128+ toJSON ChildMapping =
130+ object ["_parent" .= object ["type" .= ("parent" :: Text)]]
119data TweetMapping = TweetMapping deriving (Eq, Show)
133data TweetMapping = TweetMapping deriving (Eq, Show)
121instance ToJSON TweetMapping where
135instance ToJSON TweetMapping where
@@ -330,6 +344,18 @@ main = hspec $ do
330 res' <- insertData' cfg
344 res' <- insertData' cfg
331 liftIO $ isVersionConflict res' `shouldBe` True
345 liftIO $ isVersionConflict res' `shouldBe` True
347+ it "indexes two documents in a parent/child relationship and checks that the child exists" $ withTestEnv $ do
349+ _ <- putMapping testIndex (MappingName "parent") ParentMapping
350+ _ <- putMapping testIndex (MappingName "child") ChildMapping
351+ _ <- indexDocument testIndex (MappingName "parent") defaultIndexDocumentSettings exampleTweet (DocId "1")
352+ let parent = (Just . DocumentParent . DocId) "1"
353+ ids = IndexDocumentSettings NoVersionControl parent
354+ _ <- indexDocument testIndex (MappingName "child") ids otherTweet (DocId "2")
355+ _ <- refreshIndex testIndex
356+ exists <- documentExists testIndex (MappingName "child") parent (DocId "2")
357+ liftIO $ exists `shouldBe` True
333 describe "template API" $ do
359 describe "template API" $ do
334 it "can create a template" $ withTestEnv $ do
360 it "can create a template" $ withTestEnv $ do
335 let idxTpl = IndexTemplate (TemplatePattern "tweet-*") (Just (IndexSettings (ShardCount 1) (ReplicaCount 1))) [toJSON TweetMapping]
361 let idxTpl = IndexTemplate (TemplatePattern "tweet-*") (Just (IndexSettings (ShardCount 1) (ReplicaCount 1))) [toJSON TweetMapping]