Added a test for the script field

This commit is contained in:
Chris Allen 2018-02-08 16:42:02 -06:00
parent 23dee6617a
commit 94bf2e4835

View File

@ -1687,7 +1687,7 @@ main = hspec $ do
resetIndex
resp <- updateIndexAliases (action :| [])
liftIO $ validateStatus resp 200
deleteIndexAlias aname
_ <- deleteIndexAlias aname
getIndexAliases
-- let expected = IndexAliasSummary alias create
case aliases of
@ -1792,6 +1792,30 @@ main = hspec $ do
Left e -> liftIO $ expectationFailure ("Expected an search suggestion but got " <> show e)
Right sr -> liftIO $ (suggestOptionsText . head . suggestResponseOptions . head . nsrResponses <$> suggest sr) `shouldBe` expectedText
describe "Script" $ do
it "returns a transformed document based on the script field" $ withTestEnv $ do
_ <- insertData
let query = MatchAllQuery Nothing
sfv = toJSON $
Script
(Just (ScriptLanguage "painless"))
(Just (ScriptInline "doc['age'].value * 2"))
Nothing
Nothing
sf = ScriptFields $
HM.fromList [("test1", sfv)]
search' = mkSearch (Just query) Nothing
search = search' { scriptFields = Just sf }
resp <- searchByIndex testIndex search
parsed <- parseEsResponse resp :: BH IO (Either EsError (SearchResult Value))
case parsed of
Left e ->
liftIO $ expectationFailure ("Expected a script-transformed result but got: " <> show e)
Right sr -> do
let Just results =
hitFields (head (hits (searchHits sr)))
liftIO $ results `shouldBe` (HitFields (M.fromList [("test1", [Number 20000.0])]))
describe "Exact isomorphism JSON instances" $ do
propJSON (Proxy :: Proxy Version)
propJSON (Proxy :: Proxy IndexName)