Class XContentMapValues

java.lang.Object
org.elasticsearch.common.xcontent.support.XContentMapValues

public class XContentMapValues extends Object
  • Constructor Details

    • XContentMapValues

      public XContentMapValues()
  • Method Details

    • extractRawValues

      public static List<Object> 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.
    • extractValue

      public static Object extractValue(String path, Map<?,?> map)
      For the provided path, return its value in the xContent map. Note that in contrast with extractRawValues(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

      public static Object extractValue(Map<?,?> map, String... pathElements)
    • extractNestedSources

      public static List<Map<?,?>> extractNestedSources(String nestedPath, Map<?,?> map)
      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 null if the path does not exist.
    • extractValue

      public static Object extractValue(String path, Map<?,?> map, Object nullValue)
      For the provided path, return its value in the xContent map. Note that in contrast with extractRawValues(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,?> map, String[] includes, String[] excludes)
      Only keep properties in map that match the includes but not the excludes. 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 contains a.b as a property and a is an include, then a.b will be kept in the filtered map.
    • filter

      public static Function<Map<String,?>,Map<String,Object>> filter(String[] includes, String[] excludes)
      Returns a function that filters a document map based on the given include and exclude rules.
      See Also:
    • isObject

      public static boolean isObject(Object node)
    • isArray

      public static boolean isArray(Object node)
    • nodeStringValue

      public static String nodeStringValue(Object node, String defaultValue)
    • nodeStringValue

      public static String nodeStringValue(Object node)
      Returns the Object.toString() value of its input, or null if the input is null
    • nodeFloatValue

      public static float nodeFloatValue(Object node, float defaultValue)
    • nodeFloatValue

      public static float nodeFloatValue(Object node)
    • nodeDoubleValue

      public static double nodeDoubleValue(Object node, double defaultValue)
    • nodeDoubleValue

      public static double nodeDoubleValue(Object node)
    • nodeIntegerValue

      public static int nodeIntegerValue(Object node)
    • nodeIntegerValue

      public static int nodeIntegerValue(Object node, int defaultValue)
    • nodeShortValue

      public static short nodeShortValue(Object node, short defaultValue)
    • nodeShortValue

      public static short nodeShortValue(Object node)
    • nodeByteValue

      public static byte nodeByteValue(Object node, byte defaultValue)
    • nodeByteValue

      public static byte nodeByteValue(Object node)
    • nodeLongValue

      public static long nodeLongValue(Object node, long defaultValue)
    • nodeLongValue

      public static long nodeLongValue(Object node)
    • nodeBooleanValue

      public static boolean nodeBooleanValue(Object node, String name, boolean defaultValue)
    • nodeBooleanValue

      public static boolean nodeBooleanValue(Object node, boolean defaultValue)
    • nodeBooleanValue

      public static boolean nodeBooleanValue(Object node, String name)
    • nodeBooleanValue

      public static boolean nodeBooleanValue(Object node)
    • nodeTimeValue

      public static TimeValue nodeTimeValue(Object node, TimeValue defaultValue)
    • nodeTimeValue

      public static TimeValue nodeTimeValue(Object node)
    • nodeMapValue

      public static Map<String,Object> nodeMapValue(Object node, String desc)
    • nodeStringArrayValue

      public static String[] nodeStringArrayValue(Object node)
      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.