ES数据的基本CRUD

in ELK with 0 comment

基本CRUD

A. 添加数据,没有指定ID, 系统会生成ID

POST users/_doc
{
    "age": 10,
    "firstName": "Will",
    "lastName": "Smith"
}

B. 操作数据,指定ID,如果有对应的ID,就修改数据;如果没有对应的ID,就添加数据。

POST users/_doc/1
{
    "age": 20,
    "firstName": "Roden",
    "lastName": "Jhson"
}

C. 通过 _create 的方式,如果存在ID,就会报错

POST users/_create/2
{
    "age": 40,
    "firstName": "Douge",
    "lastName": "Lee"
} 

PUT users/_create/8
{
    "age": 50,
    "firstName":"Jacks",
    "lastName":
}

D. 查询指定ID的文档

GET users/_doc/1

E. 删除指定ID的文档

DELETE users/_doc/1

F. 指定ID,创建或者覆盖

PUT users/_doc/1
{
    "firstName": "Hello",
    "lastName": "Lee"
}

G. 修改原有数据的结构

POST users/_update/1
{
    "doc": {
        "age": 40,
        "firstName":"Rodan",
        "lastName": "Johson"
    }
}

H.批量查询

GET _mget
{
    "docs": [
        {"_index":"movies", "_id":"104372"},
        {"_index":"movies", "_id":"104374"}
    ]
}

I. 分页查询

GET movies/_search
{
    "from": 0,
    "size": 20
}

J. 批量插入(可以指定ID,也可以不指定ID)

POST users/_bulk
{"index":{"_id": 23}}
{"firstName":"a", "lastName":"A"}
{"index":{}}
{"firstName":"b", "lastName":"B"}
{"index":{}}
{"firstName":"c", "lastName":"C"}

批量插入后,使用GET users/_search查询我们添加的数据。

批量插入,然后查询

Responses