elasticsearch的一些批量操作

为了看起来毫不费力
### 批量插入
1
2
3
4
5
6
7
8
9
10
11
POST /shop/product/_bulk
{ "index" : {"_id" : "1" } }
{ "name" : "apple", "price":15.15 }
{ "index" : {"_id" : "2" } }
{ "name" : "pear", "price":16.00 }
{ "index" : {"_id" : "3" } }
{ "name" : "orange", "price":15.09 }
{ "index" : {"_id" : "4" } }
{ "name" : "bnanan", "price":3.00 }
{ "index" : {"_id" : "5" } }
{ "name" : "pototo", "price":9.15 }

批量修改

1
2
3
4
5
6
7
8
9
10
11
POST /shop/product/_bulk
{ "update" : {"_id" : "1"} }
{ "doc" : {"name" : "apple iphone"} }
{ "update" : {"_id" : "2"} }
{ "doc" : {"name" : "pear yoyo"} }
{ "update" : {"_id" : "3"} }
{ "doc" : {"name" : "orange milk"} }
{ "update" : {"_id" : "4"} }
{ "doc" : {"name" : "bnanan egg"} }
{ "update" : {"_id" : "5"} }
{ "doc" : {"name" : "pototo chips"} }

批量添加新的字段

1
2
3
4
5
6
7
8
9
10
11
POST /shop/product/_bulk
{ "update" : {"_id" : "1"} }
{ "doc" : {"desc" : "this is a apple iphone"} }
{ "update" : {"_id" : "2"} }
{ "doc" : {"desc" : "the price is low"} }
{ "update" : {"_id" : "3"} }
{ "doc" : {"desc" : "the frieight is free"} }
{ "update" : {"_id" : "4"} }
{ "doc" : {"desc" : "buy one and a free one"} }
{ "update" : {"_id" : "5"} }
{ "doc" : {"desc" : "you lost it"} }

批量删除

1
2
3
POST /shop/product/_bulk
{ "delete" : {"_id" : "2" } }
{ "delete" : {"_id" : "3" } }