跳到正文

opensearch ​

opensearch source 插件用于从 OpenSearch 集群、旧版 Elasticsearch 集群、Amazon OpenSearch Service 域或 Amazon OpenSearch Serverless 集合读取索引。

该插件支持 OpenSearch 2.x 和 Elasticsearch 7.x。

用法 ​

要使用具有最低必需设置的 opensearch source,请将以下配置添加到 pipeline.yaml 文件:

yaml
opensearch-source-pipeline:
 source:
  opensearch:
    hosts: [ "https://localhost:9200" ]
    username: "username"
    password: "password"
 ...

要使用具有所有配置设置(包括 indices、scheduling、search_options 和 connection)的 opensearch source,请将以下示例添加到 pipeline.yaml 文件:

yaml
opensearch-source-pipeline:
  source:
    opensearch:
      hosts: [ "https://localhost:9200" ]
      username: "username"
      password: "password"
      indices:
        include:
          - index_name_regex: "test-index-.*"
        exclude:
          - index_name_regex: "\..*"
      scheduling:
        interval: "PT1H"
        index_read_count: 2
        start_time: "2023-06-02T22:01:30.00Z"
      search_options:
        search_context_type: "none"
        batch_size: 1000
      connection:
        insecure: false
        cert: "/path/to/cert.crt"
  ...

Amazon OpenSearch Service ​

可以通过传递具有域访问权限的 sts_role_arn 为 Amazon OpenSearch Service 域配置 opensearch source,如以下示例所示:

yaml
opensearch-source-pipeline:
  source:
    opensearch:
      hosts: [ "https://search-my-domain-soopywaovobopgs8ywurr3utsu.us-east-1.es.amazonaws.com" ]
      aws:
        region: "us-east-1"
        sts_role_arn: "arn:aws:iam::123456789012:role/my-domain-role"
  ...

Amazon OpenSearch Serverless ​

可以通过将 serverless 选项设置为 true 来使用 Amazon OpenSearch Serverless 配置 opensearch source,如以下示例所示:

yaml
    - opensearch:
        hosts: [ 'https://1234567890abcdefghijkl.us-west-2.aoss.amazonaws.com' ]
        aws:
          sts_role_arn: 'arn:aws:iam::123456789012:role/my-domain-role'
          region: 'us-west-2'
          serverless: true

使用元数据 ​

当 opensearch source 从集群中的文档构造 Data Prepper 事件时,文档索引以 opensearch-index 键存储在 EventMetadata 中,document_id 以 opensearch-document_id 作为键存储在 EventMetadata 中。这允许基于索引或 document_id 进行条件路由。以下示例管道配置将事件发送到 opensearch sink,并使用与源集群中相同的索引和 document_id 作为目标集群:

yaml
opensearch-migration-pipeline:
  source:
    opensearch:
      hosts: [ "https://source-cluster:9200" ]
      username: "username"
      password: "password"
  sink:
    - opensearch:
        hosts: [ "https://sink-cluster:9200" ]
        username: "username"
        password: "password"
        document_id: "${getMetadata(\"opensearch-document_id\")}"
        index: "${getMetadata(\"opensearch-index\"}"

配置选项 ​

下表描述了可以为 opensearch source 配置的选项。

选项是否必需类型描述
hosts是列表要写入的 OpenSearch 主机列表,例如 ["https://localhost:9200", "https://remote-cluster:9200"]。
username否字符串HTTP 基本身份验证的用户名。从 Data Prepper 2.5 开始,如果应用了 AWS secrets 引用,此设置可以在运行时刷新。
password否字符串HTTP 基本身份验证的密码。从 Data Prepper 2.5 开始,如果应用了 AWS secrets 引用,此设置可以在运行时刷新。
disable_authentication否布尔值是否禁用身份验证。默认为 false。
aws否对象AWS 配置。有关更多信息,请参阅 aws。
acknowledgments否布尔值当为 true 时,启用 opensearch source 在 OpenSearch sink 接收事件时接收端到端确认。默认为 false。
connection否对象连接配置。有关更多信息,请参阅连接。
indices否对象过滤处理哪些索引的配置。默认为所有索引,包括系统索引。有关更多信息,请参阅索引。
scheduling否对象调度配置。有关更多信息,请参阅调度。
search_options否对象source 执行的搜索选项列表。有关更多信息,请参阅搜索选项。
serverless否布尔值确定 OpenSearch 后端是否为 Amazon OpenSearch Serverless。当 opensearch source 的目标是 Amazon OpenSearch Serverless 集合时,将此值设置为 true。默认为 false。
serverless_options否对象当 opensearch source 的后端设置为 Amazon OpenSearch Serverless 时可用的网络配置选项。有关更多信息,请参阅 Serverless 选项。

