《n8n Item Lists 节点:数组操作全攻略(排序、过滤、分组、去重、合并)》

🚀 n8n Item Lists 节点:数组处理最强工具(超详细教程)

Item Lists 节点是 n8n 中最重要的"数组处理工具"。

如果你经常需要:

  • 过滤数据(filter)

  • 排序(sort)

  • 去重(unique)

  • 分组(aggregate / group)

  • 合并多个字段

  • 把 item list 转成 map / array

那么 Item Lists 必须会用。

它是数据预处理必备节点,特别常用于:

  • CRM 数据处理

  • API 分页数据合并

  • Excel / Google Sheets 行处理

  • AI 批量任务前清洗数据

本篇一次性讲透。


📌 1. Item Lists 是干什么的?

一句话:

Item Lists = 对 nodes 输出的 items 数组进行各种操作(过滤、排序、去重、聚合、取字段等)。

它不像 Function/Code 节点写代码,而是纯 UI 配置,非常适合不会代码的人。

你只要给它输入 items,它就能通过不同模式(Operation)来 transform 数据。


📌 2. Item Lists 操作模式详解(最常用的 6 个)

在 Item Lists 中你会看到这些操作模式(Operation):

Operation 类型 说明
Filter 过滤数据
Sort 排序
Aggregate 聚合、分组、求和
Unique 去重
Limit 截取前 N 条
Split out / Combine 拆分或合并 list
Pick / Remove Fields 白名单/黑名单字段

下面我讲你最常用的几项。


📌 3. UI 操作详解(最常用 5 个)


✔ ① Filter(过滤)

用途:保留符合条件的数据。

例:

保留 price > 50 的商品

配置:

  • Field:price

  • Operation:greater

  • Value:50


✔ ② Sort(排序)

例:按更新时间倒序

  • Field:updatedAt

  • Order:DESC


✔ ③ Aggregate(聚合)

用途:做统计、按字段分组。

例:统计每个客户订单总金额

  • Group Field:customer

  • Aggregate:sum(price)

得到结构:

复制代码
[
  { "customer": "A", "sum_price": 100 },
  { "customer": "B", "sum_price": 220 }
]

✔ ④ Unique(去重)

用途:根据某一字段去重。

例:按 email 去重

  • Field:email

✔ ⑤ Limit(截取)

例:只取前 10 条数据


📌 4. 流程图(Item Lists 的位置)

复制代码
+-----------+       +------------------+       +----------------+
|   Source  | --->  |   Item Lists     | ---> |  Next Node     |
+-----------+       | (过滤/排序/聚合) |       +----------------+
                    +------------------+

📌 5. 测试数据(用于教程 + Demo)

请放入一个 Set 节点:

复制代码
[
  { "customer": "A", "price": 30, "type": "food" },
  { "customer": "A", "price": 50, "type": "food" },
  { "customer": "A", "price": 20, "type": "drink" },
  { "customer": "B", "price": 100, "type": "food" },
  { "customer": "B", "price": 90, "type": "drink" }
]

📌 6. Item Lists 场景案例(非常贴近真实需求)


✔ 场景 1:过滤价格大于 50 的商品

输出:

复制代码
[
  { "customer": "B", "price": 100, "type": "food" },
  { "customer": "B", "price": 90, "type": "drink" }
]

✔ 场景 2:按价格排序(从小到大)

返回:

复制代码
[
  { "price": 20 },
  { "price": 30 },
  ...
]

✔ 场景 3:按 customer 分组求和(Aggregate)

配置

  • Group Field:customer

  • Aggregate: sum(price) → total_price

输出

复制代码
[
  { "customer": "A", "total_price": 100 },
  { "customer": "B", "total_price": 190 }
]

✔ 场景 4:按 type 去重

Field:type

输出:

复制代码
[
  { "type": "food" },
  { "type": "drink" }
]

📌 7. 完整可导入 Workflow(JSON)

复制以下 JSON → n8n 中 Import → 就能跑通。


🔻 DEMO:包含 Filter + Sort + Aggregate + Unique

