当前位置: 代码迷 >> 综合 >> ElasticSearch7.4批量导入_bulk
  详细解决方案

ElasticSearch7.4批量导入_bulk

热度:49   发布时间:2024-01-26 06:17:26.0
请求的每一行包含描述操作说明
JSON 对象,第二行为 JSON 对象本身。可以把第一行视为信息行,第二类为数据行。唯一的例
外是 delete 操作,它只包含信息行。来看看下面的例子:
{ "index": { "_index": "addr", "_type": "contact", "_id": 1 }}
{ "name": "Fyodor Dostoevsky", "country": "RU" }
{ "create": { "_index": "addr", "_type": "contact", "_id": 2 }}
{ "name": "Erich Maria Remarque", "country": "DE" }
{ "create": { "_index": "addr", "_type": "contact", "_id": 2 }}
{ "name": "Joseph Heller", "country": "US" }
{ "delete": { "_index": "addr", "_type": "contact", "_id": 4 }}
{ "delete": { "_index": "addr", "_type": "contact", "_id": 1 }}
重要的是,每一个文档或操作说明放置在一行中(以换行符结束)。这意味着无法美化文档格
式。批量索引文件的大小存在限制,它被设定为 100 MB ,在 Elasticsearch 配置文件中可以通过
http.max_content_length 属性来改变。这避免了请求过大时可能存在的请求超时及内存问题。

 

curl -X POST http://localhost:9200/_bulk -H Content-Type:application/json --data-binary @D:\DevEnv\curl-7.68.0-win64-mingw\bin\xx.json

需要导入的文件xx.json如下:

 { "index": {"_index": "library", "_type": "book", "_id": "1"}}
{ "title": "All Quiet on the Western Front","otitle": "Im Westen nichts Neues","author": "Erich Maria Remarque","year":  1929,"characters": ["Paul B?umer", "Albert Kropp", "Haie  Westhus", "Fredrich Müller", "Stanislaus Katczinsky", "Tjaden"],"tags": ["novel"],"copies": 1, "available": true,  "section" : 3}
{ "index": {"_index": "library", "_type": "book", "_id": "2"}}
{ "title": "Catch-22","author": "Joseph Heller","year":  1961,"characters": ["John Yossarian", "Captain Aardvark",  "Chaplain Tappman", "Colonel Cathcart", "Doctor  Daneeka"],"tags": ["novel"],"copies": 6, "available" : false,  "section" : 1}
{ "index": {"_index": "library", "_type": "book", "_id": "3"}}
{ "title": "The Complete Sherlock Holmes",  "author": "Arthur Conan Doyle","year": 1936,"characters":  ["Sherlock Holmes","Dr. Watson", "G. Lestrade"],"tags":  [],"copies": 0, "available" : false, "section" : 12}
{ "index": {"_index": "library", "_type": "book", "_id": "4"}}
{ "title": "Crime and Punishment","otitle": "Преступлéние и  наказáние","author": "Fyodor Dostoevsky","year":  1886,"characters": ["Raskolnikov", "Sofia Semyonovna  Marmeladova"],"tags": [],"copies": 0, "available" : true}

注意需要导入的文件行与行之间要以换行符相隔,如果导入时提示出错,请将文件内容都归为一行,然后每一行之间以enter回车键相隔开,然后再导入。

 

 

  相关解决方案