**同步结果摘要**: | 目录 | 同步前 | 同步后 | 官方 | |------|--------|--------|------| | aggregations | 40 | 65 | 64 | | analyzers | 8 | 141 | 140 | | api-reference | 97 | 186 | 174 | | benchmark | 34 | 67 | 53 | | clients | 17 | 18 | 18 | | dashboards | 38 | 149 | 131 | | data-prepper | 77 | 134 | 123 | | im-plugin | 22 | 37 | 37 | | ingest-pipelines | 27 | 52 | 51 | | install-and-configure | 37 | 57 | 53 | | ml-commons-plugin | 81 | 157 | 155 | | observing-your-data | 39 | 73 | 66 | | query-dsl | 40 | 77 | 75 | | search-plugins | 80 | 139 | 95 | | security-analytics | 22 | 47 | 46 | **说明**: - 本地文件数 > 官方:本地有一些官方已删除或重命名的文件 - 新增了约 **740 个英文文档文件** - 已有文件保持不变(未覆盖)
2.2 KiB
layout, title, parent, grand_parent, nav_order
| layout | title | parent | grand_parent | nav_order |
|---|---|---|---|---|
| default | subList() | Functions | Pipelines | 50 |
subList() function
The subList(<key>, <start_index, inclusive>, <end_index, exclusive>) function extracts a sublist from a list field in an event. It takes the following arguments:
- A JSON pointer to an event field containing a list
- A start index (inclusive)
- An end index (exclusive)
The function returns the portion of the list between the specified start and end indexes. If the end index is -1, the function extracts elements from the start index to the end of the list.
Examples
The following examples show how the sublist() function works.
add_entries processor
You can use subList() in the add_entries processor, as shown in the following example.
The function uses the following input to extract a sublist:
input: {"my_list": [ 0, 1, 2, 3, 4, 5, 6]}
Then, the following configuration uses the add_entries processor to extract a sublist from my_list, starting at index 1 and ending before index 4:
add_entries:
entries:
- key: "my_list"
value_expression: '/subList(/my_list, 1, 4)'
overwrite_if_key_exists: true
{% include copy.html %}
The following output shows the resulting list after extracting elements from index 1 to 3 and overwriting the original list:
output: my_list: [1, 2, 3]
Specific ranges
Each of the following examples demonstrates how the subList() function extracts a specific range of elements from a list.
The following example extracts elements from index 0 to 2 (excluding index 3), resulting in the first three elements of the list:
{
"event": {
"/my_list": [0, 1, 2, 3, 4, 5, 6]
},
"expression": "subList(/my_list, 4, -1)",
"expected_output": [4, 5, 6]
}
{% include copy.html %}
The following example uses -1 as the end index, which specifies to include all elements from index 4 to the end of the list:
{
"event": {
"/my_list": [0, 1, 2, 3, 4, 5, 6]
},
"expression": "subList(/my_list, 4, -1)",
"expected_output": [4, 5, 6]
}
{% include copy.html %}