list_to_map

    The following table describes the configuration options used to generate target keys for the mappings.

    Usage

    The following example shows how to test the usage of the list_to_map processor before using the processor on your own source.

    Create a source file named logs_json.log. Because the file source reads each line in the .log file as an event, the object list appears as one line even though it contains multiple objects:

    copy

    Next, create a pipeline.yaml file that uses the logs_json.log file as the source by pointing to the .log file’s correct path:

    1. pipeline:
    2. source:
    3. file:
    4. path: "/full/path/to/logs_json.log"
    5. record_type: "event"
    6. format: "json"
    7. processor:
    8. - list_to_map:
    9. key: "name"
    10. source: "mylist"
    11. value_key: "value"
    12. flatten: true
    13. sink:
    14. - stdout:

    copy

    1. {
    2. "mylist": [
    3. {
    4. "name": "a",
    5. "value": "val-a"
    6. },
    7. {
    8. "name": "b",
    9. "value": "val-b1"
    10. },
    11. {
    12. "name": "b",
    13. "value": "val-b2"
    14. },
    15. {
    16. "name": "c",
    17. "value": "val-c"
    18. }
    19. ],
    20. "a": "val-a",
    21. "b": "val-b1",
    22. }

    The following example pipeline.yaml file shows the list_to_map processor when set to a specified target, mymap:

    copy

    The generated map appears under the target key:

    1. {
    2. "mylist": [
    3. {
    4. "name": "a",
    5. "value": "val-a"
    6. },
    7. "name": "b",
    8. "value": "val-b1"
    9. },
    10. {
    11. "name": "b",
    12. "value": "val-b2"
    13. },
    14. {
    15. "name": "c",
    16. "value": "val-c"
    17. }
    18. ],
    19. "mymap": {
    20. "a": "val-a",
    21. "b": "val-b1",
    22. "c": "val-c"
    23. }
    24. }

    The follow example pipeline.yaml file shows the list_to_map processor with no value_key specified. Because key is set to name, the processor extracts the object names to use as keys in the map.

    1. pipeline:
    2. source:
    3. file:
    4. path: "/full/path/to/logs_json.log"
    5. record_type: "event"
    6. format: "json"
    7. processor:
    8. - list_to_map:
    9. key: "name"
    10. source: "mylist"
    11. flatten: true
    12. sink:
    13. - stdout:

    copy

    The values from the generated map appear as original objects from the .log source, as shown in the following example response:

    1. pipeline:
    2. source:
    3. file:
    4. path: "/full/path/to/logs_json.log"
    5. record_type: "event"
    6. format: "json"
    7. processor:
    8. - list_to_map:
    9. key: "name"
    10. source: "mylist"
    11. value_key: "value"
    12. flatten: true
    13. flattened_element: "last"
    14. sink:
    15. - stdout:

    copy

    The processor maps object b to value val-b2 because val-b2 is the last element in object b, as shown in the following output:

    1. {
    2. "mylist": [
    3. "name": "a",
    4. "value": "val-a"
    5. },
    6. {
    7. "name": "b",
    8. "value": "val-b1"
    9. },
    10. {
    11. "name": "b",
    12. "value": "val-b2"
    13. },
    14. {
    15. "name": "c",
    16. "value": "val-c"
    17. }
    18. ],
    19. "a": "val-a",
    20. "b": "val-b2",
    21. "c": "val-c"
    22. }

    The following example pipeline.yaml file sets flatten to false, causing the processor to output values from the generated map as a list:

    copy

    Some objects in the response may have more than one element in their values, as shown in the following response:

    1. {
    2. "mylist": [
    3. {
    4. "name": "a",
    5. "value": "val-a"
    6. },
    7. {
    8. "name": "b",
    9. "value": "val-b1"
    10. },
    11. {
    12. "name": "b",
    13. "value": "val-b2"
    14. },
    15. {
    16. "name": "c",
    17. "value": "val-c"
    18. }
    19. ],
    20. "a": [
    21. "val-a"
    22. ],
    23. "b": [
    24. "val-b1",
    25. "val-b2"
    26. ],
    27. "c": [
    28. "val-c"