Class Settings
- java.lang.Object
-
- org.elasticsearch.common.settings.Settings
-
- All Implemented Interfaces:
ToXContent,ToXContentFragment
public final class Settings extends java.lang.Object implements ToXContentFragment
An immutable settings implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSettings.BuilderA builder allowing to put different settings and thenSettings.Builder.build()an immutable settings implementation.-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
-
Field Summary
Fields Modifier and Type Field Description static SettingsEMPTYstatic java.util.Set<java.lang.String>FORMAT_PARAMS-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Method Summary
Modifier and Type Method Description static Settings.Builderbuilder()Returns a builder to be used in order to build settings.booleanequals(java.lang.Object o)Settingsfilter(java.util.function.Predicate<java.lang.String> predicate)Returns a new settings object that contains all setting of the current one filtered by the given settings key predicate.static SettingsfromXContent(XContentParser parser)Parsers the generated xcontent fromtoXContent(XContentBuilder, Params)into a new Settings object.java.lang.Stringget(java.lang.String setting)Returns the setting value associated with the setting key.java.lang.Stringget(java.lang.String setting, java.lang.String defaultValue)Returns the setting value associated with the setting key.java.lang.BooleangetAsBoolean(java.lang.String setting, java.lang.Boolean defaultValue)Returns the setting value (as boolean) associated with the setting key.java.lang.BooleangetAsBooleanLenientForPreEs6Indices(Version indexVersion, java.lang.String setting, java.lang.Boolean defaultValue, DeprecationLogger deprecationLogger)Deprecated.Only used to provide automatic upgrades for pre 6.0 indices.ByteSizeValuegetAsBytesSize(java.lang.String setting, ByteSizeValue defaultValue)Returns the setting value (as size) associated with the setting key.java.lang.DoublegetAsDouble(java.lang.String setting, java.lang.Double defaultValue)Returns the setting value (as double) associated with the setting key.java.lang.FloatgetAsFloat(java.lang.String setting, java.lang.Float defaultValue)Returns the setting value (as float) associated with the setting key.java.util.Map<java.lang.String,Settings>getAsGroups()Returns group settings for the given setting prefix.java.lang.IntegergetAsInt(java.lang.String setting, java.lang.Integer defaultValue)Returns the setting value (as int) associated with the setting key.java.util.List<java.lang.String>getAsList(java.lang.String key)The values associated with a setting key as an immutable list.java.util.List<java.lang.String>getAsList(java.lang.String key, java.util.List<java.lang.String> defaultValue)The values associated with a setting key as an immutable list.java.util.List<java.lang.String>getAsList(java.lang.String key, java.util.List<java.lang.String> defaultValue, java.lang.Boolean commaDelimited)The values associated with a setting key as an immutable list.java.lang.LonggetAsLong(java.lang.String setting, java.lang.Long defaultValue)Returns the setting value (as long) associated with the setting key.ByteSizeValuegetAsMemory(java.lang.String setting, java.lang.String defaultValue)Returns the setting value (as size) associated with the setting key.SettingsgetAsSettings(java.lang.String setting)Returns the settings mapped to the given setting name.TimeValuegetAsTime(java.lang.String setting, TimeValue defaultValue)Returns the setting value (as time) associated with the setting key.VersiongetAsVersion(java.lang.String setting, Version defaultVersion)Returns a parsed version.SettingsgetByPrefix(java.lang.String prefix)A settings that are filtered (and key is removed) with the specified prefix.java.util.Map<java.lang.String,Settings>getGroups(java.lang.String settingPrefix)Returns group settings for the given setting prefix.java.util.Map<java.lang.String,Settings>getGroups(java.lang.String settingPrefix, boolean ignoreNonGrouped)Returns group settings for the given setting prefix.inthashCode()booleanhasValue(java.lang.String key)Returnstrueiff the given key has a value in this settings objectbooleanisEmpty()Returnstrueif this settings object contains no settingsjava.util.Set<java.lang.String>keySet()Returns the fully qualified setting names contained in this settings object.java.util.Set<java.lang.String>names()static SettingsreadSettingsFromStream(StreamInput in)intsize()Returns the number of settings in this settings object.java.lang.StringtoDelimitedString(char delimiter)Returns the settings as delimited string.java.lang.StringtoString()XContentBuildertoXContent(XContentBuilder builder, ToXContent.Params params)static voidwriteSettingsToStream(Settings settings, StreamOutput out)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment
isFragment
-
-
-
-
Field Detail
-
EMPTY
public static final Settings EMPTY
-
FORMAT_PARAMS
public static final java.util.Set<java.lang.String> FORMAT_PARAMS
-
-
Method Detail
-
getByPrefix
public Settings getByPrefix(java.lang.String prefix)
A settings that are filtered (and key is removed) with the specified prefix.
-
filter
public Settings filter(java.util.function.Predicate<java.lang.String> predicate)
Returns a new settings object that contains all setting of the current one filtered by the given settings key predicate.
-
getAsSettings
public Settings getAsSettings(java.lang.String setting)
Returns the settings mapped to the given setting name.
-
get
public java.lang.String get(java.lang.String setting)
Returns the setting value associated with the setting key.- Parameters:
setting- The setting key- Returns:
- The setting value,
nullif it does not exists.
-
get
public java.lang.String get(java.lang.String setting, java.lang.String defaultValue)Returns the setting value associated with the setting key. If it does not exists, returns the default value provided.
-
getAsFloat
public java.lang.Float getAsFloat(java.lang.String setting, java.lang.Float defaultValue)Returns the setting value (as float) associated with the setting key. If it does not exists, returns the default value provided.
-
getAsDouble
public java.lang.Double getAsDouble(java.lang.String setting, java.lang.Double defaultValue)Returns the setting value (as double) associated with the setting key. If it does not exists, returns the default value provided.
-
getAsInt
public java.lang.Integer getAsInt(java.lang.String setting, java.lang.Integer defaultValue)Returns the setting value (as int) associated with the setting key. If it does not exists, returns the default value provided.
-
getAsLong
public java.lang.Long getAsLong(java.lang.String setting, java.lang.Long defaultValue)Returns the setting value (as long) associated with the setting key. If it does not exists, returns the default value provided.
-
hasValue
public boolean hasValue(java.lang.String key)
Returnstrueiff the given key has a value in this settings object
-
getAsBoolean
public java.lang.Boolean getAsBoolean(java.lang.String setting, java.lang.Boolean defaultValue)Returns the setting value (as boolean) associated with the setting key. If it does not exists, returns the default value provided.
-
getAsBooleanLenientForPreEs6Indices
@Deprecated public java.lang.Boolean getAsBooleanLenientForPreEs6Indices(Version indexVersion, java.lang.String setting, java.lang.Boolean defaultValue, DeprecationLogger deprecationLogger)
Deprecated.Only used to provide automatic upgrades for pre 6.0 indices.Returns the setting value (as boolean) associated with the setting key. If it does not exist, returns the default value provided. If the index was created on Elasticsearch below 6.0, booleans will be parsed leniently otherwise they are parsed strictly. SeeBooleans.isBooleanLenient(char[], int, int)for the definition of a "lenient boolean" andBooleans.isBoolean(char[], int, int)for the definition of a "strict boolean".
-
getAsTime
public TimeValue getAsTime(java.lang.String setting, TimeValue defaultValue)
Returns the setting value (as time) associated with the setting key. If it does not exists, returns the default value provided.
-
getAsBytesSize
public ByteSizeValue getAsBytesSize(java.lang.String setting, ByteSizeValue defaultValue) throws SettingsException
Returns the setting value (as size) associated with the setting key. If it does not exists, returns the default value provided.- Throws:
SettingsException
-
getAsMemory
public ByteSizeValue getAsMemory(java.lang.String setting, java.lang.String defaultValue) throws SettingsException
Returns the setting value (as size) associated with the setting key. Provided values can either be absolute values (interpreted as a number of bytes), byte sizes (eg. 1mb) or percentage of the heap size (eg. 12%). If it does not exists, parses the default value provided.- Throws:
SettingsException
-
getAsList
public java.util.List<java.lang.String> getAsList(java.lang.String key) throws SettingsExceptionThe values associated with a setting key as an immutable list.It will also automatically load a comma separated list under the settingPrefix and merge with the numbered format.
- Parameters:
key- The setting key to load the list by- Returns:
- The setting list values
- Throws:
SettingsException
-
getAsList
public java.util.List<java.lang.String> getAsList(java.lang.String key, java.util.List<java.lang.String> defaultValue) throws SettingsExceptionThe values associated with a setting key as an immutable list.If commaDelimited is true, it will automatically load a comma separated list under the settingPrefix and merge with the numbered format.
- Parameters:
key- The setting key to load the list by- Returns:
- The setting list values
- Throws:
SettingsException
-
getAsList
public java.util.List<java.lang.String> getAsList(java.lang.String key, java.util.List<java.lang.String> defaultValue, java.lang.Boolean commaDelimited) throws SettingsExceptionThe values associated with a setting key as an immutable list.It will also automatically load a comma separated list under the settingPrefix and merge with the numbered format.
- Parameters:
key- The setting key to load the list bydefaultValue- The default value to use if no value is specifiedcommaDelimited- Whether to try to parse a string as a comma-delimited value- Returns:
- The setting list values
- Throws:
SettingsException
-
getGroups
public java.util.Map<java.lang.String,Settings> getGroups(java.lang.String settingPrefix) throws SettingsException
Returns group settings for the given setting prefix.- Throws:
SettingsException
-
getGroups
public java.util.Map<java.lang.String,Settings> getGroups(java.lang.String settingPrefix, boolean ignoreNonGrouped) throws SettingsException
Returns group settings for the given setting prefix.- Throws:
SettingsException
-
getAsGroups
public java.util.Map<java.lang.String,Settings> getAsGroups() throws SettingsException
Returns group settings for the given setting prefix.- Throws:
SettingsException
-
getAsVersion
public Version getAsVersion(java.lang.String setting, Version defaultVersion) throws SettingsException
Returns a parsed version.- Throws:
SettingsException
-
names
public java.util.Set<java.lang.String> names()
- Returns:
- The direct keys of this settings
-
toDelimitedString
public java.lang.String toDelimitedString(char delimiter)
Returns the settings as delimited string.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
readSettingsFromStream
public static Settings readSettingsFromStream(StreamInput in) throws java.io.IOException
- Throws:
java.io.IOException
-
writeSettingsToStream
public static void writeSettingsToStream(Settings settings, StreamOutput out) throws java.io.IOException
- Throws:
java.io.IOException
-
builder
public static Settings.Builder builder()
Returns a builder to be used in order to build settings.
-
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
toXContentin interfaceToXContent- Throws:
java.io.IOException
-
fromXContent
public static Settings fromXContent(XContentParser parser) throws java.io.IOException
Parsers the generated xcontent fromtoXContent(XContentBuilder, Params)into a new Settings object. Note this method requires the parser to either be positioned on a null token or onXContentParser.Token.START_OBJECT.- Throws:
java.io.IOException
-
isEmpty
public boolean isEmpty()
Returnstrueif this settings object contains no settings- Returns:
trueif this settings object contains no settings
-
size
public int size()
Returns the number of settings in this settings object.
-
keySet
public java.util.Set<java.lang.String> keySet()
Returns the fully qualified setting names contained in this settings object.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-