es批量插入能用作修改么 es批量新增_es批量插入能用作修改么

批量删除

POST /_bulk
{"delete":{"_index":"article","_type":"poems","_id":"1"}}
{"delete":{"_index":"article","_type":"poems","_id":"2"}}
{"delete":{"_index":"article","_type":"poems","_id":"3"}}
{"delete":{"_index":"article","_type":"poems","_id":"4"}}
{"delete":{"_index":"article","_type":"poems","_id":"5"}}

批量新增(注意格式,数据json串在同一行)

POST /_bulk
{"create":{"_index":"article","_type":"poems","_id":"1"}}
{"title":"静夜思","author":"李白","dynasty":"唐","words":20,"tags":["月亮","思乡","五言绝句"],"content":"床前明月光,疑是地上霜。举头望明月,低头思故乡。"}
{"create":{"_index":"article","_type":"poems","_id":"2"}}
{"title":"悯农","author":"李绅","dynasty":"唐","words":20,"tags":["农耕","五言绝句"],"content":"春种一粒粟,秋收万颗子。四海无闲田,农夫犹饿死。"}
{"create":{"_index":"article","_type":"poems","_id":"3"}}
{"title":"春夜喜雨","author":"杜甫","dynasty":"唐","words":40,"tags":["春雨","五言律诗"],"content":"好雨知时节,当春乃发生。随风潜入夜,润物细无声。野径云俱黑,江船火独明。晓看红湿处,花重锦官城。"}
{"create":{"_index":"article","_type":"poems","_id":"4"}}
{"title":"望庐山瀑布","author":"李白","dynasty":"唐","words":20,"tags":["瀑布","七言绝句"],"content":"日照香炉生紫烟,遥看瀑布挂前川。飞流直下三千尺,疑是银河落九天。"}
{"create":{"_index":"article","_type":"poems","_id":"5"}}
{"title":"早发白帝城","author":"李白","dynasty":"唐","words":28,"tags":["船","七言绝句","白帝城"],"content":"朝辞白帝彩云间,千里江陵一日还。两岸猿声啼不住,轻舟已过万重山。"}

批量删除又新增

POST /_bulk
{"delete":{"_index":"article","_type":"poems","_id":"1"}}
{"delete":{"_index":"article","_type":"poems","_id":"2"}}
{"delete":{"_index":"article","_type":"poems","_id":"3"}}
{"delete":{"_index":"article","_type":"poems","_id":"4"}}
{"delete":{"_index":"article","_type":"poems","_id":"5"}}
{"create":{"_index":"article","_type":"poems","_id":"1"}}
{"title":"静夜思","author":"李白","dynasty":"唐","words":20,"tags":["月亮","思乡","五言绝句"],"content":"床前明月光,疑是地上霜。举头望明月,低头思故乡。"}
{"create":{"_index":"article","_type":"poems","_id":"2"}}
{"title":"悯农","author":"李绅","dynasty":"唐","words":20,"tags":["农耕","五言绝句"],"content":"春种一粒粟,秋收万颗子。四海无闲田,农夫犹饿死。"}
{"create":{"_index":"article","_type":"poems","_id":"3"}}
{"title":"春夜喜雨","author":"杜甫","dynasty":"唐","words":40,"tags":["春雨","五言律诗"],"content":"好雨知时节,当春乃发生。随风潜入夜,润物细无声。野径云俱黑,江船火独明。晓看红湿处,花重锦官城。"}
{"create":{"_index":"article","_type":"poems","_id":"4"}}
{"title":"望庐山瀑布","author":"李白","dynasty":"唐","words":20,"tags":["瀑布","七言绝句"],"content":"日照香炉生紫烟,遥看瀑布挂前川。飞流直下三千尺,疑是银河落九天。"}
{"create":{"_index":"article","_type":"poems","_id":"5"}}
{"title":"早发白帝城","author":"李白","dynasty":"唐","words":28,"tags":["船","七言绝句","白帝城"],"content":"朝辞白帝彩云间,千里江陵一日还。两岸猿声啼不住,轻舟已过万重山。"}

批量修改

POST /_bulk
{"update":{"_index":"article","_type":"poems","_id":"1"}}
{"doc":{"title":"静夜思","author":"李白","dynasty":"唐","words":20,"tags":["月亮","思乡","五言绝句"],"content":"被我改了"}}
{"update":{"_index":"article","_type":"poems","_id":"2"}}
{"doc":{"title":"悯农","author":"李绅","dynasty":"唐","words":20,"tags":["农耕","五言绝句"],"content":"被我改了"}}
{"update":{"_index":"article","_type":"poems","_id":"3"}}
{"doc":{"title":"春夜喜雨","author":"杜甫","dynasty":"唐","words":40,"tags":["春雨","五言律诗"],"content":"被我改了"}}
{"update":{"_index":"article","_type":"poems","_id":"4"}}
{"doc":{"title":"望庐山瀑布","author":"李白","dynasty":"唐","words":20,"tags":["瀑布","七言绝句"],"content":"被我改了"}}
{"update":{"_index":"article","_type":"poems","_id":"5"}}
{"doc":{"title":"早发白帝城","author":"李白","dynasty":"唐","words":28,"tags":["船","七言绝句","白帝城"],"content":"被我改了"}}

放到一起

POST /_bulk
{"delete":{"_index":"article","_type":"poems","_id":"1"}}
{"create":{"_index":"article","_type":"poems","_id":"1"}}
{"title":"静夜思","author":"李白","dynasty":"唐","words":20,"tags":["月亮","思乡","五言绝句"],"content":"床前明月光,疑是地上霜。举头望明月,低头思故乡。"}
{"update":{"_index":"article","_type":"poems","_id":"1"}}
{"doc":{"title":"静夜思","author":"李白","dynasty":"唐","words":20,"tags":["月亮","思乡","五言绝句"],"content":"被我叕改了"}}

不同的写法

POST article/poems/_bulk    //这里指定了index和type
{"delete":{"_id":"1"}}
{"delete":{"_id":"2"}}
{"delete":{"_id":"3"}}
{"delete":{"_id":"4"}}
{"delete":{"_id":"5"}}

或者

POST article/_bulk    //这里指定了index没指定type
{"delete":{"_type":"poems","_id":"1"}}
{"delete":{"_type":"poems","_id":"2"}}
{"delete":{"_type":"poems","_id":"3"}}
{"delete":{"_type":"poems","_id":"4"}}
{"delete":{"_type":"poems","_id":"5"}}