正在加载

定义字段映射

您必须在 _meta/fields.yml 中定义您的 Beat 使用的字段及其映射详细信息。编辑此文件后,运行 make update

fields 数组中定义字段映射

- key: mybeat
  title: mybeat
  description: These are the fields used by mybeat.
  fields:
    - name: last_name
      type: keyword
      required: true
      description: >
        The last name.
    - name: first_name
      type: keyword
      required: true
      description: >
        The first name.
    - name: comment
      type: text
      required: false
      description: >
        Comment made by the user.
  1. name: 字段名称
  2. type: 字段类型。 type 的值可以是 Elasticsearch 中提供的 任何数据类型。如果未指定值,则默认类型为 keyword
  3. required: 是否需要字段值
  4. description: 有关字段内容的一些信息

您可以为每个字段指定其他映射参数。 有关每个参数的更多详细信息,请参阅 Elasticsearch 参考

format
指定字段使用的自定义日期格式。
multi_fields
对于 textkeyword 字段,使用 multi_fields 定义多字段映射。
enabled
是否启用该字段。
analyzer
索引时使用哪个分析器。
search_analyzer
搜索时使用哪个分析器。
norms
适用于 textkeyword 字段。 默认为 false
dynamic
动态字段控制。 可以是 true(默认)、falsestrict 之一。
index
是否应对字段建立索引。
doc_values
是否应为该字段生成 doc values。
copy_to
将字段值复制到哪个字段。
ignore_above
Elasticsearch 忽略(不索引)长度超过指定值的字符串。 当此属性值缺失或为 0 时,将使用 libbeat 的默认值 1024 个字符。 如果该值为 -1,则使用 Elasticsearch 默认值。

例如,您可以使用 copy_to 映射参数在索引时将 last_namefirst_name 字段复制到 full_name 字段中

- key: mybeat
  title: mybeat
  description: These are the fields used by mybeat.
  fields:
    - name: last_name
      type: text
      required: true
      copy_to: full_name
      description: >
        The last name.
    - name: first_name
      type: text
      required: true
      copy_to: full_name
      description: >
        The first name.
    - name: full_name
      type: text
      required: false
      description: >
        The last_name and first_name combined into one field for easy searchability.
  1. last_name 的值复制到 full_name
  2. first_name 的值复制到 full_name

还有一些 Kibana 特定的属性,此处未详细介绍。 这些是:analyzedcountsearchableaggregatablescript。 Kibana 参数也可以使用 patterninput_formatoutput_formatoutput_precisionlabel_templateurl_templateopen_link_in_current_tab 进行描述。

使用文本字段时,可以应用各种选项。 您可以使用默认分析器定义一个简单的文本字段,而不使用任何其他选项,如前面示例所示。

要在使用 text 映射时保留原始关键字值,例如用于聚合或排序,可以使用多字段映射

- key: mybeat
  title: mybeat
  description: These are the fields used by mybeat.
  fields:
    - name: city
      type: text
      multi_fields:
        - name: keyword
          type: keyword
  1. multi_fields: 定义 multi_fields 映射参数。
  2. name: 这是多字段的传统名称。 它可以是任何东西(raw 是另一个常见的选项),但惯例是使用 keyword
  3. type: 指定 keyword 类型以在聚合中使用该字段或对文档进行排序。

有关更多信息,请参阅 Elasticsearch 关于多字段的文档

可以在字段定义中内联定义新的文本分析器或搜索分析器,在字段的映射参数中。

例如,您可以定义一个新的文本分析器,该分析器不会中断连字符名称

- key: mybeat
  title: mybeat
  description: These are the fields used by mybeat.
  fields:
    - name: last_name
      type: text
      required: true
      description: >
        The last name.
      analyzer:
        mybeat_hyphenated_name:
          type: pattern
          pattern: "[\\W&&[^-]]+"
      search_analyzer:
        mybeat_hyphenated_name:
          type: pattern
          pattern: "[\\W&&[^-]]+"
  1. 使用新定义的文本分析器
  2. 定义自定义分析器类型
  3. 指定分析器行为
  4. 搜索时使用相同的分析器

在线定义的自定义分析器的名称不能用于其他文本分析器。 如果重用文本分析器名称,则会检查该分析器的现有实例是否匹配。 建议分析器名称以 beat 名称作为前缀,以避免名称冲突。

有关更多信息,请参阅 Elasticsearch 关于定义自定义文本分析器的文档

© . All rights reserved.