Elasticsearch批量插入数据
使用bulk批量操作数据库
1. 创建批量操作文件
格式:
{"index":{"_index":"home","_type":"home",""_id":"2"}}
{"id": 2, "location": "南京市栖霞区马群街道29号", "money": 3000, "area":80, "type": "三居室", "style": "整租"}
第一行指定请求与索引和类型,可以选择的请求有"create","index","delete","ubdate",
"_index"指定索引名,"_type"指定类型名,"_id"指定id
第二行指定插入的内容.
如request.json:
{"index":{"_index":"home","_type":"home","_id":"2"}}
{"id": 2, "location": "南京市栖霞区马群街道29号", "money": 3000, "area":80, "type": "三居室", "style": "整租"}
{"index":{"_index":"home","_type":"home","_id":"3"}}
{"id": 3, "location": "南京市玄武区山西路门路29号", "money": 400, "area":15, "type": "四居室", "style": "合租"}
{"index":{"_index":"home","_type":"home","_id":"4"}}
{"id": 4, "location": "南京市秦淮区山北京东路29号", "money": 500, "area":14, "type": "三居室", "style": "合租"}
{"index":{"_index":"home","_type":"home","_id":"5"}}
{"id": 5, "location": "南京市秦淮区新街口29号", "money": 450, "area":16, "type": "四居室", "style": "合租"}
2.执行批量操作文件
在数据库根目录执行:
curl -XPUT 'localhost:9200/_bulk' -H "Content-Type: application/json" --data-binary @request.json