在构建自动化工作流时,你经常会面临这样的问题:如何从众多数据中筛选出真正需要的部分? Filter 节点就是为此而生的!它就像一个智能守门人,只让符合条件的数据通过,其他数据则被过滤掉。这样做不仅能提高工作流的效率,还能避免不必要的 API 调用和成本浪费。
本教程将带你从零开始,深入理解 Filter 节点的核心概念,掌握各种数据类型的比较操作,并通过实战案例学会如何构建多条件的数据筛选流程。
Filter 节点的核心作用:根据条件过滤数据项。符合条件的数据项会被传递到工作流的下一个节点,不符合条件的数据项则被丢弃。

Filter 节点支持以下 6 种数据类型。选择正确的数据类型很重要,因为它决定了你可以使用哪些比较操作。
| 数据类型 | 说明 | 常见应用 |
|---|---|---|
| String(字符串) | 文本数据 | 邮箱、用户名、状态标签 |
| Number(数字) | 整数或小数 | 价格、库存、计数 |
| Date & Time(日期时间) | 时间戳或日期 | 订单时间、截止日期 |
| Boolean(布尔值) | 真/假 | 活跃状态、完成标记 |
| Array(数组) | 列表集合 | 标签列表、订单项数组 |
| Object(对象) | 嵌套结构 | 用户信息、配置对象 |
- exists(存在)
- does not exist(不存在)
- is empty(为空)
- is not empty(非空)
- is equal to(等于)
- is not equal to(不等于)
- contains(包含)
- does not contain(不包含)
- starts with(以...开头)
- does not start with(不以...开头)
- ends with(以...结尾)
- does not end with(不以...结尾)
- matches regex(正则匹配)
- does not match regex(不匹配正则)💡 常见应用:过滤包含特定关键词的邮件标题、检查邮箱域名等
- exists(存在)
- does not exist(不存在)
- is empty(为空)
- is not empty(非空)
- is equal to(等于)
- is not equal to(不等于)
- is greater than(大于)
- is less than(小于)
- is greater than or equal to(大于等于)
- is less than or equal to(小于等于)💡 常见应用:筛选订单金额、库存数量、评分等级
- exists(存在)
- does not exist(不存在)
- is empty(为空)
- is not empty(非空)
- is equal to(等于)
- is not equal to(不等于)
- is after(之后)
- is before(之前)
- is after or equal to(不早于)
- is before or equal to(不晚于)💡 常见应用:获取过去 7 天的订单、检查截止日期是否已过期
- exists(存在)
- does not exist(不存在)
- is empty(为空)
- is not empty(非空)
- is true(为真)
- is false(为假)
- is equal to(等于)
- is not equal to(不等于)💡 常见应用:只处理已验证的用户、筛选已发布的文章
- exists(存在)
- does not exist(不存在)
- is empty(为空)
- is not empty(非空)
- contains(包含)
- does not contain(不包含)
- length equal to(长度等于)
- length not equal to(长度不等于)
- length greater than(长度大于)
- length less than(长度小于)
- length greater than or equal to(长度大于等于)
- length less than or equal to(长度小于等于)💡 常见应用:只处理有标签的商品、检查订单是否包含特定项目
- exists(存在)
- does not exist(不存在)
- is empty(为空)
- is not empty(非空)当你需要同时满足多个条件时使用 AND。只有当所有条件都为真时,数据才能通过。
示例:
当你需要满足任意一个条件时使用 OR。只要有任何一个条件为真,数据就能通过。
示例:
你是一个电商客服团队的经理。每天会收到大量订单邮件,但你只想处理以下类型的订单:
第一步:添加触发器
第二步:添加 Filter 节点
第三步:配置第一个条件
第四步:添加第二个条件
第五步:添加第三个条件
第六步:测试你的 Filter
有时数据可能不完整。使用"exists"或"is not empty"来过滤不完整的记录:
数据类型:String
字段:email
操作:is not empty要获取特定时间内的数据,可使用两个 Filter 节点或多条件:
Filter 1 条件1:created_at is after (今天 - 7天)
Filter 1 条件2:created_at is before (今天)
如果需要复杂的文本匹配,使用正则表达式:
数据类型:String
字段:email
操作:matches regex
值:^[a-zA-Z0-9._-]+@company\.com$这会只匹配公司域名的邮箱。
对于很复杂的逻辑,可以连接多个 Filter 节点:
数据源 → Filter 1(基本有效性检查)→ Filter 2(值范围检查)→ Filter 3(特殊模式检查)→ 后续处理以下是一个完整的可执行工作流,用于自动分发不同等级的订单到相应团队。
此工作流从 Webhook 接收订单数据,然后:
{
"name": "Smart Order Distribution System",
"nodes": [
{
"parameters": {
"path": "webhook",
"authMethod": "none"
},
"name": "Order Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 1,
"position": [100, 300]
},
{
"parameters": {
"conditions": {
"boolean": [],
"number": [
{
"value1": "{{ $json.orderAmount }}",
"condition": ">=",
"value2": 500
}
],
"string": [],
"dateTime": [],
"object": [],
"array": []
}
},
"name": "Filter - VIP Orders (≥ 500)",
"type": "n8n-nodes-base.filter",
"typeVersion": 1,
"position": [400, 100]
},
{
"parameters": {
"conditions": {
"boolean": [],
"number": [
{
"value1": "{{ $json.orderAmount }}",
"condition": ">=",
"value2": 100
},
{
"value1": "{{ $json.orderAmount }}",
"condition": "<",
"value2": 500
}
],
"string": [],
"dateTime": [],
"object": [],
"array": []
}
},
"name": "Filter - Standard Orders (100-499)",
"type": "n8n-nodes-base.filter",
"typeVersion": 1,
"position": [400, 300]
},
{
"parameters": {
"conditions": {
"boolean": [],
"number": [
{
"value1": "{{ $json.orderAmount }}",
"condition": "<",
"value2": 100
}
],
"string": [],
"dateTime": [],
"object": [],
"array": []
}
},
"name": "Filter - Low Value Orders (< 100)",
"type": "n8n-nodes-base.filter",
"typeVersion": 1,
"position": [400, 500]
},
{
"parameters": {
"url": "https://hooks.slack.com/services/YOUR_WEBHOOK_URL",
"method": "POST",
"bodyParametersUi": "keyvalue",
"bodyParameters": {
"parameters": [
{
"name": "text",
"value": "🌟 VIP Order Alert!\nOrder ID: {{ $json.orderId }}\nAmount: {{ $json.orderAmount }}\nCustomer: {{ $json.customerName }}"
}
]
}
},
"name": "Send to Slack - VIP",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [700, 100]
},
{
"parameters": {
"url": "https://hooks.slack.com/services/YOUR_WEBHOOK_URL_STANDARD",
"method": "POST",
"bodyParametersUi": "keyvalue",
"bodyParameters": {
"parameters": [
{
"name": "text",
"value": "📦 Standard Order Received\nOrder ID: {{ $json.orderId }}\nAmount: {{ $json.orderAmount }}\nCustomer: {{ $json.customerName }}"
}
]
}
},
"name": "Send to Slack - Standard",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [700, 300]
},
{
"parameters": {
"url": "https://api.example.com/autoprocess",
"method": "POST",
"bodyParametersUi": "json",
"body": "{\n \"orderId\": \"{{ $json.orderId }}\",\n \"action\": \"auto_fulfill\"\n}"
},
"name": "Auto Process - Low Value",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [700, 500]
}
],
"connections": {
"Order Webhook": {
"main": [
[
{
"node": "Filter - VIP Orders (≥ 500)",
"type": "main",
"index": 0
},
{
"node": "Filter - Standard Orders (100-499)",
"type": "main",
"index": 0
},
{
"node": "Filter - Low Value Orders (< 100)",
"type": "main",
"index": 0
}
]
]
},
"Filter - VIP Orders (≥ 500)": {
"main": [
[
{
"node": "Send to Slack - VIP",
"type": "main",
"index": 0
}
]
]
},
"Filter - Standard Orders (100-499)": {
"main": [
[
{
"node": "Send to Slack - Standard",
"type": "main",
"index": 0
}
]
]
},
"Filter - Low Value Orders (< 100)": {
"main": [
[
{
"node": "Auto Process - Low Value",
"type": "main",
"index": 0
}
]
]
}
}
}┌──────────────┐
│ Order Webhook│
└──────┬───────┘
│
┌───┴───────────────────────┐
│ │
▼ ▼
┌─────────────┐ ┌──────────────┐
│Filter VIP │ │Filter Standard│
│(≥ 500) │ │(100-499) │
└──────┬──────┘ └──────┬───────┘
│ │
▼ ▼
┌─────────────┐ ┌──────────────┐
│Send to Slack│ │Send to Slack │
│VIP Team │ │Standard Team │
└─────────────┘ └──────────────┘使用表达式语法 {{ $json.字段名 }} 或 {{ $node["节点名称"].json.字段名 }}
使用条件:
is empty:检查字段为空is not empty:检查字段非空does not exist:检查字段不存在可以!使用表达式在"值"字段中引用其他节点的数据:{{ $node["前一个节点"].json.比较值 }}
Filter 节点是 n8n 工作流中的关键构件,帮助你:
✅ 提高效率:只处理需要的数据
✅ 降低成本:减少不必要的 API 调用
✅ 增强控制:精确管理数据流向
✅ 支持复杂逻辑:通过 AND/OR 组合实现多条件过滤
[1] sales@company.com: mailto:sales@company.com
[2] 官方文档: https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.filter/
[3] n8n系列教程: https://www.undsky.com/blog/?category=n8n%E6%95%99%E7%A8%8B#