添加索引:
# lib是索引的名称
PUT /lib/
{
"settings":{
"index":{
# 设置默认索引分片个数,默认为5片
"number_of_shards": 5,
# 是数据备份数,如果只有一台机器,设置为0
"number_of_replicas": 0
}
}
}
出现以下返回信息,说明添加索引成功
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "lib"
}
查看索引信息:
查看单个索引
GET /lib/_settings
{
"lib": {
"settings": {
"index": {
"creation_date": "1559563866518",
"number_of_shards": "5",
"number_of_replicas": "0",
"uuid": "zyj2bshFSHKAz8Zsb3JN0A",
"version": {
"created": "6020499"
},
"provided_name": "lib"
}
}
}
}
查看所有索引
GET /_all/_settings
{
"lib": {
"settings": {
"index": {
"creation_date": "1559563866518",
"number_of_shards": "5",
"number_of_replicas": "0",
"uuid": "zyj2bshFSHKAz8Zsb3JN0A",
"version": {
"created": "6020499"
},
"provided_name": "lib"
}
}
},
"lib2": {
"settings": {
"index": {
"creation_date": "1559564183108",
"number_of_shards": "5",
"number_of_replicas": "0",
"uuid": "FK9GeEQrRCGx_VOAFe_OTg",
"version": {
"created": "6020499"
},
"provided_name": "lib2"
}
}
}
}
添加文档:
PUT /lib/user/1
{
"first_name":"Jane",
"last_name":"Smith",
"age":32,
"about":"I like to collect rock albums",
"interests":[ "music" ]
}
添加成功后会返回以下信息:
{
"_index": "lib",
"_type": "user",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
不指定id,用post请求
POST /lib/user/
{
"first_name":"Douglas",
"last_name":"Fir",
"age":23,
"about":"I like to build cabinets",
"interests":[ "forestry" ]
}
添加成功后返回以下信息:
生成的自动id是20的guid
{
"_index": "lib",
"_type": "user",
"_id": "V0pMHWsBe9Wb_OasyrkF",
"_version": 1,
"result": "created",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
查看文档
GET /lib/user/1
GET /lib/user/V0pMHWsBe9Wb_OasyrkF
GET /lib/user/1?_source=age,interests
{
"_index": "lib",
"_type": "user",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"interests": [
"music"
],
"age": 32
}
}
更新文档:
PUT /lib/user/1
{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : 36,
"about" : "I like to collect rock albums",
"interests": [ "music" ]
}
POST /lib/user/1/_update
{
"doc":{
"age":33
}
}
删除一个文档
DELETE /lib/user/1
删除一个索引
DELETE /lib