1. Mapping操作
# 新增
PUT / hm
{
"mappings" : {
"properties" : {
"info" : {
"type" : "text" ,
"analyzer" : "ik_smart"
} ,
"age" : {
"type" : "byte"
} ,
"email" : {
"type" : "keyword" ,
"index" : false
} ,
"name" : {
"type" : "object" ,
"properties" : {
"firstName" : {
"type" : "keyword"
} ,
"lastName" : {
"type" : "keyword"
}
}
}
}
}
}
# 查询索引库
GET / hm
# 删除索引库
DELETE / hm
# 修改,只能添加新字段
PUT / hm/ _mapping
{
"properties" : {
"sex" : {
"type" : "boolean"
}
}
}
2. 文档操作
# 新增文档
POST / hm/ _doc/ 1
{
"info" : "原神Java讲师" ,
"email" : "ys@itcast.cn" ,
"age" : 18 ,
"name" : {
"firstName" : "米" ,
"lastName" : "大卫"
} ,
"sex" : true
}
# 查询文档
GET / hm/ _doc/ 1
# 删除文档
DELETE / hm/ _doc/ 1
# 增量修改文档
POST / hm/ _update/ 1
{
"doc" : {
"email" : "dw@itcast.cn"
}
}
3. 文档批操作
POST _bulk
{ "index" : { "_index" : "test" , "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test" , "_id" : "2" } }
{ "create" : { "_index" : "test" , "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : { "_id" : "1" , "_index" : "test" } }
{ "doc" : { "field2" : "value2" } }
# 批量新增
POST / _bulk
{ "index" : { "_index" : "hm" , "_id" : "3" } }
{ "info" : "黑马程序员C++讲师" , "email" : "ww@itcast.cn" , "name" : { "firstName" : "五" , "lastName" : "王" } , "sex" : true }
{ "index" : { "_index" : "hm" , "_id" : "4" } }
{ "info" : "黑马程序员前端讲师" , "email" : "zhangsan@itcast.cn" , "name" : { "firstName" : "三" , "lastName" : "张" } , "sex" : false }
# 批量删除
POST / _bulk
{ "delete" : { "_index" : "hm" , "_id" : "3" } }
{ "delete" : { "_index" : "hm" , "_id" : "4" } }