Serverless 选项 ​

以下选项可以在 serverless_options 对象中使用。

选项是否必需类型描述
network_policy_name是字符串要创建的网络策略的名称。
collection_name是字符串要配置的 Amazon OpenSearch Serverless 集合的名称。
vpce_id是字符串source 连接的虚拟私有云 (VPC) 端点。

调度 ​

scheduling 配置允许用户根据 index_read_count 和重新计数时间 interval 配置源中如何重新处理索引。

例如,将 index_read_count 设置为 3,interval 为 1h,将导致所有索引被重新处理 3 次,间隔 1 小时。默认情况下,索引只处理一次。

在 scheduling 配置下使用以下选项。

选项是否必需类型描述
index_read_count否整数每个索引将被处理的次数。默认为 1。
interval否字符串确定重新处理之间时间量的间隔。支持 ISO 8601 表示法字符串,如 "PT20.345S" 或 "PT15M",以及秒 ("60s") 和毫秒 ("1500ms") 的简单表示法字符串。默认为 8h。
start_time否字符串处理应开始的时间。source 在此时间之前不会开始处理。字符串必须是 ISO 8601 格式,如 2007-12-03T10:15:30.00Z。默认选项立即开始处理。

indices ​

以下选项帮助 opensearch source 使用正则表达式模式确定从源集群处理哪些索引。只有当索引匹配 include 设置下的 index_name_regex 模式之一且不匹配 exclude 设置下的任何模式时,才会处理该索引。

选项是否必需类型描述
include否对象数组指定将处理哪些索引的索引配置模式列表。
exclude否对象数组指定不会处理哪些索引的索引配置模式列表。例如,你可以指定 \..* 的 index_name_regex 模式来排除系统索引。

在 include 和 exclude 选项下使用以下设置来指示索引的正则表达式模式。

选项是否必需类型描述
index_name_regex是正则表达式字符串用于匹配索引的正则表达式模式。

search_options ​

在 search_options 配置下使用以下设置。

选项是否必需类型描述
batch_size否整数从 OpenSearch 分页时读取的文档数。默认为 1000。
search_context_type否枚举在索引上使用的搜索/分页类型的覆盖。可以是 point_in_time)、scroll 或 none。none 选项将使用 search_after 参数。有关更多信息,请参阅默认搜索行为。

默认搜索行为 ​

默认情况下,opensearch source 将查找集群版本和发行版以确定使用哪个 search_context_type。对于支持 Point in Time 的版本和发行版,将使用 point_in_time。 如果集群不支持 point_in_time,则将使用 scroll。对于 Amazon OpenSearch Serverless 集合,将使用 search_after,因为集合既不支持 point_in_time 也不支持 scroll。

连接 ​

在 connection 配置下使用以下设置。

选项是否必需类型描述
cert否字符串当集群使用 OpenSearch Security 插件时的安全证书路径,例如 "config/root-ca.pem"。
insecure否布尔值是否验证 SSL 证书。如果设置为 true,则禁用证书颁发机构 (CA) 证书验证并发送不安全的 HTTP 请求。默认为 false。

AWS ​

设置 aws 服务身份验证时使用以下选项。

选项是否必需类型描述
region否字符串用于凭证的 AWS 区域。默认为确定区域的标准 SDK 行为。
sts_role_arn否字符串用于 Amazon OpenSearch Service 和 Amazon OpenSearch Serverless 请求的 AWS Security Token Service (AWS STS) 角色。默认为 null,它将使用凭证的标准 SDK 行为。
serverless否布尔值从 Amazon OpenSearch Serverless 集合处理时应设置为 true。默认为 false。

指标 ​

opensearch source 包含以下指标。

计数器 ​

  • documentsProcessed:测量 opensearch source 插件处理的文档总数。
  • indicesProcessed:测量 opensearch source 插件处理的索引总数。
  • processingErrors:测量 opensearch source 插件产生的索引处理错误总数。
  • credentialsChanged:测量 opensearch source 刷新基本凭证(用户名/密码)的次数。
  • clientRefreshErrors:测量由于 opensearch source 刷新基本凭证而生成新客户端时遇到的错误数。

