elasticsearch api 增删改

 

List All Indices(列出所有索引) 

http://39.107.36.109:9200/_cat/indices?v&pretty

 

 

创建索引:

 1 PUT /people3 HTTP/1.1
 2 Host: 39.107.36.109:9200
 3 Content-Type: application/json
 4 Cache-Control: no-cache
 5 Postman-Token: a4fb7ab9-f523-02fb-cf51-a3a7b99fc9ce
 6 
 7 {
 8     "settings":{
 9         "number_of_shards":3,
10         "number_of_replicas":1
11     },
12     "mappings":{
13         "man":{
14         "properties":{
15             "name":{
16                 "type":"text"
17             },
18             "country":{
19                 "type":"keyword"
20             },
21             "age":{
22                 "type":"integer"
23             },
24             "date":{
25                 "type":"date",
26                 "format":"yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
27             }
28         }
29     },
30     "woman":{}
31     }
32     
33 }

 

 

插入数据:

插入指定id的数据:

 1 POST /people3/man/1 HTTP/1.1
 2 Host: 39.107.36.109:9200
 3 Content-Type: application/json
 4 Cache-Control: no-cache
 5 Postman-Token: ab0a7791-6daf-ddac-a504-615abdfb4986
 6 
 7 {
 8 "name":"jessi",
 9 "country":"China",
10 "age":30,
11 "date":"1999-01-01"
12 }

 

 

 

自动生成id插入数据

 1 POST /people3/woman HTTP/1.1
 2 Host: 39.107.36.109:9200
 3 Cache-Control: no-cache
 4 Postman-Token: a9a979d0-8d5d-629d-1294-179f00304e28
 5 
 6 {
 7 "name":"AngelaBaby",
 8 "country":"China",
 9 "age":20,
10 "date":"204-01-01"
11 }

 

修改数据 方式一:

 

 1 PUT /people3/man/1 HTTP/1.1
 2 Host: 39.107.36.109:9200
 3 Content-Type: application/json
 4 Cache-Control: no-cache
 5 Postman-Token: 5d0e9893-0d73-2288-d2bc-9c7b247a54a1
 6 
 7 {
 8 "name":"C罗",
 9 "country":"China",
10 "age":30,
11 "date":"1999-01-01"
12 }

 

 

方式二 脚本修改数据第一种 :

POST /people3/man/1/_update HTTP/1.1
Host: 39.107.36.109:9200
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 691c1f49-99c4-9fff-f1b0-115ab153860c

{
"script":{
"lang":"painless",
"inline":"ctx._source.age+=1"
}
}

 

 

方式三 脚本修改数据第二种:

POST /people3/man/1/_update HTTP/1.1
Host: 39.107.36.109:9200
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: e082870c-ece1-9c8a-f3e7-627346c939c7

{
"script":{
"lang":"painless",
"inline":"ctx._source.age=params.age",
"params":{
    "age":100
}
}
}

 

 

 

 

删除数据:

1 DELETE /people3/man/1 HTTP/1.1
2 Host: 39.107.36.109:9200
3 Cache-Control: no-cache
4 Postman-Token: f66063ef-6cd0-ade1-d616-87497f665346

 

 

 

 

 

删除索引:

DELETE /people3 HTTP/1.1
Host: 39.107.36.109:9200
Cache-Control: no-cache
Postman-Token: c1ec3f37-3eaa-46ab-39e8-cedbe83385b0

 

posted on 2018-06-11 14:51  ziyi_ang  阅读(115)  评论(0编辑  收藏  举报

导航