所有操作基本7.0版本
1、创建一个名为“test”的索引
PUT test
2、向test索引中添加一个_id值为1文档
PUT /test/_doc/1
{
"msg":"Hello,world!"
}
3、在test索引中查询_id值为1的文档
GET /test/_doc/1
4、创建一个users映射类型,并设置数据类型
PUT users
{
"mappings":{
"properties":{
"name":{ "type":"text"},
"age":{ "type":"integer"},
"address":{"type":"text"}
}
}
}
5、创建索引设置分片数和副本分片数
PUT /test
{
"settings":{
"number_of_shards":10,
"number_of_replicas":2
}
}
6、为索引创建一个代表一年级的别名grade1
PUT /student/_alias/grade1
{
"filter":{
"term":{
"grade":1
}
}
}
7、向已创建的索引添加映射字段
PUT /students/mappings
{
"properties":{
"age":{
"type":"short"
}
}
}
8、查询多个文档
GET _mget
{
"docs":[
{
"_index":"students",
"name":"tom"
},
{
"_index":"user"
"age":14
}
]
}
9、按照文档编号删除文档
DELETE /users/_doc/1
10、按照查询条件删除文档
POST /users/_delete_by_query
{
"query":{
"match":{
"name":"tom"
}
}
}
11、按照标号更新文档字段
POST /students/_update/1
{
"doc":{
"age":16
}
}
12、更新不存在此文档则创建此文档
POST /students/_update/5
{
"doc":{
"age":16
},
"upsert":{
"name":"tom",
"age":16
}
}
POST /students/_update/6
{
"doc":{
"age":16
},
"doc_as_upsert":true
}