第 2 步:将数据上传到 Amazon ES 以便编制索引 - Amazon Elasticsearch Service
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

第 2 步:将数据上传到 Amazon ES 以便编制索引

重要

这是一个简明教程,用于上传少量测试数据到 Amazon Elasticsearch Service (Amazon ES)。有关在生产域中上传数据的详细信息,请参阅在 Amazon Elasticsearch Service 中为数据建立索引

您可以使用命令行或大多数编程语言将数据上传到 Amazon ES 域。

以下示例请求使用curl(常见的 HTTP 客户端),以简化和方便。像 curl 这样的客户端无法执行您的访问策略指定 IAM 用户或角色时所需的请求签名。要成功完成此过程,必须使用精细访问控制以及主用户名和密码,就像在步骤 1

您可以在 Windows 上安装 curl 并通过命令提示符使用它,但我们建议您使用奇格温适用于 Linux 的 Windows 子系统macOS 和大多数 Linux 发行版都预安装有 curl。

选项 1:上传单个文档

运行以下命令将单个文档添加到 movies 域:

curl -XPUT -u 'master-user:master-user-password' 'domain-endpoint/movies/_doc/1' -d '{"director": "Burton, Tim", "genre": ["Comedy","Sci-Fi"], "year": 1996, "actor": ["Jack Nicholson","Pierce Brosnan","Sarah Jessica Parker"], "title": "Mars Attacks!"}' -H 'Content-Type: application/json'

有关此命令的详细说明,以及如何向 Amazon ES 发出签名请求,请参阅在 Amazon Elasticsearch Service 中为数据建立索引

选项 2:上传多个文档

上传包含多个文档的 JSON 文件到 Amazon ES 域

  1. 创建名为 bulk_movies.json 的文件。将以下内容粘贴到文件中并添加一个尾部换行:

    { "index" : { "_index": "movies", "_id" : "2" } } {"director": "Frankenheimer, John", "genre": ["Drama", "Mystery", "Thriller", "Crime"], "year": 1962, "actor": ["Lansbury, Angela", "Sinatra, Frank", "Leigh, Janet", "Harvey, Laurence", "Silva, Henry", "Frees, Paul", "Gregory, James", "Bissell, Whit", "McGiver, John", "Parrish, Leslie", "Edwards, James", "Flowers, Bess", "Dhiegh, Khigh", "Payne, Julie", "Kleeb, Helen", "Gray, Joe", "Nalder, Reggie", "Stevens, Bert", "Masters, Michael", "Lowell, Tom"], "title": "The Manchurian Candidate"} { "index" : { "_index": "movies", "_id" : "3" } } {"director": "Baird, Stuart", "genre": ["Action", "Crime", "Thriller"], "year": 1998, "actor": ["Downey Jr., Robert", "Jones, Tommy Lee", "Snipes, Wesley", "Pantoliano, Joe", "Jacob, Ir\u00e8ne", "Nelligan, Kate", "Roebuck, Daniel", "Malahide, Patrick", "Richardson, LaTanya", "Wood, Tom", "Kosik, Thomas", "Stellate, Nick", "Minkoff, Robert", "Brown, Spitfire", "Foster, Reese", "Spielbauer, Bruce", "Mukherji, Kevin", "Cray, Ed", "Fordham, David", "Jett, Charlie"], "title": "U.S. Marshals"} { "index" : { "_index": "movies", "_id" : "4" } } {"director": "Ray, Nicholas", "genre": ["Drama", "Romance"], "year": 1955, "actor": ["Hopper, Dennis", "Wood, Natalie", "Dean, James", "Mineo, Sal", "Backus, Jim", "Platt, Edward", "Ray, Nicholas", "Hopper, William", "Allen, Corey", "Birch, Paul", "Hudson, Rochelle", "Doran, Ann", "Hicks, Chuck", "Leigh, Nelson", "Williams, Robert", "Wessel, Dick", "Bryar, Paul", "Sessions, Almira", "McMahon, David", "Peters Jr., House"], "title": "Rebel Without a Cause"}
  2. 运行以下命令以将该文件上传到 movies 域:

    curl -XPOST -u 'master-user:master-user-password' 'domain-endpoint/_bulk' --data-binary @bulk_movies.json -H 'Content-Type: application/json'

有关批量文件格式的更多信息,请参阅在 Amazon Elasticsearch Service 中为数据建立索引

后续:Search 文档