ElasticSearch(ES)索引库与文档的创建和操作
索引库操作有哪些?
- 创建索引库:PUT /索引库名
- 查询索引库:GET /索引库名
- 删除索引库:DELETE /索引库名
- 添加字段:PUT /索引库名/_mapping
##创建索引库
PUT /test
{
"mappings": {
"properties": {
"info": {
"type": "text",
"analyzer": "ik_smart"
},
"email": {
"type": "keyword",
"index": false
},
"name":{
"type": "object",
"properties": {
"firstName":{
"type":"keyword"
},
"lastName":{
"type":"keyword"
}
}
}
}
}
}
#查询索引库
GET /test/_mapping
GET /test/_search
#修改(新增)索引库字段
PUT /test/_mapping
{
"properties":{
"age":{
"type":"integer"
},
"weight":{
"type":"float"
},
"isMarried":{
"type":"boolean"
},
"score":{
"type":"float"
}
}
}
#删除数据库
DELETE /test
文档操作有哪些?
- 创建文档:POST /{索引库名}/_doc/文档id { json文档 }
- 查询文档:GET /{索引库名}/_doc/文档id
- 删除文档:DELETE /{索引库名}/_doc/文档id
修改文档:
- 全量修改:PUT /{索引库名}/_doc/文档id { json文档 }
- 增量修改:POST /{索引库名}/_update/文档id { "doc": {字段}}
## 文档操作
#新增文档
POST /test/_doc/1
{
"info":"我是大帅哥",
"email":"admin@oalo.cn",
"name":{
"firstName":"哥",
"lastName":"帅"
},
"age": "18",
"weight":"120",
"score":[99,99,100],
"isMarried":false
}
#查询所有
GET /test/_search
#根据id查询
GET /test/_doc/1
#根据id进行删除文档
DELETE /test/_doc/1
# 修改文档
#1.全量修改
PUT /test/_doc/1
{
"info":"我依旧是大帅哥",
"email":"admin@oalo.cn",
"name":{
"firstName":"比",
"lastName":"帅"
},
"age": "18",
"weight":"110",
"score":[99,99,100],
"isMarried":false
}
#2.增量修改
POST /test/_update/1
{
"doc": {
"email":"521@oalo.cn"
}
}