elasticsearch的增删命令备忘记录

文章目录

  • 创建一个文档 index/create
    • index 如果id不存在创建新的文档,否则先删除现有的文档,再创建新的文档,版本会增加
    • 如果id已经存在,会失败
    • 系统会自动生成id
  • 更新一个文档 update
    • 文档必须已经存在,更新只会对相应字段做增量修改
  • 删除一个文档 delete
  • 查一个文档 get
  • 批量操作:
  • 批量读取:
  • 批量查询-msearch
  • 总体记录

创建一个文档 index/create

index 如果id不存在创建新的文档,否则先删除现有的文档,再创建新的文档,版本会增加

PUT test/_doc/1
{"user":"mike","comment":"you known,for search"}

如果id已经存在,会失败

PUT test/_create/1
{"user":"mike1","comment":"you known,for search"}

系统会自动生成id

POST test/_doc
{"user":"mike2","comment":"you known,for search"}

更新一个文档 update

文档必须已经存在,更新只会对相应字段做增量修改

POST test/_update/1
{"doc":{"user":"mike4","comment":"you known,for search","test":"55"}}

删除一个文档 delete

DELETE test/_doc/1

查一个文档 get

GET test/_doc/1

批量操作:

批量操作,每一条都有返回,相互不影响
POST _bulk
{"index":{"_index":"test","_id":"1"}}
{"field1":"value1"}
{"delete":{"_index":"test","_id":"2"}}
{"create":{"_index":"test2","_id":"3"}}
{"field1":"value3"}
{"update":{"_id":"1","_index":"test"}}
{"doc":{"field2":"value2"}}

批量读取:

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

批量查询-msearch

POST test/_msearch
{}
{"query":{"match_all":{}},"from":0,"size":2}
{}
{"query":{"match_all":{}}}
{"index":"test2"}
{"query":{"match_all":{}}}

总体记录

GET _cluster/health
GET _cat/nodes
GET _cat/shards
# type 默认都是_doc
# index 如果id不存在创建新的文档,否则先删除现有的文档,再创建新的文档,版本会增加
PUT test/_doc/1
{"user":"mike","comment":"you known,for search"}
# 如果id已经存在,会失败
PUT test/_create/1
{"user":"mike1","comment":"you known,for search"}
# 系统会自动生成id
POST test/_doc
{"user":"mike2","comment":"you known,for search"}
# 查询数量
GET test/_count
# 查询文档
GET test/_doc/1
# 查询索引下所有
GET test/_search/
# 查询文档
GET test/_doc/1
# 文档必须已经存在,更新只会对相应字段做增量修改
POST test/_update/1
{"doc":{"user":"mike4","comment":"you known,for search","test":"55"}}
# 删除文档
DELETE test/_doc/1
# 批量操作,每一条都有返回,相互不影响
POST _bulk
{"index":{"_index":"test","_id":"1"}}
{"field1":"value1"}
{"delete":{"_index":"test","_id":"2"}}
{"create":{"_index":"test2","_id":"3"}}
{"field1":"value3"}
{"update":{"_id":"1","_index":"test"}}
{"doc":{"field2":"value2"}}
# 批量读取,每一条都会有返回,相互不影响
GET _mget
{
  "docs":[
    {
      "_index":"test",
      "_id":1
    },
    {
      "_index":"test",
      "_id":2
    }
  ]
}
# 批量查询
POST test/_msearch
{}
{"query":{"match_all":{}},"from":0,"size":2}
{}
{"query":{"match_all":{}}}
{"index":"test2"}
{"query":{"match_all":{}}}

你可能感兴趣的:(elasticsearch)