ES学习笔记--文档操作
添加文档
新增文档的DSL语法如下:
POST /索引库名/_doc/文档id { "字段一":"value1", "字段二":"value2", "字段三":{ "子属性1":"value3", "子属性2":"value4" } }
示例:
#插入文档 POST /heima/_doc/1 { "info":"东北师范大学", "email":"1016783624@qq.com", "name":{ "firstName":"W", "lastName":"TY" } }
查看文档:
GET /索引库名/_doc/ID
示例:
GET /heima/_doc/1
删除文档
DELETE /索引库名/_doc/ 文档ID
示例:
DELETE /heima/_doc/1
修改文档
方式一:全量修改,会删除旧文档,添加新文档
PUT /索引库名/_doc/文档id { "字段1":"value1", "字段2":"value2" }
示例:
PUT /heima/_doc/1 { "info":"东北师范大学", "email":"1016783624@qq.com", "name":{ "firstName":"KOL", "lastName":"MIKESLION" } }
方式二:增量修改,修改指定字段值
POST /索引库名/_update/ 文档ID { "doc":{ "字段名":"new value" } }
示例
POST /heima/_update/1 { "doc":{ "info":"杜克大学" } }