git.iko.soy/typeable/bloodhound
on 28386b0 help sign in
173 lines 7.4 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
3module Test.Indices where
5import Test.Common
6import Test.Import
8import qualified Data.List as L
9import qualified Data.List.NonEmpty as NE
10import qualified Data.Map as M
11spec :: Spec
12spec = do
13 describe "Index create/delete API" $ do
14 it "creates and then deletes the requested index" $ withTestEnv $ do
15 -- priming state.
16 _ <- deleteExampleIndex
17 resp <- createExampleIndex
18 deleteResp <- deleteExampleIndex
19 liftIO $ do
20 validateStatus resp 200
21 validateStatus deleteResp 200
23 describe "Index aliases" $ do
24 let aname = IndexAliasName (IndexName "bloodhound-tests-twitter-1-alias")
25 let alias = IndexAlias (testIndex) aname
26 let create = IndexAliasCreate Nothing Nothing
27 let action = AddAlias alias create
28 it "handles the simple case of aliasing an existing index" $ do
29 withTestEnv $ do
30 resetIndex
31 resp <- updateIndexAliases (action :| [])
32 liftIO $ validateStatus resp 200
33 let cleanup = withTestEnv (updateIndexAliases (RemoveAlias alias :| []))
34 (do aliases <- withTestEnv getIndexAliases
35 let expected = IndexAliasSummary alias create
36 case aliases of
37 Right (IndexAliasesSummary summs) ->
38 L.find ((== alias) . indexAliasSummaryAlias) summs `shouldBe` Just expected
39 Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)) `finally` cleanup
40 it "allows alias deletion" $ do
41 aliases <- withTestEnv $ do
42 resetIndex
43 resp <- updateIndexAliases (action :| [])
44 liftIO $ validateStatus resp 200
45 _ <- deleteIndexAlias aname
46 getIndexAliases
47 -- let expected = IndexAliasSummary alias create
48 case aliases of
49 Right (IndexAliasesSummary summs) ->
50 L.find ( (== aname)
51 . indexAlias
52 . indexAliasSummaryAlias
53 ) summs
54 `shouldBe` Nothing
55 Left e -> expectationFailure ("Expected an IndexAliasesSummary but got " <> show e)
57 describe "Index Listing" $ do
58 it "returns a list of index names" $ withTestEnv $ do
59 _ <- createExampleIndex
60 ixns <- listIndices
61 liftIO (ixns `shouldContain` [testIndex])
63 describe "Index Settings" $ do
64 it "persists settings" $ withTestEnv $ do
65 _ <- deleteExampleIndex
66 _ <- createExampleIndex
67 let updates = BlocksWrite False :| []
68 updateResp <- updateIndexSettings updates testIndex
69 liftIO $ validateStatus updateResp 200
70 getResp <- getIndexSettings testIndex
71 liftIO $
72 getResp `shouldBe` Right (IndexSettingsSummary
73 testIndex
74 (IndexSettings (ShardCount 1) (ReplicaCount 0))
75 (NE.toList updates))
77 it "allows total fields to be set" $ when' (atleast es50) $ withTestEnv $ do
78 _ <- deleteExampleIndex
79 _ <- createExampleIndex
80 let updates = MappingTotalFieldsLimit 2500 :| []
81 updateResp <- updateIndexSettings updates testIndex
82 liftIO $ validateStatus updateResp 200
83 getResp <- getIndexSettings testIndex
84 liftIO $
85 getResp `shouldBe` Right (IndexSettingsSummary
86 testIndex
87 (IndexSettings (ShardCount 1) (ReplicaCount 0))
88 (NE.toList updates))
90 it "accepts customer analyzers" $ when' (atleast es50) $ withTestEnv $ do
91 _ <- deleteExampleIndex
92 let analysis = Analysis
93 (M.singleton "ex_analyzer"
94 ( AnalyzerDefinition
95 (Just (Tokenizer "ex_tokenizer"))
96 (map TokenFilter
97 [ "ex_filter_lowercase","ex_filter_uppercase","ex_filter_apostrophe"
98 , "ex_filter_reverse","ex_filter_snowball"
99 , "ex_filter_shingle"
100 ]
101 )
102 (map CharFilter
103 ["html_strip", "ex_mapping", "ex_pattern_replace"]
104 )
105 )
106 )
107 (M.singleton "ex_tokenizer"
108 ( TokenizerDefinitionNgram
109 ( Ngram 3 4 [TokenLetter,TokenDigit])
110 )
111 )
112 (M.fromList
113 [ ("ex_filter_lowercase",TokenFilterDefinitionLowercase (Just Greek))
114 , ("ex_filter_uppercase",TokenFilterDefinitionUppercase Nothing)
115 , ("ex_filter_apostrophe",TokenFilterDefinitionApostrophe)
116 , ("ex_filter_reverse",TokenFilterDefinitionReverse)
117 , ("ex_filter_snowball",TokenFilterDefinitionSnowball English)
118 , ("ex_filter_shingle",TokenFilterDefinitionShingle (Shingle 3 3 True False " " "_"))
119 , ("ex_filter_stemmer",TokenFilterDefinitionStemmer German)
120 , ("ex_filter_stop1", TokenFilterDefinitionStop (Left French))
121 , ("ex_filter_stop2",
122 TokenFilterDefinitionStop
123 (Right
124 $ map StopWord ["a", "is", "the"]))
125 ]
126 )
127 (M.fromList
128 [ ("ex_mapping", CharFilterDefinitionMapping (M.singleton "١" "1"))
129 , ("ex_pattern_replace", CharFilterDefinitionPatternReplace "(\\d+)-(?=\\d)" "$1_" Nothing)
130 ]
131 )
132 updates = [AnalysisSetting analysis]
133 createResp <- createIndexWith (updates ++ [NumberOfReplicas (ReplicaCount 0)]) 1 testIndex
134 liftIO $ validateStatus createResp 200
135 getResp <- getIndexSettings testIndex
136 liftIO $
137 getResp `shouldBe` Right (IndexSettingsSummary
138 testIndex
139 (IndexSettings (ShardCount 1) (ReplicaCount 0))
140 updates
141 )
143 it "accepts default compression codec" $ when' (atleast es50) $ withTestEnv $ do
144 _ <- deleteExampleIndex
145 let updates = [CompressionSetting CompressionDefault]
146 createResp <- createIndexWith (updates ++ [NumberOfReplicas (ReplicaCount 0)]) 1 testIndex
147 liftIO $ validateStatus createResp 200
148 getResp <- getIndexSettings testIndex
149 liftIO $ getResp `shouldBe` Right
150 (IndexSettingsSummary testIndex (IndexSettings (ShardCount 1) (ReplicaCount 0)) updates)
152 it "accepts best compression codec" $ when' (atleast es50) $ withTestEnv $ do
153 _ <- deleteExampleIndex
154 let updates = [CompressionSetting CompressionBest]
155 createResp <- createIndexWith (updates ++ [NumberOfReplicas (ReplicaCount 0)]) 1 testIndex
156 liftIO $ validateStatus createResp 200
157 getResp <- getIndexSettings testIndex
158 liftIO $ getResp `shouldBe` Right
159 (IndexSettingsSummary testIndex (IndexSettings (ShardCount 1) (ReplicaCount 0)) updates)
162 describe "Index Optimization" $ do
163 it "returns a successful response upon completion" $ withTestEnv $ do
164 _ <- createExampleIndex
165 resp <- forceMergeIndex (IndexList (testIndex :| [])) defaultForceMergeIndexSettings
166 liftIO $ validateStatus resp 200
169 describe "Index flushing" $ do
170 it "returns a successful response upon flushing" $ withTestEnv $ do
171 _ <- createExampleIndex
172 resp <- flushIndex testIndex
173 liftIO $ validateStatus resp 200