Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Elasticsearch inserts data in bulk

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report