Skip to content

Add getInnerValue as a utility method in Painless #42769

@jdconrad

Description

@jdconrad

Add two utility methods with the following signature to the shared API:

def getInnerValue(def data, String path); // default delimiter of '.'
def getInnerValue(def data, String path, String delimiter);

This method should take in either a Map or a List and be able to parse a path to get a value out of the data. The path should be separated into pieces based on the delimiter. For each piece in the path if the current level is a Map retrieve the value based on the piece as a key, if the current level is a List retrieve the value based on the piece as an index.

Example:

String path = "key0.2.key1";
def value = getInnerValue(data, path);

This assumes a structure of Map, List, Map and will return the equivalent of data.get('key0').get(2).get('key1');

This allows uses to specify a path as part of params and then use this method without having to separate the path themselves. This is useful in many situations when the context contains _source as there can be many inner fields.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions