一 Index
- 索引
索引中存儲相同結構的文檔互广,每個索引有自己的mapping定義十拣,用于定義字段名和類型昭雌;
- 操作
#創(chuàng)建索引
PUT /test_index
#獲取所有索引
GET _cat/indices
#刪除索引
DELETE test_index
二 Document
- 文檔
由字段JsonObject組成,每個文檔有唯一的id標識奕枢,可以自行指定娄昆,也可以自動生成;
每個文檔有元數據缝彬,用于標注文檔的相關信息萌焰,_index/-type/_id/_uid/_source等;
- 操作
#創(chuàng)建文檔指定id
PUT /test_index/doc/1
{
"username":"alfred",
"age":1
}
#創(chuàng)建文檔不指定id
POST /test_index/doc
{
"username":"tom",
"age":20
}
#查詢文檔指定id
GET /test_index/doc/1
#查詢所有文檔
GET /test_index/doc/_search
#批量添加文檔
#index/create/delete/update index創(chuàng)建時可以替換文檔谷浅,create創(chuàng)建時不可以替換
POST _bulk
{"index":{"_index":"test_index","_type":"doc","_id":"3"}}
{"username":"alfred","age":20}
{"delete":{"_index":"test_index","_type":"doc","_id":"1"}}
{"update":{"_id":"2","_index":"test_index","_type":"doc"}}
{"doc":{"age":"20"}}
#批量查詢文檔
GET /_mget
{
"docs": [
{"_index": "test_index","_type": "doc","_id": "3"},
{"_index": "test_index","_type": "doc","_id": "2"}
]
}