@@ -74,6 +74,7 @@ module Database.V5.Bloodhound.Types
74 , UpdatableIndexSetting(..)
74 , UpdatableIndexSetting(..)
75 , IndexSettingsSummary(..)
75 , IndexSettingsSummary(..)
76 , AllocationPolicy(..)
76 , AllocationPolicy(..)
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(..)
205 , MaxExpansions(..)
207 , MaxExpansions(..)
206 , Lenient(..)
208 , Lenient(..)
207 , MatchQueryType(..)
209 , MatchQueryType(..)
@@ -376,6 +378,12 @@ module Database.V5.Bloodhound.Types
377 , EsUsername(..)
379 , EsUsername(..)
378 , EsPassword(..)
380 , EsPassword(..)
383+ , AnalyzerDefinition(..)
384+ , TokenizerDefinition(..)
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)
599+data Analysis = Analysis
600+ { analysisAnalyzer :: M.Map Text AnalyzerDefinition
601+ , analysisTokenizer :: M.Map Text TokenizerDefinition
602+ } deriving (Eq,Show,Generic,Typeable)
604+instance ToJSON Analysis where
605+ toJSON (Analysis analyzer tokenizer) = object
606+ [ "analyzer" .= analyzer
607+ , "tokenizer" .= tokenizer
610+instance FromJSON Analysis where
611+ parseJSON = withObject "Analysis" $ \m -> Analysis
613+ <*> m .: "tokenizer"
615+data AnalyzerDefinition = AnalyzerDefinition
616+ { analyzerDefinitionTokenizer :: Maybe Tokenizer
617+ } deriving (Eq,Show,Generic,Typeable)
619+instance ToJSON AnalyzerDefinition where
620+ toJSON (AnalyzerDefinition tokenizer) = object $ catMaybes
621+ [ fmap ("tokenizer" .=) tokenizer
624+instance FromJSON AnalyzerDefinition where
625+ parseJSON = withObject "AnalyzerDefinition" $ \m -> AnalyzerDefinition
626+ <$> m .:? "tokenizer"
629+data TokenizerDefinition
630+ = TokenizerDefinitionNgram Ngram
631+ deriving (Eq,Show,Generic,Typeable)
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
642+instance FromJSON TokenizerDefinition where
643+ parseJSON = withObject "TokenizerDefinition" $ \m -> do
644+ typ <- m .: "type" :: Parser Text
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"
653+ { ngramMinGram :: Int
654+ , ngramMaxGram :: Int
655+ , ngramTokenChars :: [TokenChar]
656+ } deriving (Eq,Show,Generic,Typeable)
658+data TokenChar = TokenLetter | TokenDigit | TokenWhitespace | TokenPunctuation | TokenSymbol
659+ deriving (Eq,Read,Show,Generic,Typeable)
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"
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"
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)
694+ = CompressionDefault
695+ -- ^ Compress with LZ4
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)
702+instance ToJSON Compression where
703+ toJSON x = case x of
704+ CompressionDefault -> toJSON ("default" :: Text)
705+ CompressionBest -> toJSON ("best_compression" :: Text)
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"
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.
@@ -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)
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)
@@ -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)
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'
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
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
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
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"
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
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
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
4644newtype StringlyTypedDouble = StringlyTypedDouble { unStringlyTypedDouble :: Double }
4769newtype StringlyTypedDouble = StringlyTypedDouble { unStringlyTypedDouble :: Double }
4647instance FromJSON StringlyTypedDouble where
4771instance FromJSON StringlyTypedDouble where
4648 parseJSON = fmap StringlyTypedDouble . parseJSON . unStringlyTypeJSON
4772 parseJSON = fmap StringlyTypedDouble . parseJSON . unStringlyTypeJSON
4774+newtype StringlyTypedInt = StringlyTypedInt { unStringlyTypedInt :: Int }
4776+instance FromJSON StringlyTypedInt where
4777+ parseJSON = fmap StringlyTypedInt . parseJSON . unStringlyTypeJSON
4651instance FromJSON NodeFSTotalStats where
4779instance FromJSON NodeFSTotalStats where
4652 parseJSON = withObject "NodeFSTotalStats" parse
4780 parseJSON = withObject "NodeFSTotalStats" parse