Module org.elasticsearch.server
Class XContentMapValues
java.lang.Object
org.elasticsearch.common.xcontent.support.XContentMapValues
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.lucene.util.automaton.CharacterRunAutomatoncompileAutomaton(String[] patterns, org.apache.lucene.util.automaton.CharacterRunAutomaton defaultValue) extractNestedSources(String nestedPath, Map<?, ?> map) For the provided nested path, return its source maps from the parent xContent map.extractRawValues(String path, Map<String, Object> map) Extracts raw values (string, int, and so on) based on the path provided returning all of them as a single list.static ObjectextractValue(String path, Map<?, ?> map) For the provided path, return its value in the xContent map.static ObjectextractValue(String path, Map<?, ?> map, Object nullValue) For the provided path, return its value in the xContent map.static ObjectextractValue(Map<?, ?> map, String... pathElements) Returns a function that filters a document map based on the given include and exclude rules.Only keep properties inmapthat match theincludesbut not theexcludes.static voidinsertValue(String path, Map<?, ?> map, Object newValue) static voidinsertValue(String path, Map<?, ?> map, Object newValue, boolean failOnMultiMap) Insert or replace the path's value in the map with the provided new value.static booleanstatic booleannodeBooleanValue(Object node) static booleannodeBooleanValue(Object node, boolean defaultValue) static booleannodeBooleanValue(Object node, String name) static booleannodeBooleanValue(Object node, String name, boolean defaultValue) static doublenodeDoubleValue(Object node) static doublenodeDoubleValue(Object node, double defaultValue) static intnodeIntegerValue(Object node) static intnodeIntegerValue(Object node, int defaultValue) nodeMapValue(Object node, String desc) static String[]nodeStringArrayValue(Object node) Returns an array of string value from a node value.static StringnodeStringValue(Object node) Returns theObject.toString()value of its input, ornullif the input is nullstatic StringnodeStringValue(Object node, String defaultValue) static TimeValuenodeTimeValue(Object node) static TimeValuenodeTimeValue(Object node, TimeValue defaultValue)
-
Constructor Details
-
XContentMapValues
public XContentMapValues()
-
-
Method Details
-
extractRawValues
Extracts raw values (string, int, and so on) based on the path provided returning all of them as a single list. -
extractValue
For the provided path, return its value in the xContent map. Note that in contrast withextractRawValues(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>), array and object values can be returned.- Parameters:
path- the value's path in the map.- Returns:
- the value associated with the path in the map or 'null' if the path does not exist.
-
extractValue
-
extractNestedSources
For the provided nested path, return its source maps from the parent xContent map.- Parameters:
nestedPath- the nested field value's path in the map.map- the parent source map- Returns:
- a list of source maps or
nullif the path does not exist.
-
extractValue
For the provided path, return its value in the xContent map. Note that in contrast withextractRawValues(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>), array and object values can be returned.- Parameters:
path- the value's path in the map.nullValue- a value to return if the path exists, but the value is 'null'. This helps in distinguishing between a path that doesn't exist vs. a value of 'null'.- Returns:
- the value associated with the path in the map or 'null' if the path does not exist.
-
filter
public static Map<String,Object> filter(Map<String, Object> map, String[] includes, String[] excludes) Only keep properties inmapthat match theincludesbut not theexcludes. An empty list of includes is interpreted as a wildcard while an empty list of excludes does not match anything. If a property matches both an include and an exclude, then the exclude wins. If an object matches, then any of its sub properties are automatically considered as matching as well, both for includes and excludes. Dots in field names are treated as sub objects. So for instance if a document containsa.bas a property andais an include, thena.bwill be kept in the filtered map. -
filter
public static Function<Map<String,Object>, filterMap<String, Object>> (String[] includes, String[] excludes) Returns a function that filters a document map based on the given include and exclude rules.- See Also:
-
compileAutomaton
public static org.apache.lucene.util.automaton.CharacterRunAutomaton compileAutomaton(String[] patterns, org.apache.lucene.util.automaton.CharacterRunAutomaton defaultValue) -
isArray
-
nodeStringValue
-
nodeStringValue
Returns theObject.toString()value of its input, ornullif the input is null -
nodeDoubleValue
-
nodeDoubleValue
-
nodeIntegerValue
-
nodeIntegerValue
-
nodeBooleanValue
-
nodeBooleanValue
-
nodeBooleanValue
-
nodeBooleanValue
-
nodeTimeValue
-
nodeTimeValue
-
nodeMapValue
-
nodeStringArrayValue
Returns an array of string value from a node value. If the node represents an array the corresponding array of strings is returned. Otherwise the node is treated as a comma-separated string. -
insertValue
-
insertValue
Insert or replace the path's value in the map with the provided new value. The map will be modified in-place. If the complete path does not exist in the map, it will be added to the deepest (sub-)map possible.
For example, given the map:
{ "path1": { "path2": { "key1": "value1" } } }And the caller wanted to insert
"path1.path2.path3.key2": "value2", the method would emit the modified map:{ "path1": { "path2": { "key1": "value1", "path3.key2": "value2" } } }- Parameters:
path- the value's path in the map.map- the map to search and modify in-place.newValue- the new value to assign to the path.failOnMultiMap- whether the insertion should fail with anIllegalArgumentExceptionif the path can be resolved in multiple ways.- Throws:
IllegalArgumentException- If either the path cannot be fully traversed.
-