复制代码
{
  "nodes": [
    {
      "id": "1",
      "name": "Set Test Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [300, 300],
      "parameters": {
        "values": {
          "json": [
            {
              "name": "items",
              "value": "[{\"customer\":\"A\",\"price\":30,\"type\":\"food\"},{\"customer\":\"A\",\"price\":50,\"type\":\"food\"},{\"customer\":\"A\",\"price\":20,\"type\":\"drink\"},{\"customer\":\"B\",\"price\":100,\"type\":\"food\"},{\"customer\":\"B\",\"price\":90,\"type\":\"drink\"}]"
            }
          ]
        }
      }
    },
    {
      "id": "2",
      "name": "Item Lists - Filter",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [600, 150],
      "parameters": {
        "operation": "filter",
        "rules": {
          "rules": [
            {
              "field": "price",
              "operation": "greater",
              "value": 50
            }
          ]
        }
      }
    },
    {
      "id": "3",
      "name": "Item Lists - Sort",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [600, 300],
      "parameters": {
        "operation": "sort",
        "sortFieldsUi": {
          "sortField": [
            {
              "field": "price",
              "order": "asc"
            }
          ]
        }
      }
    },
    {
      "id": "4",
      "name": "Item Lists - Aggregate",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [600, 450],
      "parameters": {
        "operation": "aggregate",
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "price",
              "operation": "sum",
              "outputFieldName": "total_price"
            }
          ]
        },
        "groupByFields": "customer"
      }
    },
    {
      "id": "5",
      "name": "Item Lists - Unique",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [600, 600],
      "parameters": {
        "operation": "unique",
        "uniqueFields": "type"
      }
    }
  ],
  "connections": {
    "Set Test Data": {
      "main": [
        [
          { "node": "Item Lists - Filter", "type": "main", "index": 0 }
        ],
        [
          { "node": "Item Lists - Sort", "type": "main", "index": 0 }
        ],
        [
          { "node": "Item Lists - Aggregate", "type": "main", "index": 0 }
        ],
        [
          { "node": "Item Lists - Unique", "type": "main", "index": 0 }
        ]
      ]
    }
  }
}

📌 8. 最佳实践(项目中一定要知道)

⭐ 1. 尽量用 Item Lists 代替 Code Node

因为 UI 配置更清晰,可维护性更强。


⭐ 2. 聚合操作尽量写在一个 Item Lists

减少节点数量。


⭐ 3. 排序 → 过滤 → 聚合 顺序很重要

不然你会得到意外结果。


📌 9. 常见踩坑点(避免90%错误)


❌ 错误 1:忘记为 Unique 指定字段

结果:完全不去重。


❌ 错误 2:Aggregate 没指定 groupField

结果:所有数据被合成一条。


❌ 错误 3:Sort 字段不在 JSON 里

结果:节点无法排序 → items 不变。


🎉 总结

想做 用 Item Lists
过滤 JSON 数组 ✔ Filter
排序 ✔ Sort
去重 ✔ Unique
聚合/分组 ✔ Aggregate
截取前N条 ✔ Limit
字段选择 ✔ Pick

Item Lists 是数据清洗几乎必用的节点,掌握后能大幅减少你写 Code 节点的数量。

相关推荐
無间行者23 天前
【笔记】n8n 自动化平台安装部署使用笔记(一)
自动化流程·n8n
無间行者24 天前
【笔记】n8n 新手上路指南(三)
自动化流程·n8n
無间行者25 天前
【笔记】n8n Docker 容器时间与时区同步记录(二)
自动化流程·n8n
HoldBelief1 个月前
安装N8N2.11.2 以及 访问宿主机上的文件
n8n
一马平川的大草原2 个月前
基于n8n构建企业内部知识库
人工智能·知识库·n8n
勇气要爆发2 个月前
2026年想学AI,面对 Dify、Coze、n8n、LangChain 该学哪个?
人工智能·langchain·dify·coze·n8n
呆萌的代Ma2 个月前
N8N(二):示例项目:将表单内容写入到飞书表格中
大模型·飞书·n8n
呆萌的代Ma2 个月前
N8N(一):在Docker中安装N8N
docker·容器·n8n
rs勿忘初心2 个月前
n8n工作流使用问题集合
常见问题·n8n·工作流平台·json解析方法·json参数报错
m_136872 个月前
n8n 启动时报 EACCES permission denied 的完整排查与修复
自动化·n8n