git.iko.soy/typeable/bloodhound
on master help sign in
Merge branch 'master' into directGenerators
624b07bJosh Berman
src/Database/V5/Bloodhound/Client.hs+27−2
@@ -25,6 +25,7 @@ module Database.V5.Bloodhound.Client
25 withBH
25 withBH
26 -- ** Indices
26 -- ** Indices
27 , createIndex
27 , createIndex
28+ , createIndexWith
28 , deleteIndex
29 , deleteIndex
29 , updateIndexSettings
30 , updateIndexSettings
30 , getIndexSettings
31 , getIndexSettings
@@ -512,6 +513,28 @@ createIndex indexSettings (IndexName indexName) =
512 where url = joinPath [indexName]
513 where url = joinPath [indexName]
513 body = Just $ encode indexSettings
514 body = Just $ encode indexSettings
514
515
516+-- | Create an index, providing it with any number of settings. This
517+-- is more expressive than 'createIndex' but makes is more verbose
518+-- for the common case of configuring only the shard count and
519+-- replica count.
520+createIndexWith :: MonadBH m
521+ => [UpdatableIndexSetting]
522+ -> Int -- ^ shard count
523+ -> IndexName
524+ -> m Reply
525+createIndexWith updates shards (IndexName indexName) =
526+ bindM2 put url (return (Just body))
527+ where url = joinPath [indexName]
528+ body = encode $ object
529+ ["settings" .= deepMerge
530+ ( HM.singleton "index.number_of_shards" (toJSON shards) :
531+ [u | Object u <- toJSON <$> updates]
532+ )
533+ ]
534+
535+oPath :: ToJSON a => NonEmpty Text -> a -> Value
536+oPath (k :| []) v = object [k .= v]
537+oPath (k:| (h:t)) v = object [k .= oPath (h :| t) v]
515
538
516-- | 'deleteIndex' will delete an index given a 'Server', and an 'IndexName'.
539-- | 'deleteIndex' will delete an index given a 'Server', and an 'IndexName'.
517--
540--
@@ -545,7 +568,6 @@ getIndexSettings (IndexName indexName) = do
545 parseEsResponse =<< get =<< url
568 parseEsResponse =<< get =<< url
546 where url = joinPath [indexName, "_settings"]
569 where url = joinPath [indexName, "_settings"]
547
570
548−
549-- | 'forceMergeIndex'
571-- | 'forceMergeIndex'
550--
572--
551-- The force merge API allows to force merging of one or more indices through
573-- The force merge API allows to force merging of one or more indices through
@@ -787,7 +809,10 @@ versionCtlParams cfg =
787-- | 'indexDocument' is the primary way to save a single document in
809-- | 'indexDocument' is the primary way to save a single document in
788-- Elasticsearch. The document itself is simply something we can
810-- Elasticsearch. The document itself is simply something we can
789-- convert into a JSON 'Value'. The 'DocId' will function as the
811-- convert into a JSON 'Value'. The 'DocId' will function as the
790−-- primary key for the document.
812+-- primary key for the document. You are encouraged to generate
813+-- your own id's and not rely on ElasticSearch's automatic id
814+-- generation. Read more about it here:
815+-- https://github.com/bitemyapp/bloodhound/issues/107
791--
816--
792-- >>> resp <- runBH' $ indexDocument testIndex testMapping defaultIndexDocumentSettings exampleTweet (DocId "1")
817-- >>> resp <- runBH' $ indexDocument testIndex testMapping defaultIndexDocumentSettings exampleTweet (DocId "1")
793-- >>> print resp
818-- >>> print resp
src/Database/V5/Bloodhound/Types.hs+133−5
@@ -74,6 +74,7 @@ module Database.V5.Bloodhound.Types
74 , UpdatableIndexSetting(..)
74 , UpdatableIndexSetting(..)
75 , IndexSettingsSummary(..)
75 , IndexSettingsSummary(..)
76 , AllocationPolicy(..)
76 , AllocationPolicy(..)
77+ , Compression(..)
77 , ReplicaBounds(..)
78 , ReplicaBounds(..)
78 , Bytes(..)
79 , Bytes(..)
79 , gigabytes
80 , gigabytes
@@ -202,6 +203,7 @@ module Database.V5.Bloodhound.Types
202 , ZeroTermsQuery(..)
203 , ZeroTermsQuery(..)
203 , CutoffFrequency(..)
204 , CutoffFrequency(..)
204 , Analyzer(..)
205 , Analyzer(..)
206+ , Tokenizer(..)
205 , MaxExpansions(..)
207 , MaxExpansions(..)
206 , Lenient(..)
208 , Lenient(..)
207 , MatchQueryType(..)
209 , MatchQueryType(..)
@@ -376,6 +378,12 @@ module Database.V5.Bloodhound.Types
376
378
377 , EsUsername(..)
379 , EsUsername(..)
378 , EsPassword(..)
380 , EsPassword(..)
381+
382+ , Analysis(..)
383+ , AnalyzerDefinition(..)
384+ , TokenizerDefinition(..)
385+ , Ngram(..)
386+ , TokenChar(..)
379 ) where
387 ) where
380
388
381import Control.Applicative as A
389import Control.Applicative as A
@@ -579,12 +587,94 @@ data UpdatableIndexSetting = NumberOfReplicas ReplicaCount
579 | TTLDisablePurge Bool
587 | TTLDisablePurge Bool
580 -- ^ Disables temporarily the purge of expired docs.
588 -- ^ Disables temporarily the purge of expired docs.
581 | TranslogFSType FSType
589 | TranslogFSType FSType
590+ | CompressionSetting Compression
582 | IndexCompoundFormat CompoundFormat
591 | IndexCompoundFormat CompoundFormat
583 | IndexCompoundOnFlush Bool
592 | IndexCompoundOnFlush Bool
584 | WarmerEnabled Bool
593 | WarmerEnabled Bool
585 | MappingTotalFieldsLimit Int
594 | MappingTotalFieldsLimit Int
595+ | AnalysisSetting Analysis
596+ -- ^ Analysis is not a dynamic setting and can only be performed on a closed index.
586 deriving (Eq, Show, Generic, Typeable)
597 deriving (Eq, Show, Generic, Typeable)
587
598
599+data Analysis = Analysis
600+ { analysisAnalyzer :: M.Map Text AnalyzerDefinition
601+ , analysisTokenizer :: M.Map Text TokenizerDefinition
602+ } deriving (Eq,Show,Generic,Typeable)
603+
604+instance ToJSON Analysis where
605+ toJSON (Analysis analyzer tokenizer) = object
606+ [ "analyzer" .= analyzer
607+ , "tokenizer" .= tokenizer
608+ ]
609+
610+instance FromJSON Analysis where
611+ parseJSON = withObject "Analysis" $ \m -> Analysis
612+ <$> m .: "analyzer"
613+ <*> m .: "tokenizer"
614+
615+data AnalyzerDefinition = AnalyzerDefinition
616+ { analyzerDefinitionTokenizer :: Maybe Tokenizer
617+ } deriving (Eq,Show,Generic,Typeable)
618+
619+instance ToJSON AnalyzerDefinition where
620+ toJSON (AnalyzerDefinition tokenizer) = object $ catMaybes
621+ [ fmap ("tokenizer" .=) tokenizer
622+ ]
623+
624+instance FromJSON AnalyzerDefinition where
625+ parseJSON = withObject "AnalyzerDefinition" $ \m -> AnalyzerDefinition
626+ <$> m .:? "tokenizer"
627+
628+
629+data TokenizerDefinition
630+ = TokenizerDefinitionNgram Ngram
631+ deriving (Eq,Show,Generic,Typeable)
632+
633+instance ToJSON TokenizerDefinition where
634+ toJSON x = case x of
635+ TokenizerDefinitionNgram (Ngram minGram maxGram tokenChars) -> object
636+ [ "type" .= ("ngram" :: Text)
637+ , "min_gram" .= minGram
638+ , "max_gram" .= maxGram
639+ , "token_chars" .= tokenChars
640+ ]
641+
642+instance FromJSON TokenizerDefinition where
643+ parseJSON = withObject "TokenizerDefinition" $ \m -> do
644+ typ <- m .: "type" :: Parser Text
645+ case typ of
646+ "ngram" -> fmap TokenizerDefinitionNgram $ Ngram
647+ <$> (fmap unStringlyTypedInt (m .: "min_gram"))
648+ <*> (fmap unStringlyTypedInt (m .: "max_gram"))
649+ <*> m .: "token_chars"
650+ _ -> fail "invalid TokenizerDefinition"
651+
652+data Ngram = Ngram
653+ { ngramMinGram :: Int
654+ , ngramMaxGram :: Int
655+ , ngramTokenChars :: [TokenChar]
656+ } deriving (Eq,Show,Generic,Typeable)
657+
658+data TokenChar = TokenLetter | TokenDigit | TokenWhitespace | TokenPunctuation | TokenSymbol
659+ deriving (Eq,Read,Show,Generic,Typeable)
660+
661+instance ToJSON TokenChar where
662+ toJSON t = String $ case t of
663+ TokenLetter -> "letter"
664+ TokenDigit -> "digit"
665+ TokenWhitespace -> "whitespace"
666+ TokenPunctuation -> "punctuation"
667+ TokenSymbol -> "symbol"
668+
669+instance FromJSON TokenChar where
670+ parseJSON = withText "TokenChar" $ \t -> case t of
671+ "letter" -> return TokenLetter
672+ "digit" -> return TokenDigit
673+ "whitespace" -> return TokenWhitespace
674+ "punctuation" -> return TokenPunctuation
675+ "symbol" -> return TokenSymbol
676+ _ -> fail "invalid TokenChar"
677+
588data AllocationPolicy = AllocAll
678data AllocationPolicy = AllocAll
589 -- ^ Allows shard allocation for all shards.
679 -- ^ Allows shard allocation for all shards.
590 | AllocPrimaries
680 | AllocPrimaries
@@ -600,6 +690,26 @@ data ReplicaBounds = ReplicasBounded Int Int
600 | ReplicasUnbounded
690 | ReplicasUnbounded
601 deriving (Eq, Read, Show, Generic, Typeable)
691 deriving (Eq, Read, Show, Generic, Typeable)
602
692
693+data Compression
694+ = CompressionDefault
695+ -- ^ Compress with LZ4
696+ | CompressionBest
697+ -- ^ Compress with DEFLATE. Elastic
698+ -- <https://www.elastic.co/blog/elasticsearch-storage-the-true-story-2.0 blogs>
699+ -- that this can reduce disk use by 15%-25%.
700+ deriving (Eq,Show,Generic,Typeable)
701+
702+instance ToJSON Compression where
703+ toJSON x = case x of
704+ CompressionDefault -> toJSON ("default" :: Text)
705+ CompressionBest -> toJSON ("best_compression" :: Text)
706+
707+instance FromJSON Compression where
708+ parseJSON = withText "Compression" $ \t -> case t of
709+ "default" -> return CompressionDefault
710+ "best_compression" -> return CompressionBest
711+ _ -> fail "invalid compression codec"
712+
603-- | A measure of bytes used for various configurations. You may want
713-- | A measure of bytes used for various configurations. You may want
604-- to use smart constructors like 'gigabytes' for larger values.
714-- to use smart constructors like 'gigabytes' for larger values.
605--
715--
@@ -1020,6 +1130,8 @@ newtype CutoffFrequency =
1020 CutoffFrequency Double deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1130 CutoffFrequency Double deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1021newtype Analyzer =
1131newtype Analyzer =
1022 Analyzer Text deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1132 Analyzer Text deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1133+newtype Tokenizer =
1134+ Tokenizer Text deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1023newtype MaxExpansions =
1135newtype MaxExpansions =
1024 MaxExpansions Int deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1136 MaxExpansions Int deriving (Eq, Read, Show, Generic, ToJSON, FromJSON, Typeable)
1025
1137
@@ -1438,13 +1550,15 @@ data MatchQuery =
1438 , matchQueryAnalyzer :: Maybe Analyzer
1550 , matchQueryAnalyzer :: Maybe Analyzer
1439 , matchQueryMaxExpansions :: Maybe MaxExpansions
1551 , matchQueryMaxExpansions :: Maybe MaxExpansions
1440 , matchQueryLenient :: Maybe Lenient
1552 , matchQueryLenient :: Maybe Lenient
1553+ , matchQueryBoost :: Maybe Boost
1554+ , matchQueryMinimumShouldMatch :: Maybe Text
1441− , matchQueryBoost :: Maybe Boost } deriving (Eq, Read, Show, Generic, Typeable)
1555+ } deriving (Eq, Read, Show, Generic, Typeable)
1442
1556
1443{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
1557{-| 'mkMatchQuery' is a convenience function that defaults the less common parameters,
1444 enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
1558 enabling you to provide only the 'FieldName' and 'QueryString' to make a 'MatchQuery'
1445-}
1559-}
1446mkMatchQuery :: FieldName -> QueryString -> MatchQuery
1560mkMatchQuery :: FieldName -> QueryString -> MatchQuery
1447−mkMatchQuery field query = MatchQuery field query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing
1561+mkMatchQuery field query = MatchQuery field query Or ZeroTermsNone Nothing Nothing Nothing Nothing Nothing Nothing Nothing
1448
1562
1449data MatchQueryType =
1563data MatchQueryType =
1450 MatchPhrase
1564 MatchPhrase
@@ -2834,7 +2948,9 @@ instance ToJSON MatchQuery where
2834 toJSON (MatchQuery (FieldName fieldName)
2948 toJSON (MatchQuery (FieldName fieldName)
2835 (QueryString mqQueryString) booleanOperator
2949 (QueryString mqQueryString) booleanOperator
2836 zeroTermsQuery cutoffFrequency matchQueryType
2950 zeroTermsQuery cutoffFrequency matchQueryType
2837− analyzer maxExpansions lenient boost) =
2951+ analyzer maxExpansions lenient boost
2952+ minShouldMatch
2953+ ) =
2838 object [ fieldName .= omitNulls base ]
2954 object [ fieldName .= omitNulls base ]
2839 where base = [ "query" .= mqQueryString
2955 where base = [ "query" .= mqQueryString
2840 , "operator" .= booleanOperator
2956 , "operator" .= booleanOperator
@@ -2844,7 +2960,9 @@ instance ToJSON MatchQuery where
2844 , "analyzer" .= analyzer
2960 , "analyzer" .= analyzer
2845 , "max_expansions" .= maxExpansions
2961 , "max_expansions" .= maxExpansions
2846 , "lenient" .= lenient
2962 , "lenient" .= lenient
2847− , "boost" .= boost ]
2963+ , "boost" .= boost
2964+ , "minimum_should_match" .= minShouldMatch
2965+ ]
2848
2966
2849instance FromJSON MatchQuery where
2967instance FromJSON MatchQuery where
2850 parseJSON = withObject "MatchQuery" parse
2968 parseJSON = withObject "MatchQuery" parse
@@ -2859,6 +2977,7 @@ instance FromJSON MatchQuery where
2859 <*> o .:? "max_expansions"
2977 <*> o .:? "max_expansions"
2860 <*> o .:? "lenient"
2978 <*> o .:? "lenient"
2861 <*> o .:? "boost"
2979 <*> o .:? "boost"
2980+ <*> o .:? "minimum_should_match"
2862
2981
2863instance ToJSON MultiMatchQuery where
2982instance ToJSON MultiMatchQuery where
2864 toJSON (MultiMatchQuery fields (QueryString query) boolOp
2983 toJSON (MultiMatchQuery fields (QueryString query) boolOp
@@ -2982,6 +3101,7 @@ instance ToJSON UpdatableIndexSetting where
2982 toJSON (GCDeletes x) = oPath ("index" :| ["gc_deletes"]) (NominalDiffTimeJSON x)
3101 toJSON (GCDeletes x) = oPath ("index" :| ["gc_deletes"]) (NominalDiffTimeJSON x)
2983 toJSON (TTLDisablePurge x) = oPath ("index" :| ["ttl", "disable_purge"]) x
3102 toJSON (TTLDisablePurge x) = oPath ("index" :| ["ttl", "disable_purge"]) x
2984 toJSON (TranslogFSType x) = oPath ("index" :| ["translog", "fs", "type"]) x
3103 toJSON (TranslogFSType x) = oPath ("index" :| ["translog", "fs", "type"]) x
3104+ toJSON (CompressionSetting x) = oPath ("index" :| ["codec"]) x
2985 toJSON (IndexCompoundFormat x) = oPath ("index" :| ["compound_format"]) x
3105 toJSON (IndexCompoundFormat x) = oPath ("index" :| ["compound_format"]) x
2986 toJSON (IndexCompoundOnFlush x) = oPath ("index" :| ["compound_on_flush"]) x
3106 toJSON (IndexCompoundOnFlush x) = oPath ("index" :| ["compound_on_flush"]) x
2987 toJSON (WarmerEnabled x) = oPath ("index" :| ["warmer", "enabled"]) x
3107 toJSON (WarmerEnabled x) = oPath ("index" :| ["warmer", "enabled"]) x
@@ -2990,6 +3110,7 @@ instance ToJSON UpdatableIndexSetting where
2990 toJSON (BlocksWrite x) = oPath ("blocks" :| ["write"]) x
3110 toJSON (BlocksWrite x) = oPath ("blocks" :| ["write"]) x
2991 toJSON (BlocksMetaData x) = oPath ("blocks" :| ["metadata"]) x
3111 toJSON (BlocksMetaData x) = oPath ("blocks" :| ["metadata"]) x
2992 toJSON (MappingTotalFieldsLimit x) = oPath ("index" :| ["mapping","total_fields","limit"]) x
3112 toJSON (MappingTotalFieldsLimit x) = oPath ("index" :| ["mapping","total_fields","limit"]) x
3113+ toJSON (AnalysisSetting x) = oPath ("index" :| ["analysis"]) x
2993
3114
2994instance FromJSON UpdatableIndexSetting where
3115instance FromJSON UpdatableIndexSetting where
2995 parseJSON = withObject "UpdatableIndexSetting" parse
3116 parseJSON = withObject "UpdatableIndexSetting" parse
@@ -3014,6 +3135,7 @@ instance FromJSON UpdatableIndexSetting where
3014 <|> gcDeletes `taggedAt` ["index", "gc_deletes"]
3135 <|> gcDeletes `taggedAt` ["index", "gc_deletes"]
3015 <|> ttlDisablePurge `taggedAt` ["index", "ttl", "disable_purge"]
3136 <|> ttlDisablePurge `taggedAt` ["index", "ttl", "disable_purge"]
3016 <|> translogFSType `taggedAt` ["index", "translog", "fs", "type"]
3137 <|> translogFSType `taggedAt` ["index", "translog", "fs", "type"]
3138+ <|> compressionSetting `taggedAt` ["index", "codec"]
3017 <|> compoundFormat `taggedAt` ["index", "compound_format"]
3139 <|> compoundFormat `taggedAt` ["index", "compound_format"]
3018 <|> compoundOnFlush `taggedAt` ["index", "compound_on_flush"]
3140 <|> compoundOnFlush `taggedAt` ["index", "compound_on_flush"]
3019 <|> warmerEnabled `taggedAt` ["index", "warmer", "enabled"]
3141 <|> warmerEnabled `taggedAt` ["index", "warmer", "enabled"]
@@ -3022,6 +3144,7 @@ instance FromJSON UpdatableIndexSetting where
3022 <|> blocksWrite `taggedAt` ["blocks", "write"]
3144 <|> blocksWrite `taggedAt` ["blocks", "write"]
3023 <|> blocksMetaData `taggedAt` ["blocks", "metadata"]
3145 <|> blocksMetaData `taggedAt` ["blocks", "metadata"]
3024 <|> mappingTotalFieldsLimit `taggedAt` ["index", "mapping", "total_fields", "limit"]
3146 <|> mappingTotalFieldsLimit `taggedAt` ["index", "mapping", "total_fields", "limit"]
3147+ <|> analysisSetting `taggedAt` ["index", "analysis"]
3025 where taggedAt f ks = taggedAt' f (Object o) ks
3148 where taggedAt f ks = taggedAt' f (Object o) ks
3026 taggedAt' f v [] = f =<< (parseJSON v <|> (parseJSON (unStringlyTypeJSON v)))
3149 taggedAt' f v [] = f =<< (parseJSON v <|> (parseJSON (unStringlyTypeJSON v)))
3027 taggedAt' f v (k:ks) = withObject "Object" (\o -> do v' <- o .: k
3150 taggedAt' f v (k:ks) = withObject "Object" (\o -> do v' <- o .: k
@@ -3047,6 +3170,7 @@ instance FromJSON UpdatableIndexSetting where
3047 gcDeletes = pure . GCDeletes . ndtJSON
3170 gcDeletes = pure . GCDeletes . ndtJSON
3048 ttlDisablePurge = pure . TTLDisablePurge
3171 ttlDisablePurge = pure . TTLDisablePurge
3049 translogFSType = pure . TranslogFSType
3172 translogFSType = pure . TranslogFSType
3173+ compressionSetting = pure . CompressionSetting
3050 compoundFormat = pure . IndexCompoundFormat
3174 compoundFormat = pure . IndexCompoundFormat
3051 compoundOnFlush = pure . IndexCompoundOnFlush
3175 compoundOnFlush = pure . IndexCompoundOnFlush
3052 warmerEnabled = pure . WarmerEnabled
3176 warmerEnabled = pure . WarmerEnabled
@@ -3055,6 +3179,7 @@ instance FromJSON UpdatableIndexSetting where
3055 blocksWrite = pure . BlocksWrite
3179 blocksWrite = pure . BlocksWrite
3056 blocksMetaData = pure . BlocksMetaData
3180 blocksMetaData = pure . BlocksMetaData
3057 mappingTotalFieldsLimit = pure . MappingTotalFieldsLimit
3181 mappingTotalFieldsLimit = pure . MappingTotalFieldsLimit
3182+ analysisSetting = pure . AnalysisSetting
3058
3183
3059instance FromJSON IndexSettingsSummary where
3184instance FromJSON IndexSettingsSummary where
3060 parseJSON = withObject "IndexSettingsSummary" parse
3185 parseJSON = withObject "IndexSettingsSummary" parse
@@ -4643,10 +4768,13 @@ instance FromJSON NodeDataPathStats where
4643
4768
4644newtype StringlyTypedDouble = StringlyTypedDouble { unStringlyTypedDouble :: Double }
4769newtype StringlyTypedDouble = StringlyTypedDouble { unStringlyTypedDouble :: Double }
4645
4770
4646−
4647instance FromJSON StringlyTypedDouble where
4771instance FromJSON StringlyTypedDouble where
4648 parseJSON = fmap StringlyTypedDouble . parseJSON . unStringlyTypeJSON
4772 parseJSON = fmap StringlyTypedDouble . parseJSON . unStringlyTypeJSON
4649
4773
4774+newtype StringlyTypedInt = StringlyTypedInt { unStringlyTypedInt :: Int }
4775+
4776+instance FromJSON StringlyTypedInt where
4777+ parseJSON = fmap StringlyTypedInt . parseJSON . unStringlyTypeJSON
4650
4778
4651instance FromJSON NodeFSTotalStats where
4779instance FromJSON NodeFSTotalStats where
4652 parseJSON = withObject "NodeFSTotalStats" parse
4780 parseJSON = withObject "NodeFSTotalStats" parse
tests/V5/tests.hs+46
@@ -907,7 +907,14 @@ instance Arbitrary RegexpFlag where arbitrary = sopArbitrary; shrink = genericSh
907instance Arbitrary BoolMatch where arbitrary = sopArbitrary; shrink = genericShrink
907instance Arbitrary BoolMatch where arbitrary = sopArbitrary; shrink = genericShrink
908instance Arbitrary Term where arbitrary = sopArbitrary; shrink = genericShrink
908instance Arbitrary Term where arbitrary = sopArbitrary; shrink = genericShrink
909instance Arbitrary IndexSettings where arbitrary = sopArbitrary; shrink = genericShrink
909instance Arbitrary IndexSettings where arbitrary = sopArbitrary; shrink = genericShrink
910+instance Arbitrary TokenChar where arbitrary = sopArbitrary; shrink = genericShrink
911+instance Arbitrary Ngram where arbitrary = sopArbitrary; shrink = genericShrink
912+instance Arbitrary TokenizerDefinition where arbitrary = sopArbitrary; shrink = genericShrink
913+instance Arbitrary AnalyzerDefinition where arbitrary = sopArbitrary; shrink = genericShrink
914+instance Arbitrary Analysis where arbitrary = sopArbitrary; shrink = genericShrink
915+instance Arbitrary Tokenizer where arbitrary = sopArbitrary; shrink = genericShrink
910instance Arbitrary UpdatableIndexSetting where arbitrary = sopArbitrary; shrink = genericShrink
916instance Arbitrary UpdatableIndexSetting where arbitrary = sopArbitrary; shrink = genericShrink
917+instance Arbitrary Compression where arbitrary = sopArbitrary; shrink = genericShrink
911instance Arbitrary Bytes where arbitrary = sopArbitrary; shrink = genericShrink
918instance Arbitrary Bytes where arbitrary = sopArbitrary; shrink = genericShrink
912instance Arbitrary AllocationPolicy where arbitrary = sopArbitrary; shrink = genericShrink
919instance Arbitrary AllocationPolicy where arbitrary = sopArbitrary; shrink = genericShrink
913instance Arbitrary InitialShardCount where arbitrary = sopArbitrary; shrink = genericShrink
920instance Arbitrary InitialShardCount where arbitrary = sopArbitrary; shrink = genericShrink
@@ -1622,6 +1629,45 @@ main = hspec $ do
1622 (IndexSettings (ShardCount 1) (ReplicaCount 0))
1629 (IndexSettings (ShardCount 1) (ReplicaCount 0))
1623 (NE.toList updates))
1630 (NE.toList updates))
1624
1631
1632+ it "accepts customer analyzers" $ when' (atleast es50) $ withTestEnv $ do
1633+ _ <- deleteExampleIndex
1634+ let analysis = Analysis
1635+ (M.singleton "ex_analyzer" (AnalyzerDefinition (Just (Tokenizer "ex_tokenizer"))))
1636+ (M.singleton "ex_tokenizer"
1637+ ( TokenizerDefinitionNgram
1638+ ( Ngram 3 4 [TokenLetter,TokenDigit])
1639+ )
1640+ )
1641+ updates = [AnalysisSetting analysis]
1642+ createResp <- createIndexWith (updates ++ [NumberOfReplicas (ReplicaCount 0)]) 1 testIndex
1643+ liftIO $ validateStatus createResp 200
1644+ getResp <- getIndexSettings testIndex
1645+ liftIO $
1646+ getResp `shouldBe` Right (IndexSettingsSummary
1647+ testIndex
1648+ (IndexSettings (ShardCount 1) (ReplicaCount 0))
1649+ updates
1650+ )
1651+
1652+ it "accepts default compression codec" $ when' (atleast es50) $ withTestEnv $ do
1653+ _ <- deleteExampleIndex
1654+ let updates = [CompressionSetting CompressionDefault]
1655+ createResp <- createIndexWith (updates ++ [NumberOfReplicas (ReplicaCount 0)]) 1 testIndex
1656+ liftIO $ validateStatus createResp 200
1657+ getResp <- getIndexSettings testIndex
1658+ liftIO $ getResp `shouldBe` Right
1659+ (IndexSettingsSummary testIndex (IndexSettings (ShardCount 1) (ReplicaCount 0)) updates)
1660+
1661+ it "accepts best compression codec" $ when' (atleast es50) $ withTestEnv $ do
1662+ _ <- deleteExampleIndex
1663+ let updates = [CompressionSetting CompressionBest]
1664+ createResp <- createIndexWith (updates ++ [NumberOfReplicas (ReplicaCount 0)]) 1 testIndex
1665+ liftIO $ validateStatus createResp 200
1666+ getResp <- getIndexSettings testIndex
1667+ liftIO $ getResp `shouldBe` Right
1668+ (IndexSettingsSummary testIndex (IndexSettings (ShardCount 1) (ReplicaCount 0)) updates)
1669+
1670+
1625 describe "Index Optimization" $ do
1671 describe "Index Optimization" $ do
1626 it "returns a successful response upon completion" $ withTestEnv $ do
1672 it "returns a successful response upon completion" $ withTestEnv $ do
1627 _ <- createExampleIndex
1673 _ <- createExampleIndex