ElasticSearch Rest style operation (1) index operation
Basic Rest command description
method | url address | description |
---|---|---|
PUT | 127.0.0.1:9200/index name/type name/document id | Create document (specify document id) |
POST | 127.0.0.1:9200/index name/type name | Create document (random document id) |
POST | 127.0.0.1:9200/index name/type name/document id/_update | Modify the document |
DELETE | 127.0.0.1:9200/index name/type name/document id | Delete document |
GET | 127.0.0.1:9200/index name/type name/document id | Query documents by document id |
POST | 127.0.0.1:9200/index name/type name/_search | Query all data |
1. Create an index
PUT /test1/type1/1
{
"name":"洪七公",
"age":3
}
2. Specify the type of field
Common field types
String type text, keyword
numeric type long, integer, short, byte, double, float, half float, scalet float
date type date
Boolean type boolean
binary type binary
etc...
Example: execute the following script
PUT /test2
{
"mappings": {
"properties": {
"name":{
"type": "text"
},
"age":{
"type": "long"
},
"birthday":{
"type": "date"
}
}
}
}
View Results:
3. GET command
GET test2
4. Get health value
GET _cat/health
5. Get version information
GET _cat/indices?v
6. Modify
6.1. Modification method 1
POST /test1/type1/1
{
"name":"张三丰",
"age":33
}
Execution:
Query:
6.2. Modification 2
POST /test1/type1/1/_update
{
"doc":{
"name":"六小龄童"
}
}
7, delete
DELETE test2
Special thanks: Mad God said Java