index create update 第1、2行分别为:信息行、数据行,在索引中增加或更换文档
delete 移除文档,只包含信息行
Bulk API | Elasticsearch Reference [6.4] | Elastic https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
action_and_meta_data optional_source action_and_meta_data optional_source .... action_and_meta_data optional_source
{ "index" : { "_index" : "test", "_type" : "_doc", "_id" : "1" } } { "field1" : "value1" } { "delete" : { "_index" : "test", "_type" : "_doc", "_id" : "2" } } { "create" : { "_index" : "test", "_type" : "_doc", "_id" : "3" } } { "field1" : "value3" } { "update" : {"_id" : "1", "_type" : "_doc", "_index" : "test"} } { "doc" : {"field2" : "value2"} }
$ curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@requests"; echo
批量索引文件的大小限制:100MB
修改http.max_content_length调整,避免请求过大时可能存在的请求超时及内存问题
为了执行批量请求,Elasticsearch提供了_bulk端点,有3种粒度
/_bulk
/index_name/_bulk
/index_name/type_name/_bulk
curl -XPOST ‘localhost:9200/_bulk?pretty’ --data-binary@j.json
【 -d --data-binary 】
-d 忽略换行符
--data-binary