***1. 插入操作 create ***
The difference between POST and PUT is that PUT requests are idempotent (幂等).
post 请求每次都会新增一条记录,所以可以不指定ID
POST my_test/_doc
{
"NAME": "TOMAS",
"AGE": 20,
"MEMBERS": "SISTER"
}
PUT 请求是幂等,无论请求多少次,都只会有一条记录,所以需要指定ID
PUT my_test/_doc/1
{
"NAME": "KD",
"AGE": 30,
"MEMBERS": "MONTHER"
}
2. 更新操作 update
PUT my_test/_doc/1
{
"AGE": 21,
}
post 请求若不指定ID, 则会随机更新一条
POST my_test/_doc
{
"AGE": 22,
}
3. 读取操作 read
GET my_test/_doc/1
全匹配范围查询
GET my_test/_search/
{
"size": 20,
"query": {
"match_all": {}
},
"sort": {
"AGE": "desc"
}
}
按字段内容范围查询
GET my_test/_search/
{
"size": 20,
"query": {
"constant_score": {
"filter": {"range": {
"AGE": {
"gte": 10,
"lte": 20
}
}},
"boost": 1.2
}
}
}
按字段内容匹配查询
GET my_test/_search/
{
"query": {
"match": {
"AGE": 21
}
}
}
4. 删除操作 delete
DELETE my_test/_doc/1