加载中

示例:基于精确值富化数据

match 丰富策略 使用 term 查询,基于精确值(例如电子邮件地址或 ID)将丰富数据匹配到传入文档。

以下示例创建了一个 match 丰富策略,该策略根据电子邮件地址将用户名和联系信息添加到传入文档中。然后,它将此 match 丰富策略添加到摄取管道中的处理器中。

使用 创建索引 API索引 API 来创建源索引。

以下索引 API 请求会创建一个源索引,并将一个新文档索引到该索引中。

				PUT /users/_doc/1?refresh=wait_for
					{
  "email": "mardy.brown@example.com",
  "first_name": "Mardy",
  "last_name": "Brown",
  "city": "New Orleans",
  "county": "Orleans",
  "state": "LA",
  "zip": 70116,
  "web": "mardy.example.com"
}
		

使用创建丰富策略 API 创建一个 match 策略类型的丰富策略。此策略必须包含

  • 一个或多个源索引
  • 一个 match_field,即源索引中用于匹配传入文档的字段
  • 您希望附加到传入文档的源索引中的丰富字段
				PUT /_enrich/policy/users-policy
					{
  "match": {
    "indices": "users",
    "match_field": "email",
    "enrich_fields": ["first_name", "last_name", "city", "zip", "state"]
  }
}
		

使用 执行丰富策略 API 为该策略创建一个丰富索引。

				POST /_enrich/policy/users-policy/_execute?wait_for_completion=false
		

使用 创建或更新管道 API 创建一个摄取管道。在管道中,添加一个包含以下内容的 丰富处理器

  • 您的丰富策略。
  • 传入文档中用于匹配丰富索引中文档的 field
  • 用于存储附加到传入文档的丰富数据的 target_field。此字段包含您丰富策略中指定的 match_fieldenrich_fields
				PUT /_ingest/pipeline/user_lookup
					{
  "processors" : [
    {
      "enrich" : {
        "description": "Add 'user' data based on 'email'",
        "policy_name": "users-policy",
        "field" : "email",
        "target_field": "user",
        "max_matches": "1"
      }
    }
  ]
}
		

使用摄取管道索引一个文档。传入的文档应包含您丰富处理器中指定的 field

				PUT /my-index-000001/_doc/my_id?pipeline=user_lookup
					{
  "email": "mardy.brown@example.com"
}
		

要验证丰富处理器是否匹配并附加了相应的字段数据,请使用 get API 查看已索引的文档。

				GET /my-index-000001/_doc/my_id
		

API 返回以下响应

{
  "found": true,
  "_index": "my-index-000001",
  "_id": "my_id",
  "_version": 1,
  "_seq_no": 55,
  "_primary_term": 1,
  "_source": {
    "user": {
      "email": "mardy.brown@example.com",
      "first_name": "Mardy",
      "last_name": "Brown",
      "zip": 70116,
      "city": "New Orleans",
      "state": "LA"
    },
    "email": "mardy.brown@example.com"
  }
}
		
© . This website operates independently and is not affiliated with or endorsed by Elasticsearch B.V. All brand names, logos, and trademarks are the property of their respective owners.