ElasticSearch7笔记:基本操作and批量操作

ES虽然是一个分布式搜索引擎,但使用上依然是CRUD的形式,这也是所有软件都在做的事情,因为所有操作都是围绕数据展开的。

基本操作

index: 指定文档id,文档type固定为_doc。如果文档id已存在,先删除再新增,version版本会递增。

PUT student/_doc/1
{
     
  "name":"star.mai",
  "age":30,
  "interest":["football","elec-game"]
}

create: _create时如果文档已存在,返回失败。

PUT student/_create/2
{
     
  "name":"star",
  "age":25,
  "interest":["basketball","music"]
}

POST student/_doc
{
     
  "name":"little.mai",
  "age":28,
  "interest":["computer","novel"]
}

get: 读取

GET student/_doc/1 

update: 注意payload部分使用doc。update时文档不存在返回404。更新是增量操作。

POST student/_update/1
{
     
  "doc": {
     
    "interest":["football","elec-game","computer"]
  }
}

批量操作

_bulk: 批量提交

POST _bulk
{
     "create":{
     "_index":"batch_demo2","_id":2}}
{
     "name":"batch2","city":"shanghai"}
{
     "update":{
     "_index":"batch_demo2","_id":2}}
{
     "doc":{
     "age":25,"city":"beijing"}}

mget: 批量get

GET _mget
{
     "docs":[
  {
     
    "_index":"batch_demo",
    "_id":1
  },
  {
     
    "_index":"batch_demo2",
    "_id":2
  }
  ]
}

msearch 批量search

POST student/_msearch
{
     "index":"batch_demo"}
{
     "query":{
     "match_all":{
     }}}
{
     "index":"batch_demo2"}
{
     "query":{
     "match_all":{
     }}}

你可能感兴趣的:(es7,elasticsearch)