_bulk 批量操作

批量上传数据

POST /es/_bulk

这将批量上传多个文档。当你有多个文档需要插入时,它比使用UpdateDocument API更可取,因为它的速度是单独上传文档的许多倍。

你可以根据服务器上的可用资源使用API批量上传任意数量的文档。在服务器端,任何大于10000的批量都会被拆分为多个不超过 1000 的批次。例如,一个 1500 的批量将被拆分为两个 1000+500 的批次,一个2500的批量将被拆分为三个 1000+1000+500 的批次。

像 fluentbit 和 syslog-ng 这样的日志转发器使用此 API。

如果在请求中提供的索引不存在,则会创建该索引。

请求示例

POST /es/_bulk

请求体:ndjson(换行符分隔的JSON)内容

请求体示例:

  1. { "index" : { "_index" : "olympics" } }
  2. {"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "HAJOS, Alfred", "Country": "HUN", "Gender": "Men", "Event": "100M Freestyle", "Medal": "Gold", "Season": "summer"}
  3. { "index" : { "_index" : "olympics" } }
  4. {"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "HERSCHMANN, Otto", "Country": "AUT", "Gender": "Men", "Event": "100M Freestyle", "Medal": "Silver", "Season": "summer"}
  5. { "index" : { "_index" : "olympics" } }
  6. {"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "DRIVAS, Dimitrios", "Country": "GRE", "Gender": "Men", "Event": "100M Freestyle For Sailors", "Medal": "Bronze", "Season": "summer"}
  7. { "index" : { "_index" : "olympics" } }
  8. {"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "MALOKINIS, Ioannis", "Country": "GRE", "Gender": "Men", "Event": "100M Freestyle For Sailors", "Medal": "Gold", "Season": "summer"}
  9. { "index" : { "_index" : "olympics" } }
  10. {"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "CHASAPIS, Spiridon", "Country": "GRE", "Gender": "Men", "Event": "100M Freestyle For Sailors", "Medal": "Silver", "Season": "summer"}

第一行是 index action 第二行是 文档数据

Request action

对文档进行索引

  1. { "index" : { "_index" : "olympics" } }

或者

  1. { "create" : { "_index" : "olympics" } }

或者

  1. { "update" : { "_index" : "olympics", "_id": "1" } }

删除文档

  1. { "delete" : { "_index" : "olympics", "_id": "1" } }

删除操作不需要文档数据