ecs-field-mappings
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseecs-field-mappings
ecs-field-mappings
When to use
使用场景
Use this skill when tasks include:
- adding or modifying files under
data_stream/<stream>/fields/ - populating with ECS field references
ecs.yml - selecting ,
event.kind,event.category, andevent.typevaluesevent.outcome - choosing field and mapping properties (
type,metric_type,dimension, and related options)multi_fields - checking whether a field already exists in ECS before adding custom fields
- troubleshooting mapping validation/build failures from ,
elastic-package check, or pipeline test schema checkselastic-package lint
当您需要完成以下任务时,请使用本技能:
- 添加或修改目录下的文件
data_stream/<stream>/fields/ - 使用ECS字段引用填充
ecs.yml - 选择、
event.kind、event.category和event.type的值event.outcome - 选择字段和映射属性(
type、metric_type、dimension及相关选项)multi_fields - 添加自定义字段前检查该字段是否已存在于ECS中
- 排查、
elastic-package check或管道测试 schema 检查导致的映射验证/构建失败elastic-package lint
ECS dependency configuration
ECS依赖配置
Every package needs at the package root. This file pins the ECS schema version used for field resolution.
_dev/build/build.ymlyaml
dependencies:
ecs:
reference: "git@v9.3.0"This file is required whenever the package has any field file. The scaffold does not generate it — create it manually. If it is missing or uses an outdated version, tests report ECS fields as undefined (e.g., ).
field "destination.ip" is undefined每个包的根目录下都需要文件,该文件用于固定字段解析所使用的ECS schema版本。
_dev/build/build.ymlyaml
dependencies:
ecs:
reference: "git@v9.3.0"只要包包含任何字段文件,该文件就是必填项。脚手架不会自动生成它——需要手动创建。如果缺失或使用过时版本,测试会报告ECS字段未定义(例如:)。
field "destination.ip" is undefinedField files and roles
字段文件与作用
A data stream's directory contains a small set of YAML files with distinct responsibilities:
fields/数据流的目录包含一组职责明确的YAML文件:
fields/base-fields.yml
base-fields.ymlbase-fields.yml
base-fields.ymlFixed routing constants and . All six fields are ECS fields, so each entry uses . Override and where the data stream needs a with a fixed value — the description is inherited from ECS automatically.
@timestampexternal: ecstypevalueconstant_keywordyaml
- name: data_stream.type
external: ecs
- name: data_stream.dataset
external: ecs
- name: data_stream.namespace
external: ecs
- name: event.module
external: ecs
type: constant_keyword
value: <package_name>
- name: event.dataset
external: ecs
type: constant_keyword
value: <package_name>.<stream_name>
- name: '@timestamp'
external: ecsDo not add other fields here. Only these routing constants and belong in .
@timestampbase-fields.yml包含固定路由常量和。这六个字段均为ECS字段,因此每个条目都使用。当数据流需要带固定值的时,可覆盖和——描述会自动从ECS继承。
@timestampexternal: ecsconstant_keywordtypevalueyaml
- name: data_stream.type
external: ecs
- name: data_stream.dataset
external: ecs
- name: data_stream.namespace
external: ecs
- name: event.module
external: ecs
type: constant_keyword
value: <package_name>
- name: event.dataset
external: ecs
type: constant_keyword
value: <package_name>.<stream_name>
- name: '@timestamp'
external: ecs请勿在此添加其他字段。只有这些路由常量和属于。
@timestampbase-fields.ymlconstant_keyword
candidates
constant_keywordconstant_keyword
候选字段
constant_keywordFields that hold a single value for every document in a data stream should use . Beyond the routing constants in , evaluate these:
constant_keywordbase-fields.yml| Field | Why |
|---|---|
| One value per data stream by definition |
| One value per package |
| Fixed per stream ( |
| Fixed per stream |
| Set at deployment, constant within index |
| Package represents one vendor |
| Package represents one product |
When a field is also an ECS field (e.g., ), use with the type override. This inherits the description from ECS and avoids manual duplication. Place the definition in the appropriate field file ( for most ECS fields, for routing constants):
constant_keywordobserver.vendorexternal: ecsecs.ymlbase-fields.ymlyaml
- name: observer.vendor
external: ecs
type: constant_keyword
value: Acme Corpremove_from_sourceconstant_keyword_source_source.excludes对于数据流中每个文档都持有单一值的字段,应使用。除了中的路由常量外,还需评估以下字段:
constant_keywordbase-fields.yml| 字段 | 使用 |
|---|---|
| 根据定义,每个数据流对应一个值 |
| 每个包对应一个值 |
| 每个流固定为 |
| 每个流固定不变 |
| 部署时设置,在索引内保持恒定 |
| 每个包代表一个厂商 |
| 每个包代表一个产品 |
当字段同时也是ECS字段时(例如),请使用并覆盖类型。这会从ECS继承描述,避免手动重复定义。将定义放在合适的字段文件中(大多数ECS字段放在,路由常量放在):
constant_keywordobserver.vendorexternal: ecsecs.ymlbase-fields.ymlyaml
- name: observer.vendor
external: ecs
type: constant_keyword
value: Acme Corpremove_from_sourceconstant_keyword_source_source.excludesecs.yml
ecs.ymlecs.yml
ecs.ymlPopulate this file with every ECS field the pipeline sets. Use only and for each entry — no type, no description. The type is resolved from the ECS schema via .
nameexternal: ecs_dev/build/build.ymlexternal: ecsecs.ymlbase-fields.ymltype: constant_keywordvalue:external: ecsexternal: ecsfields.ymlagent.ymlbeats.ymlyaml
- name: event.kind
external: ecs
- name: event.category
external: ecs
- name: event.type
external: ecs
- name: event.outcome
external: ecs
- name: event.action
external: ecs
- name: source.ip
external: ecs
- name: source.port
external: ecs
- name: destination.ip
external: ecs
- name: user.name
external: ecs
- name: related.ip
external: ecs
- name: related.user
external: ecsWhen attaching extra metadata to an ECS field (for example making a field a TSDB dimension or a constant_keyword with a fixed value), combine with that metadata. The description is inherited from ECS. Place the definition in (or for routing constants):
external: ecsecs.ymlbase-fields.ymlyaml
- name: observer.vendor
external: ecs
type: constant_keyword
value: Acme Corp请在此文件中填入管道设置的所有ECS字段。 每个条目仅使用和——无需指定类型和描述。类型会通过从ECS schema解析得到。
nameexternal: ecs_dev/build/build.yml只要字段名称存在于ECS中,就必须使用(维基参考)。这适用于所有字段文件——、以及任何定义ECS字段的文件。您可以在使用的同时覆盖属性(例如、)——描述会从ECS继承。请勿在、或中使用——这些文件用于定义非ECS字段。
external: ecsecs.ymlbase-fields.ymlexternal: ecstype: constant_keywordvalue:fields.ymlagent.ymlbeats.ymlexternal: ecsyaml
- name: event.kind
external: ecs
- name: event.category
external: ecs
- name: event.type
external: ecs
- name: event.outcome
external: ecs
- name: event.action
external: ecs
- name: source.ip
external: ecs
- name: source.port
external: ecs
- name: destination.ip
external: ecs
- name: user.name
external: ecs
- name: related.ip
external: ecs
- name: related.user
external: ecs当为ECS字段附加额外元数据时(例如将字段设为TSDB维度或带固定值的constant_keyword),请将与该元数据结合使用。描述会从ECS继承。将定义放在中(路由常量放在):
external: ecsecs.ymlbase-fields.ymlyaml
- name: observer.vendor
external: ecs
type: constant_keyword
value: Acme Corpfields.yml
fields.ymlfields.yml
fields.ymlIntegration-specific custom (non-ECS) fields only. Use a nested hierarchy for the vendor namespace:
groupyaml
- name: acme.firewall
type: group
fields:
- name: rule_id
type: keyword
- name: policy_name
type: keyword
- name: bytes_in
type: long
unit: byte
metric_type: gaugeGroups do not need to be declared as — defining a with nested is sufficient. The object structure is implicit.
type: objectgroupfields仅包含集成专属的自定义(非ECS)字段。针对厂商命名空间使用嵌套的层级结构:
groupyaml
- name: acme.firewall
type: group
fields:
- name: rule_id
type: keyword
- name: policy_name
type: keyword
- name: bytes_in
type: long
unit: byte
metric_type: gauge无需将组声明为——定义带嵌套的即可。对象结构是隐式的。
type: objectfieldsgrouplabels.*
exception
labels.*labels.*
例外情况
labels.*labelstype: objectobject_type: keywordlabels.*Use for simple keyword flags or integration-internal markers (e.g., ). Use the vendor namespace for structured or nested data from an upstream source.
labels.*labels.is_ioc_transform_sourcelabelstype: objectobject_type: keywordlabels.*对于简单的关键字标记或集成内部标识(例如),请使用。对于上游来源的结构化或嵌套数据,请使用厂商命名空间。
labels.is_ioc_transform_sourcelabels.*Flags vs structured data
标记与结构化数据
Boolean flags and simple tags can live flat under the vendor group:
yaml
- name: acme.firewall
type: group
fields:
- name: is_encrypted
type: boolean
- name: policy_name
type: keywordStructured data from the source should use sub-groups for logical hierarchy:
yaml
- name: acme.firewall
type: group
fields:
- name: rule
type: group
fields:
- name: id
type: keyword
- name: name
type: keyword
- name: action
type: keyword布尔标记和简单标签可以直接放在厂商组下:
yaml
- name: acme.firewall
type: group
fields:
- name: is_encrypted
type: boolean
- name: policy_name
type: keyword来源的结构化数据应使用子组构建逻辑层级:
yaml
- name: acme.firewall
type: group
fields:
- name: rule
type: group
fields:
- name: id
type: keyword
- name: name
type: keyword
- name: action
type: keywordagent.yml
agent.ymlagent.yml
agent.ymlNon-ECS fields populated by the Elastic Agent or Beats framework but not covered by ECS. Include only when the input type emits these fields. Typical fields: , , , , , , .
cloud.image.idcloud.instance.idhost.containerizedhost.os.buildhost.os.codenameinput.typelog.offsetSee for full YAML samples.
references/root-and-core-fields.md由Elastic Agent或Beats框架填充但未被ECS覆盖的非ECS字段。仅当输入类型会输出这些字段时才包含。典型字段包括:、、、、、、。
cloud.image.idcloud.instance.idhost.containerizedhost.os.buildhost.os.codenameinput.typelog.offset完整YAML示例请参见。
references/root-and-core-fields.mdbeats.yml
beats.ymlbeats.yml
beats.ymlFilebeat/Beats-specific fields not covered by ECS. Minimal form contains and . Some inputs also emit or sub-fields.
input.typelog.offsetlog.flagslog.file.*See for full YAML samples.
references/root-and-core-fields.md未被ECS覆盖的Filebeat/Beats专属字段。最简形式包含和。部分输入还会输出或子字段。
input.typelog.offsetlog.flagslog.file.*完整YAML示例请参见。
references/root-and-core-fields.mdECS field selection
ECS字段选择
Prefer ECS fields whenever semantics match. If no ECS field exists for the data, add it under the package namespace in .
fields.yml只要语义匹配,优先使用ECS字段。如果ECS中没有对应数据的字段,请在的包命名空间下添加该字段。
fields.ymlCategorization quick reference
分类速查表
| Field | Type | Notes |
|---|---|---|
| keyword | Highest-level classification. |
| keyword[] | Broad domain buckets — always an array. |
| keyword[] | Sub-buckets within category — always an array. |
| keyword | |
- :
event.kind,alert,asset,enrichment,event,metric,pipeline_error,signalstate - :
event.category,api,authentication,configuration,database,driver,email,file,host,iam,intrusion_detection,library,malware,network,package,process,registry,session,threat,vulnerabilityweb - :
event.type,access,admin,allowed,change,connection,creation,deletion,denied,device,end,error,group,indicator,info,installation,protocol,startuser
Decision workflow:
- :
event.kindfor normal logs,eventfor measurements,metricfor snapshots,stateinpipeline_erroron_failure - : one or more values (array) for the broad domain
event.category - : one or more values (array) for operation style
event.type - : only when a clear success/failure/unknown applies; omit for informational/metric events
event.outcome - If no allowed value fits, leave the field empty — do not invent values
Use for source-specific verbs (, , ).
event.actionblockeddroppedauthenticatedSee for full worked examples.
references/categorization-cheatsheet.md| 字段 | 类型 | 说明 |
|---|---|---|
| keyword | 最高层级分类。 |
| keyword[] | 宽泛领域分组——始终为数组。 |
| keyword[] | 分类下的子分组——始终为数组。 |
| keyword | |
- :
event.kind,alert,asset,enrichment,event,metric,pipeline_error,signalstate - :
event.category,api,authentication,configuration,database,driver,email,file,host,iam,intrusion_detection,library,malware,network,package,process,registry,session,threat,vulnerabilityweb - :
event.type,access,admin,allowed,change,connection,creation,deletion,denied,device,end,error,group,indicator,info,installation,protocol,startuser
决策流程:
- :普通日志用
event.kind,测量数据用event,快照用metric,state中用on_failurepipeline_error - :为宽泛领域设置一个或多个值(数组)
event.category - :为操作类型设置一个或多个值(数组)
event.type - :仅当存在明确的成功/失败/未知结果时设置;信息类/指标类事件可省略
event.outcome - 如果没有合适的允许值,请留空字段——不要自行创建值
针对来源特定的动词(如、、),请使用。
blockeddroppedauthenticatedevent.action完整示例请参见。
references/categorization-cheatsheet.mdTimestamp fields
时间戳字段
ECS defines several timestamp fields with distinct semantics. Use them correctly:
| Field | When to use | Set by |
|---|---|---|
| The primary event timestamp. Parse from the source event data. Required. | Integration pipeline |
| When the event was first created or recorded by the source system, if different from | Integration pipeline |
| When an activity or period began (e.g., session start, connection start). | Integration pipeline |
| When an activity or period ended (e.g., session end, connection close). | Integration pipeline |
| When the event was ingested into Elasticsearch. | Elasticsearch (outside the integration) |
event.ingestedsetevent.ingestedWhen the source data contains multiple timestamps:
- Map the primary event timestamp to .
@timestamp - If another timestamp represents when the event was first recorded/created, map it to .
event.created - If timestamps represent the start or end of an activity, map them to and
event.start.event.end - If a timestamp does not match the semantics of any of the above, map it to a custom field under the vendor namespace with in
type: date.fields.yml
ECS定义了多个具有不同语义的时间戳字段,请正确使用:
| 字段 | 使用场景 | 设置方 |
|---|---|---|
| 主事件时间戳。从源事件数据中解析。必填。 | 集成管道 |
| 当事件首次被源系统创建或记录的时间与 | 集成管道 |
| 活动或周期开始的时间(例如会话开始、连接建立)。 | 集成管道 |
| 活动或周期结束的时间(例如会话结束、连接关闭)。 | 集成管道 |
| 事件被Elasticsearch摄入的时间。 | Elasticsearch(集成外部) |
event.ingestedevent.ingestedset当源数据包含多个时间戳时:
- 将主事件时间戳映射到。
@timestamp - 如果另一个时间戳表示事件首次记录/创建的时间,将其映射到。
event.created - 如果时间戳表示活动的开始或结束,将其映射到和
event.start。event.end - 如果时间戳不符合上述任何语义,请在中将其映射到厂商命名空间下的自定义字段,并设置
fields.yml。type: date
Reusable fieldset nesting rules
可复用字段集嵌套规则
Some ECS field sets must be nested under a parent entity — they are not valid at document root.
geoclient.geodestination.geohost.geoobserver.geoserver.geosource.geothreat.indicator.geoRoot-level fields are not recognized and will appear unmapped. Always set on the processor:
geo.*target_fieldgeoipyaml
- geoip:
field: source.ip
target_field: source.geo
ignore_missing: trueasclient.asdestination.asserver.assource.asWhen using for geolocation, always also perform an ASN lookup using and rename the raw output fields to ECS names. The ASN processor outputs and , which must be renamed to and :
geoipGeoLite2-ASN.mmdbgeoipasnorganization_nameas.numberas.organization.nameyaml
- geoip:
database_file: GeoLite2-ASN.mmdb
field: source.ip
target_field: source.as
properties:
- asn
- organization_name
ignore_missing: true
- rename:
field: source.as.asn
target_field: source.as.number
ignore_missing: true
- rename:
field: source.as.organization_name
target_field: source.as.organization.name
ignore_missing: trueSee the skill → for the full geo+ASN pattern with both source and destination.
ingest-pipelinesreferences/processor-cookbook.mdoshost.osobserver.osuser_agent.os部分ECS字段集必须嵌套在父实体下——不能直接放在文档根节点。
geoclient.geodestination.geohost.geoobserver.geoserver.geosource.geothreat.indicator.geo根节点级别的字段不会被识别,会显示为未映射。请始终在处理器上设置:
geo.*geoiptarget_fieldyaml
- geoip:
field: source.ip
target_field: source.geo
ignore_missing: trueasclient.asdestination.asserver.assource.as使用进行地理定位时,还需使用执行ASN查询,并将原始输出字段重命名为ECS名称。 ASN处理器输出和,必须将其重命名为和:
geoipGeoLite2-ASN.mmdbgeoipasnorganization_nameas.numberas.organization.nameyaml
- geoip:
database_file: GeoLite2-ASN.mmdb
field: source.ip
target_field: source.as
properties:
- asn
- organization_name
ignore_missing: true
- rename:
field: source.as.asn
target_field: source.as.number
ignore_missing: true
- rename:
field: source.as.organization_name
target_field: source.as.organization.name
ignore_missing: true包含源端和目的端的完整geo+ASN模式,请参见技能 → 。
ingest-pipelinesreferences/processor-cookbook.mdoshost.osobserver.osuser_agent.osNested (array-of-objects) ECS fields
嵌套(对象数组)ECS字段
Some ECS fields use , meaning they hold an array of objects where each object groups related sub-fields together. The pipeline must produce this structure — do not flatten these into parallel scalar arrays.
type: nestedECS fields that use type:
nested| Field | Contains |
|---|---|
| |
| |
| |
| |
| |
| |
Anti-pattern — parallel arrays (WRONG):
json
{
"email": {
"attachments": {
"file": {
"name": ["a.pdf", "b.pdf"],
"size": [1024, 2048]
}
}
}
}This loses the association between each attachment's name and size. Queries cannot isolate individual objects.
Correct — array of objects:
json
{
"email": {
"attachments": [
{ "file": { "name": "a.pdf", "size": 1024 } },
{ "file": { "name": "b.pdf", "size": 2048 } }
]
}
}ecs.ymlnestedexternal: ecsemail.attachments.file.nameyaml
- name: email.attachments
external: ecsPipeline construction: when source data delivers attachment metadata as separate parallel arrays (e.g., a comma-separated list of filenames and a separate list of sizes), use a processor to zip them into an array of objects. See → for array construction patterns and → Foreach semantics for iterating over array elements.
scriptingest-pipelinesreferences/painless-patterns.mdreferences/processor-cookbook.mdyaml
- script:
tag: build_email_attachments
description: Build email.attachments as array of nested objects from parallel source arrays.
lang: painless
if: ctx.json?.file_names instanceof List && ctx.json?.file_sizes instanceof List
source: |-
def names = ctx.json.file_names;
def sizes = ctx.json.file_sizes;
int len = Math.min(names.size(), sizes.size());
def attachments = new ArrayList(len);
for (int i = 0; i < len; i++) {
def attachment = new HashMap();
def file = new HashMap();
file.put('name', names.get(i));
file.put('size', sizes.get(i));
attachment.put('file', file);
attachments.add(attachment);
}
ctx.email = ctx.email ?: [:];
ctx.email.attachments = attachments;When source data already delivers each attachment as a separate object (e.g., a JSON array of attachment objects), no zipping is needed — use or with to place the array at directly.
renamesetcopy_fromemail.attachments部分ECS字段使用,表示它们存储对象数组,其中每个对象将相关子字段分组在一起。管道必须生成此结构——请勿将其扁平化为并行标量数组。
type: nested使用类型的ECS字段:
nested| 字段 | 包含内容 |
|---|---|
| |
| |
| |
| |
| |
| |
反模式——并行数组(错误):
json
{
"email": {
"attachments": {
"file": {
"name": ["a.pdf", "b.pdf"],
"size": [1024, 2048]
}
}
}
}这会丢失每个附件名称与大小之间的关联。查询无法隔离单个对象。
正确方式——对象数组:
json
{
"email": {
"attachments": [
{ "file": { "name": "a.pdf", "size": 1024 } },
{ "file": { "name": "b.pdf", "size": 2048 } }
]
}
}ecs.ymlexternal: ecsnestedemail.attachments.file.nameyaml
- name: email.attachments
external: ecs管道构建: 当源数据将附件元数据作为单独的并行数组传递时(例如逗号分隔的文件名列表和单独的大小列表),请使用处理器将它们合并为对象数组。数组构建模式请参见 → ,遍历数组元素请参见 → Foreach语义。
scriptingest-pipelinesreferences/painless-patterns.mdreferences/processor-cookbook.mdyaml
- script:
tag: build_email_attachments
description: Build email.attachments as array of nested objects from parallel source arrays.
lang: painless
if: ctx.json?.file_names instanceof List && ctx.json?.file_sizes instanceof List
source: |-
def names = ctx.json.file_names;
def sizes = ctx.json.file_sizes;
int len = Math.min(names.size(), sizes.size());
def attachments = new ArrayList(len);
for (int i = 0; i < len; i++) {
def attachment = new HashMap();
def file = new HashMap();
file.put('name', names.get(i));
file.put('size', sizes.get(i));
attachment.put('file', file);
attachments.add(attachment);
}
ctx.email = ctx.email ?: [:];
ctx.email.attachments = attachments;当源数据已将每个附件作为单独对象传递时(例如附件对象的JSON数组),无需合并——使用或带的将数组直接放置在即可。
renamecopy_fromsetemail.attachmentsCustom field types
自定义字段类型
For non-ECS fields in :
fields.yml- for identifiers and exact-match strings
keyword - for fixed values (dataset/module constants)
constant_keyword - ,
long,doublefor metrics and numeric valuesscaled_float - /
datefor timestamps (date_nanosonly when sub-millisecond precision is truly needed)date_nanos - for IP addresses
ip - for true/false (avoid string booleans in pipelines)
boolean - for lat/lon coordinates
geo_point - with nested
groupfor logical structure — no need to separately declare intermediatefieldsnodesobject - for arbitrary key/value blobs with unknown keys
flattened - for arrays of objects requiring per-object query isolation (heavier than group)
nested - /
textfor full-text content; add amatch_only_textsub-field viakeywordwhen aggregation is also neededmulti_fields
Useful properties on numeric fields: ( or ), (e.g., , , ), for low-cardinality TSDB fields.
metric_typegaugecounterunitbytepercentmsdimensionSee for the full type reference.
references/mapping-type-matrix.md对于中的非ECS字段:
fields.yml- :用于标识符和精确匹配字符串
keyword - :用于固定值(数据集/模块常量)
constant_keyword - 、
long、double:用于指标和数值scaled_float - /
date:用于时间戳(仅当确实需要亚毫秒精度时使用date_nanos)date_nanos - :用于IP地址
ip - :用于布尔值(管道中避免使用字符串形式的布尔值)
boolean - :用于经纬度坐标
geo_point - 带嵌套
group:用于逻辑结构——无需单独声明中间fields节点object - :用于键未知的任意键值 blob
flattened - :用于需要按对象隔离查询的对象数组(比group开销更大)
nested - /
text:用于全文内容;当需要聚合时,通过match_only_text添加multi_fields子字段keyword
数值字段的有用属性:(或)、(例如、、)、低基数TSDB字段的。
metric_typegaugecounterunitbytepercentmsdimension完整类型参考请参见。
references/mapping-type-matrix.mdField naming conventions
字段命名规范
| Rule | DO | DON'T |
|---|---|---|
| Use snake_case | | |
| Use lowercase | | |
| No asterisks in names | | |
| Use groups for hierarchy | | |
Field names must never contain literal characters. An asterisk in a field name is almost always a copy-paste error from documentation or wildcard patterns. Use a with known subfields or for dynamic keys instead.
*groupflattened| 规则 | 正确做法 | 错误做法 |
|---|---|---|
| 使用蛇形命名法 | | |
| 使用小写 | | |
| 名称中不含星号 | | |
| 使用组实现层级 | 嵌套group形式的 | 扁平点分形式的 |
字段名称绝不能包含字面意义上的字符。字段名称中的星号几乎总是来自文档或通配符模式的复制粘贴错误。请改用带已知子字段的或用于动态键的。
*groupflattenedDotted field names vs nested groups
点分字段名称 vs 嵌套组
Both styles are valid in field files:
yaml
undefined两种格式在字段文件中均有效:
yaml
undefinedDotted (flat) — common for ECS fields in ecs.yml
点分(扁平)——ecs.yml中ECS字段常用格式
- name: source.ip external: ecs
- name: source.ip external: ecs
Nested group — common for custom fields
嵌套组——自定义字段常用格式
- name: acme.firewall
type: group
fields:
- name: rule_id type: keyword
Pipeline expected output (`*-expected.json`) always uses nested object form regardless of how the source data represented the field. A source `"host.name": "myhost"` produces `{"host": {"name": "myhost"}}` in the output.
When source data contains literal dotted keys that Elasticsearch would otherwise expand, use `dot_expander`:
```yaml
- dot_expander:
field: "*"
override: true- name: acme.firewall
type: group
fields:
- name: rule_id type: keyword
管道预期输出(`*-expected.json`)始终使用嵌套对象形式,无论源数据如何表示该字段。源数据中的`"host.name": "myhost"`在输出中会变为`{"host": {"name": "myhost"}}`。
当源数据包含Elasticsearch会自动展开的字面点分键时,请使用`dot_expander`:
```yaml
- dot_expander:
field: "*"
override: truegeo_point field handling
geo_point字段处理
In pipeline test expected outputs, fields appear as objects with and keys:
geo_pointlatlonjson
"source": {
"geo": {
"location": { "lat": 51.5142, "lon": -0.0931 },
"city_name": "London",
"country_iso_code": "GB"
}
}These sub-fields do not need entries in — they are part of the type mapping. Only the field (type ) needs to be in for non-standard parent prefixes where does not apply.
fields.ymlgeo_point*.geo.locationgeo_pointecs.ymlecs@mappings在管道测试预期输出中,字段显示为带和键的对象:
geo_pointlatlonjson
"source": {
"geo": {
"location": { "lat": 51.5142, "lon": -0.0931 },
"city_name": "London",
"country_iso_code": "GB"
}
}这些子字段无需在中添加条目——它们是类型映射的一部分。对于不适用的非标准父前缀,仅需在中添加字段(类型为)。
fields.ymlgeo_pointecs@mappingsecs.yml*.geo.locationgeo_pointCommon pipeline categorization patterns
常见管道分类模式
Web access
Web访问
yaml
- set:
field: event.kind
value: event
- append:
field: event.category
value: web
- append:
field: event.type
value: accessyaml
- set:
field: event.kind
value: event
- append:
field: event.category
value: web
- append:
field: event.type
value: accessOutcome from HTTP status
基于HTTP状态的结果
yaml
- set:
field: event.outcome
value: success
if: "ctx?.http?.response?.status_code != null && ctx.http.response.status_code < 400"
- set:
field: event.outcome
value: failure
if: "ctx?.http?.response?.status_code != null && ctx.http.response.status_code >= 400"yaml
- set:
field: event.outcome
value: success
if: "ctx?.http?.response?.status_code != null && ctx.http.response.status_code < 400"
- set:
field: event.outcome
value: failure
if: "ctx?.http?.response?.status_code != null && ctx.http.response.status_code >= 400"Pipeline error fallback
管道错误回退
yaml
on_failure:
- set:
field: event.kind
value: pipeline_erroryaml
on_failure:
- set:
field: event.kind
value: pipeline_errorTroubleshooting: "field X is undefined" for ECS fields
故障排查:ECS字段提示“field X is undefined”
When tests report for standard ECS fields:
field "destination.ip" is undefined- Check exists at the package root
_dev/build/build.yml - Check is set (use
dependencies.ecs.reference)git@v9.3.0 - Check the field is listed in with
ecs.ymlexternal: ecs
Fix the root cause. Do not work around it by:
- Adding ECS fields with full type definitions to without
fields.ymlexternal: ecs - Skipping and defining ECS field types/descriptions manually
external: ecs
Exception: Custom (non-ECS) fields reported as undefined must be defined in .
fields.yml当测试针对标准ECS字段报告时:
field "destination.ip" is undefined- 检查包根目录下是否存在
_dev/build/build.yml - 检查是否设置了(建议使用
dependencies.ecs.reference)git@v9.3.0 - 检查该字段是否在中列出并使用
ecs.ymlexternal: ecs
修复根本原因,请勿通过以下方式规避:
- 在中添加不带
fields.yml的完整ECS字段类型定义external: ecs - 跳过并手动定义ECS字段类型/描述
external: ecs
例外情况: 报告为未定义的自定义(非ECS)字段必须在中定义。
fields.ymlCommon failure patterns
常见失败模式
- missing — all ECS fields reported undefined; create with
_dev/build/build.ymldependencies.ecs.reference - outdated ECS version in — fields from newer ECS versions undefined; update reference to
build.ymlgit@v9.3.0 - ECS field set in pipeline but missing from — field is undefined in test schema validation; add it to
ecs.ymlecs.yml - ECS field defined without — descriptions and types diverge from ECS; always use
external: ecsfor ECS fields, with overrides as neededexternal: ecs - on non-numeric field — lint error
metric_type - at document root — unmapped; always nest under a parent entity
geo.* - or
event.categoryset as scalar — must useevent.typeprocessor, notappendset - ECS field mapped as parallel arrays —
nested,email.attachments, and similarthreat.enrichmentsfields must be arrays of objects, not objects with parallel scalar arrays; see the Nested (array-of-objects) ECS fields section abovenested
- 缺失— 所有ECS字段均报告未定义;创建该文件并设置
_dev/build/build.ymldependencies.ecs.reference - 中ECS版本过时 — 新版本ECS中的字段未定义;将引用更新为
build.ymlgit@v9.3.0 - 管道中设置了ECS字段但未在中列出 — 测试schema验证时字段未定义;将其添加到
ecs.ymlecs.yml - ECS字段定义未使用— 描述和类型与ECS不一致;ECS字段请始终使用
external: ecs,必要时可覆盖属性external: ecs - 非数值字段设置— 代码检查错误
metric_type - 位于文档根节点 — 未映射;请始终嵌套在父实体下
geo.* - 或
event.category设置为标量 — 必须使用event.type处理器,而非appendset - ECS字段映射为并行数组 —
nested、email.attachments及类似threat.enrichments字段必须是对象数组,而非带并行标量数组的对象;请参见上方的嵌套(对象数组)ECS字段部分nested
Validation loop
验证循环
bash
elastic-package lint
elastic-package check
elastic-package test pipeline --data-streams <stream>bash
elastic-package lint
elastic-package check
elastic-package test pipeline --data-streams <stream>References
参考资料
references/mapping-type-matrix.mdreferences/categorization-cheatsheet.mdreferences/root-and-core-fields.mdreferences/fieldset-links.md- ECS field reference
references/mapping-type-matrix.mdreferences/categorization-cheatsheet.mdreferences/root-and-core-fields.mdreferences/fieldset-links.md- ECS字段参考