es 基础概念总结 —— 文档的APIs

一、基本 CRUD

增 Index

PUT //_doc/<_id>

POST //_doc/

查 Get

GET /_doc/<_id>

删 Delete

DELETE //_doc/<_id>

改 Update

POST //_update/<_id>

 示例:

# 创建
POST user/_doc
{
  "user": "Mike",
  "post_date": "2019-04-15T14:12:12",
  "message": "Trying out kibana"
}

# 索引
PUT user/_create/1
{
  "user": "Jack",
  "post_date": "2019-04-15T14:12:12",
  "message": "Trying out kibana"
}

# 获取
GET user/_doc/1

# 更新
POST user/_update/1
{
  "doc": {
    "post_date": "2019-04-15T14:12:12",
    "message": "Trying out kibana"
  }
}

 

 二、多文档操作

1.mget

GET /_mget

GET //_mget

 通过 ID 获取不同索引上的多个文档

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

 

2.bulk 块操作

POST /_bulk

POST //_bulk

同时执行多个索引或删除等操作

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"} }

 

3.delete by query 根据查询结果删除

POST //_delete_by_query

 根据查询结果一次性删除

POST /twitter/_delete_by_query
{
  "query": {
    "match": {
      "message": "some message"
    }
  }
}

 

4.update by query 根据查询的结果更新

POST twitter/_update_by_query?conflicts=proceed

 

 5.reindex

POST /_reindex

 从一个索引复制到另一个索引

POST _reindex
{
  "source": {
    "index": "twitter"
  },
  "dest": {
    "index": "new_twitter"
  }
}

 

 

参考资料


https://www.elastic.co/guide/en/elasticsearch/reference/7.6/docs.html

 

你可能感兴趣的:(es 基础概念总结 —— 文档的APIs)