elasticsearch教程(一)之基本增删改查

创建索引

PUT /lib/
{
  "settings":{
    "index":{
      "number_of_shards":5,
      "number_of_replicas":1
    }
  }
}

lib:索引的名称
number_of_shards:分片,确定之后不能修改
number_of_replicas:备份的数量

//直接添加一个索引

PUT lib2

//查看索引

GET /lib/_settings

GET lib2

//查看索引索引

GET /_all/_settings

//添加文档,可以理解为向数据库添加一条记录

PUT /lib/user/1
{
  "fist_name":"小明",
  "second_name":"明明",
  "nick_name":"protty boy",
  "age":18,
  "address_now":"shanghai",
  "interests":["misic"]
}

user:索引中的类型名称
1:文档的id
使用put的形式,我们要指定id的值

如果没有指定id,使用elasticsearch来生成,这个时候使用POST方式来创建一条记录

POST /lib/user
{
  "fist_name":"小高",
  "second_name":"老高",
  "nick_name":"protty boy",
  "age":18,
  "address_now":"shanghai",
  "interests":["misic"]
}


查询文档

GET /lib/user/1
GET /lib/user/5xyfOWoB-uMbznsAgDWH

//查看部分字段

GET /lib/user/1?_source=nick_name,fist_name

修改文档
(1)指定id,用一个新的文档把以前的覆盖掉

PUT /lib/user/1
{
  "fist_name":"xuwenchan",
  "second_name":"xuyi",
  "nick_name":"protty boy",
  "age":18,
  "address_now":"shanghai",
  "interests":["misic"],
  "abc":"aljkfaldkj"
}

GET /lib/user/1

(2)直接修改

POST /lib/user/1/_update
{
  "doc":{
    "age":24,
    "school":"jiangxi"
  }
}

删除文档

DELETE /lib/user/1

删除索引

DELETE lib


 

你可能感兴趣的:(elasticsearch)