ElasticSearch11:文档操作

ElasticSearch11:文档操作

添加文档

# 添加文档操作,手动指定_id POST /products/_doc/1 { "id":1, "title":"冰墩墩", "price":388, "create_at":"2022-02-02", "description":"一墩难求" } #添加文档 自动创建文档的id POST /products/_doc/ { "title":"雪融融", "price":288, "create_at":"2022-02-02", "description":"雪融融真可爱" }
 
#添加文档 自动创建文档的id POST /products/_doc/ { "title":"雪融融", "price":288, "create_at":"2022-02-02", "description":"雪融融真可爱" }
notion image
 

查询文档

# 文档查询 GET /products/_doc/1

删除文档

# 删除文档,基于id删除 DELETE /products/_doc/1

更新文档

# 更新文档,删除原始文档,在重新添加,传入全部字段 PUT /products/_doc/1 { "title":"雪融融", "price":288, "create_at":"2022-02-02", "description":"雪融融真可爱,抢购一个" } # 8.0版本之前,更新文档,基于指定字段更新 POST /products/_doc/1/_update { "doc":{ "price":188 } } # ES8.0以后API采用以下更新文档,基于指定字段更新 POST /products/_update/1 { "doc":{ "price":188 } }
 

文档批量操作

# 文档批量操作 POST /products/_bulk {"index":{"_id":3}} {"id":3,"title":"冰墩墩","price":388,"create_at":"2022-02-02", "description":"一墩难求"} {"index":{"_id":4}} {"id":4,"title":"雪融融","price":288,"create_at":"2022-02-02", "description":"真可爱"} # 文档查询 GET /products/_doc/3 # 文档批量操作,添加、更新、删除 POST /products/_bulk {"index":{"_id":5}} {"id":4,"title":"福娃","price":688,"create_at":"2018-02-02", "description":"北京欢迎你"} {"update":{"_id":3}} {"doc":{"title":"冰墩墩儿"}} {"delete":{"_id":4}}