Module org.elasticsearch.server
Package org.elasticsearch.index.mapper
Class FieldMapper.Parameter<T>
java.lang.Object
org.elasticsearch.index.mapper.FieldMapper.Parameter<T>
- Type Parameters:
T
- the type of the value the parameter holds
- All Implemented Interfaces:
Supplier<T>
- Enclosing class:
- FieldMapper
A configurable parameter for a field mapper
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionParameter
(String name, boolean updateable, Supplier<T> defaultValue, TriFunction<String, MappingParserContext, Object, T> parser, Function<FieldMapper, T> initializer, FieldMapper.Serializer<T> serializer, Function<T, String> conflictSerializer) Creates a new Parameter -
Method Summary
Modifier and TypeMethodDescriptionAllows the parameter to accept anull
valueaddDeprecatedName
(String deprecatedName) Adds a deprecated parameter name.addValidator
(Consumer<T> validator) Adds validation to a parameter, called after parsing and merging.Always serialize this parameter, no matter its valuestatic FieldMapper.Parameter<NamedAnalyzer>
analyzerParam
(String name, boolean updateable, Function<FieldMapper, NamedAnalyzer> initializer, Supplier<NamedAnalyzer> defaultAnalyzer) Defines a parameter that takes an analyzer namestatic FieldMapper.Parameter<NamedAnalyzer>
analyzerParam
(String name, boolean updateable, Function<FieldMapper, NamedAnalyzer> initializer, Supplier<NamedAnalyzer> defaultAnalyzer, IndexVersion indexCreatedVersion) Defines a parameter that takes an analyzer namestatic FieldMapper.Parameter<Boolean>
boolParam
(String name, boolean updateable, Function<FieldMapper, Boolean> initializer, boolean defaultValue) Defines a parameter that takes the valuestrue
orfalse
static FieldMapper.Parameter<Boolean>
boolParam
(String name, boolean updateable, Function<FieldMapper, Boolean> initializer, Supplier<Boolean> defaultValue) boolean
Deprecates the entire parameter.static FieldMapper.Parameter<Boolean>
docValuesParam
(Function<FieldMapper, Boolean> initializer, boolean defaultValue) static <T extends Enum<T>>
FieldMapper.Parameter<T>enumParam
(String name, boolean updateable, Function<FieldMapper, T> initializer, Supplier<T> defaultValue, Class<T> enumClass) Defines a parameter that takes any of the values of an enumeration.static <T extends Enum<T>>
FieldMapper.Parameter<T>enumParam
(String name, boolean updateable, Function<FieldMapper, T> initializer, T defaultValue, Class<T> enumClass) Defines a parameter that takes any of the values of an enumeration.static FieldMapper.Parameter<Explicit<Boolean>>
explicitBoolParam
(String name, boolean updateable, Function<FieldMapper, Explicit<Boolean>> initializer, boolean defaultValue) Defines a parameter that takes the valuestrue
orfalse
, and will always serialize its value if configured.get()
Returns the default value of the parametergetValue()
Returns the current value of the parameterstatic FieldMapper.Parameter<Boolean>
indexParam
(Function<FieldMapper, Boolean> initializer, boolean defaultValue) static FieldMapper.Parameter<Boolean>
indexParam
(Function<FieldMapper, Boolean> initializer, Supplier<Boolean> defaultValue) static FieldMapper.Parameter<Integer>
intParam
(String name, boolean updateable, Function<FieldMapper, Integer> initializer, int defaultValue) Defines a parameter that takes an integer valueboolean
static FieldMapper.Parameter<Map<String,
String>> Declares a metadata parameterNever serialize this parameter, no matter its valuestatic FieldMapper.Parameter<OnScriptError>
onScriptErrorParam
(Function<FieldMapper, OnScriptError> initializer, FieldMapper.Parameter<Script> dependentScriptParam) Defines an on_script_error parametervoid
parse
(String field, MappingParserContext context, Object in) Parse the field value from an ObjectprecludesParameters
(FieldMapper.Parameter<?>... ps) static <T extends Enum<T>>
FieldMapper.Parameter<T>restrictedEnumParam
(String name, boolean updateable, Function<FieldMapper, T> initializer, Supplier<T> defaultValue, Class<T> enumClass, Set<T> acceptedValues) Defines a parameter that takes one of a restricted set of values from an enumeration.static <T extends Enum<T>>
FieldMapper.Parameter<T>restrictedEnumParam
(String name, boolean updateable, Function<FieldMapper, T> initializer, T defaultValue, Class<T> enumClass, Set<T> acceptedValues) Defines a parameter that takes one of a restricted set of values from an enumeration.static FieldMapper.Parameter<Script>
scriptParam
(Function<FieldMapper, Script> initializer) Defines a script parametersetMergeValidator
(FieldMapper.MergeValidator<T> mergeValidator) Sets a custom merge validator.Configure a custom serialization check for this parametervoid
Sets the current value of the parameterstatic FieldMapper.Parameter<Boolean>
storeParam
(Function<FieldMapper, Boolean> initializer, boolean defaultValue) static FieldMapper.Parameter<List<String>>
stringArrayParam
(String name, boolean updateable, Function<FieldMapper, List<String>> initializer) static FieldMapper.Parameter<String>
stringParam
(String name, boolean updateable, Function<FieldMapper, String> initializer, String defaultValue) Defines a parameter that takes a string valuestatic FieldMapper.Parameter<String>
stringParam
(String name, boolean updateable, Function<FieldMapper, String> initializer, String defaultValue, FieldMapper.Serializer<String> serializer) protected void
toXContent
(XContentBuilder builder, boolean includeDefaults)
-
Field Details
-
name
-
-
Constructor Details
-
Parameter
public Parameter(String name, boolean updateable, Supplier<T> defaultValue, TriFunction<String, MappingParserContext, Object, T> parser, Function<FieldMapper, T> initializer, FieldMapper.Serializer<T> serializer, Function<T, String> conflictSerializer) Creates a new Parameter- Parameters:
name
- the parameter name, used in parsing and serializationupdateable
- whether the parameter can be updated with a new value during a mapping updatedefaultValue
- the default value for the parameter, used if unspecified in mappingsparser
- a function that converts an object to a parameter valueinitializer
- a function that reads a parameter value from an existing mapperserializer
- a function that serializes a parameter value, prefer type specific x-content generation methods here for good performance as this is used on the hot-path during cluster state updates. This should explicitly not be linked withXContentBuilder.field(String, Object)
by callers through the use of default values or other indirection to this constructor.conflictSerializer
- a function that serializes a parameter value on conflict
-
-
Method Details
-
getValue
Returns the current value of the parameter -
get
-
getDefaultValue
Returns the default value of the parameter -
setValue
Sets the current value of the parameter -
isConfigured
public boolean isConfigured() -
acceptsNull
Allows the parameter to accept anull
value -
canAcceptNull
public boolean canAcceptNull() -
addDeprecatedName
Adds a deprecated parameter name. If this parameter name is encountered during parsing, a deprecation warning will be emitted. The parameter will be serialized with its main name. -
deprecated
Deprecates the entire parameter. If this parameter is encountered during parsing, a deprecation warning will be emitted. -
addValidator
Adds validation to a parameter, called after parsing and merging. Multiple validators can be added and all of them will be executed. -
setSerializerCheck
Configure a custom serialization check for this parameter -
alwaysSerialize
Always serialize this parameter, no matter its value -
neverSerialize
Never serialize this parameter, no matter its value -
setMergeValidator
Sets a custom merge validator. By default, merges are accepted if the parameter is updateable, or if the previous and new values are equal -
requiresParameter
-
precludesParameters
-
parse
Parse the field value from an Object- Parameters:
field
- the field namecontext
- the parser contextin
- the object
-
toXContent
- Throws:
IOException
-
boolParam
public static FieldMapper.Parameter<Boolean> boolParam(String name, boolean updateable, Function<FieldMapper, Boolean> initializer, boolean defaultValue) Defines a parameter that takes the valuestrue
orfalse
- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultValue
- the default value, to be used if the parameter is undefined in a mapping
-
boolParam
public static FieldMapper.Parameter<Boolean> boolParam(String name, boolean updateable, Function<FieldMapper, Boolean> initializer, Supplier<Boolean> defaultValue) -
explicitBoolParam
public static FieldMapper.Parameter<Explicit<Boolean>> explicitBoolParam(String name, boolean updateable, Function<FieldMapper, Explicit<Boolean>> initializer, boolean defaultValue) Defines a parameter that takes the valuestrue
orfalse
, and will always serialize its value if configured.- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultValue
- the default value, to be used if the parameter is undefined in a mapping
-
intParam
public static FieldMapper.Parameter<Integer> intParam(String name, boolean updateable, Function<FieldMapper, Integer> initializer, int defaultValue) Defines a parameter that takes an integer value- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultValue
- the default value, to be used if the parameter is undefined in a mapping
-
stringParam
public static FieldMapper.Parameter<String> stringParam(String name, boolean updateable, Function<FieldMapper, String> initializer, String defaultValue) Defines a parameter that takes a string value- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultValue
- the default value, to be used if the parameter is undefined in a mapping
-
stringParam
public static FieldMapper.Parameter<String> stringParam(String name, boolean updateable, Function<FieldMapper, String> initializer, String defaultValue, FieldMapper.Serializer<String> serializer) -
stringArrayParam
public static FieldMapper.Parameter<List<String>> stringArrayParam(String name, boolean updateable, Function<FieldMapper, List<String>> initializer) -
enumParam
public static <T extends Enum<T>> FieldMapper.Parameter<T> enumParam(String name, boolean updateable, Function<FieldMapper, T> initializer, T defaultValue, Class<T> enumClass) Defines a parameter that takes any of the values of an enumeration.- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultValue
- the default value, to be used if the parameter is undefined in a mappingenumClass
- the enumeration class the parameter takes values from
-
enumParam
public static <T extends Enum<T>> FieldMapper.Parameter<T> enumParam(String name, boolean updateable, Function<FieldMapper, T> initializer, Supplier<T> defaultValue, Class<T> enumClass) Defines a parameter that takes any of the values of an enumeration.- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultValue
- a supplier for the default value, to be used if the parameter is undefined in a mappingenumClass
- the enumeration class the parameter takes values from
-
restrictedEnumParam
public static <T extends Enum<T>> FieldMapper.Parameter<T> restrictedEnumParam(String name, boolean updateable, Function<FieldMapper, T> initializer, T defaultValue, Class<T> enumClass, Set<T> acceptedValues) Defines a parameter that takes one of a restricted set of values from an enumeration.- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultValue
- the default value, to be used if the parameter is undefined in a mappingenumClass
- the enumeration class the parameter takes values fromacceptedValues
- the set of values that the parameter can take
-
restrictedEnumParam
public static <T extends Enum<T>> FieldMapper.Parameter<T> restrictedEnumParam(String name, boolean updateable, Function<FieldMapper, T> initializer, Supplier<T> defaultValue, Class<T> enumClass, Set<T> acceptedValues) Defines a parameter that takes one of a restricted set of values from an enumeration.- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultValue
- a supplier for the default value, to be used if the parameter is undefined in a mappingenumClass
- the enumeration class the parameter takes values fromacceptedValues
- the set of values that the parameter can take
-
analyzerParam
public static FieldMapper.Parameter<NamedAnalyzer> analyzerParam(String name, boolean updateable, Function<FieldMapper, NamedAnalyzer> initializer, Supplier<NamedAnalyzer> defaultAnalyzer, IndexVersion indexCreatedVersion) Defines a parameter that takes an analyzer name- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultAnalyzer
- the default value, to be used if the parameter is undefined in a mappingindexCreatedVersion
- the version on which this index was created
-
analyzerParam
public static FieldMapper.Parameter<NamedAnalyzer> analyzerParam(String name, boolean updateable, Function<FieldMapper, NamedAnalyzer> initializer, Supplier<NamedAnalyzer> defaultAnalyzer) Defines a parameter that takes an analyzer name- Parameters:
name
- the parameter nameupdateable
- whether the parameter can be changed by a mapping updateinitializer
- a function that reads the parameter value from an existing mapperdefaultAnalyzer
- the default value, to be used if the parameter is undefined in a mapping
-
metaParam
Declares a metadata parameter -
indexParam
public static FieldMapper.Parameter<Boolean> indexParam(Function<FieldMapper, Boolean> initializer, boolean defaultValue) -
indexParam
public static FieldMapper.Parameter<Boolean> indexParam(Function<FieldMapper, Boolean> initializer, Supplier<Boolean> defaultValue) -
storeParam
public static FieldMapper.Parameter<Boolean> storeParam(Function<FieldMapper, Boolean> initializer, boolean defaultValue) -
docValuesParam
public static FieldMapper.Parameter<Boolean> docValuesParam(Function<FieldMapper, Boolean> initializer, boolean defaultValue) -
scriptParam
Defines a script parameter- Parameters:
initializer
- retrieves the equivalent parameter from an existing FieldMapper for use in merges- Returns:
- a script parameter
-
onScriptErrorParam
public static FieldMapper.Parameter<OnScriptError> onScriptErrorParam(Function<FieldMapper, OnScriptError> initializer, FieldMapper.Parameter<Script> dependentScriptParam) Defines an on_script_error parameter- Parameters:
initializer
- retrieves the equivalent parameter from an existing FieldMapper for use in mergesdependentScriptParam
- the corresponding required script parameter- Returns:
- a new on_error_script parameter
-