批量上传文档
POST /api/_bulk
这将批量上传多个文档。当你有多个要插入的文档时,与 UpdateDocument API 相比,它的速度要快得多,因此是首选。
你可以根据可用的服务器资源使用此API批量上传任意数量的文档。在服务器端,任何大于 10000 的批量都将拆分为 1000 或更少的多个批次。例如,一个 1500 的批量将被拆分为两个 1000+500 的批次,一个 2500 的批量将被拆分为三个 1000+1000+500 的批次。
像 fluentbit 和 syslog-ng 这样的日志转发器使用此 API。
如果在请求中提供的索引不存在,则将创建它。
请求示例
POST /api/_bulk
请求体: - ndjson(换行符分隔的json)内容
示例:ndjson 内容
{ "index" : { "_index" : "olympics" } }
{"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "HAJOS, Alfred", "Country": "HUN", "Gender": "Men", "Event": "100M Freestyle", "Medal": "Gold", "Season": "summer"}
{ "index" : { "_index" : "olympics" } }
{"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "HERSCHMANN, Otto", "Country": "AUT", "Gender": "Men", "Event": "100M Freestyle", "Medal": "Silver", "Season": "summer"}
{ "index" : { "_index" : "olympics" } }
{"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "DRIVAS, Dimitrios", "Country": "GRE", "Gender": "Men", "Event": "100M Freestyle For Sailors", "Medal": "Bronze", "Season": "summer"}
{ "index" : { "_index" : "olympics" } }
{"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "MALOKINIS, Ioannis", "Country": "GRE", "Gender": "Men", "Event": "100M Freestyle For Sailors", "Medal": "Gold", "Season": "summer"}
{ "index" : { "_index" : "olympics" } }
{"Year": 1896, "City": "Athens", "Sport": "Aquatics", "Discipline": "Swimming", "Athlete": "CHASAPIS, Spiridon", "Country": "GRE", "Gender": "Men", "Event": "100M Freestyle For Sailors", "Medal": "Silver", "Season": "summer"}
第一行是索引操作
第二行是文档数据
Request 方法
索引文档
{ "index" : { "_index" : "olympics" } }
或者
{ "create" : { "_index" : "olympics" } }
或者
{ "update" : { "_index" : "olympics", "_id": "1" } }
删除文档
{ "delete" : { "_index" : "olympics", "_id": "1" } }
删除操作不需要文档内容