计时器 ​

  • indexProcessingTime:测量 opensearch source 插件索引处理延迟(以秒为单位)。

分布摘要 ​

  • bytesReceived:测量 opensearch source 插件接收的传入文档的大小分布(以字节为单位)。
  • bytesProcessed:测量 opensearch source 插件成功处理的传入文档的大小分布(以字节为单位)。

OpenSearch 集群安全 ​

要使用 opensearch source 插件从 OpenSearch 集群提取数据,你必须在管道配置中指定用户名和密码。以下示例 pipeline.yaml 文件演示了如何指定默认的管理员安全凭证:

yaml
source:
  opensearch:
    username: "admin"
    password: "admin"
  ...

Amazon OpenSearch Service 域安全 ​

opensearch source 插件可以从使用 AWS Identity and Access Management (IAM) 进行安全验证的 Amazon OpenSearch Service 域提取数据。该插件使用默认的 Amazon OpenSearch Service 凭证链。使用 AWS Command Line Interface (AWS CLI) 运行 aws configure 来设置凭证。

确保配置的凭证具有所需的 IAM 权限。以下域访问策略显示了最低必需权限:

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<AccountId>:user/data-prepper-user"
      },
      "Action": "es:ESHttpGet",
      "Resource": [
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/",
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/_cat/indices",
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/_search",
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/_search/scroll",
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/*/_search"
      ]
    },
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<AccountId>:user/data-prepper-user"
      },
      "Action": "es:ESHttpPost",
      "Resource": [
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/*/_search/point_in_time",
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/*/_search/scroll"
      ]
    },
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::<AccountId>:user/data-prepper-user"
      },
      "Action": "es:ESHttpDelete",
      "Resource": [
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/_search/point_in_time",
        "arn:aws:es:us-east-1:<AccountId>:domain/<domain-name>/_search/scroll"
      ]
    }
  ]
}

有关如何配置域访问策略的说明,请参阅 Amazon OpenSearch Service 文档中的基于资源的策略。

OpenSearch Serverless 集合安全 ​

opensearch source 插件可以从 Amazon OpenSearch Serverless 集合接收数据。

WARNING

你无法从使用虚拟私有云 (VPC) 访问的集合读取数据。集合必须可从公共网络访问。

创建管道角色 ​

要使用 OpenSearch Serverless 集合安全,请创建管道将承担的 IAM 角色以从集合读取。该角色必须具有以下最低权限:

json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "aoss:APIAccessAll"
            ],
            "Resource": "arn:aws:aoss:*:<AccountId>:collection/*"
        }
    ]
}

创建集合 ​

接下来,使用以下设置创建集合:

  • 对 OpenSearch 端点和 OpenSearch Dashboards 的公共网络访问。

  • 以下数据访问策略,向管道角色授予所需权限,如以下配置所示:

    json
    [
     {
        "Rules":[
           {
              "Resource":[
                 "index/collection-name/*"
              ],
              "Permission":[
                 "aoss:ReadDocument",
                 "aoss:DescribeIndex"
              ],
              "ResourceType":"index"
           }
        ],
        "Principal":[
           "arn:aws:iam::<AccountId>:role/PipelineRole"
        ],
        "Description":"Pipeline role access"
     }
    ]

TIP

确保将 Principal 元素中的 Amazon Resource Name (ARN) 替换为你在上一步中创建的管道角色的 ARN。

有关如何创建集合的说明,请参阅 Amazon OpenSearch Service 文档中的创建集合。

创建管道 ​

在 pipeline.yaml 文件中,将 OpenSearch Serverless 集合端点指定为 hosts 选项。此外,你必须将 serverless 选项设置为 true。在 sts_role_arn 选项中指定管道角色,如以下示例所示:

yaml
opensearch-source-pipeline:
  source:
    opensearch:
      hosts: [ "https://<serverless-public-collection-endpoint>" ]
      aws:
        serverless: true
        sts_role_arn: "arn:aws:iam::<AccountId>:role/PipelineRole"
        region: "us-east-1"
  processor:
    - date:
        from_time_received: true
        destination: "@timestamp"
  sink:
    - stdout: