版本说明
本文基于Elasticsearch6.4.0版本
创建索引
PUT /order
返回如下信息,则表示创建成功
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "order"
}
查询索引信息
GET /order
索引信息
{
"order": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"creation_date": "1618916346622",
"number_of_shards": "5",
"number_of_replicas": "1",
"uuid": "c89QFkZKSK2m5FhiaS8crA",
"version": {
"created": "6040099"
},
"provided_name": "order"
}
}
}
}
Index Settings
指定一些index设置的索引,比如指定number_of_replicas(副本)为2,number_of_shards(分片)为3。
如不指定,默认副本为1,分片为5。
PUT /order
{
"settings": {
"number_of_replicas": 2,
"number_of_shards": 3
}
}
查看索引
GET /order
索引信息
{
"order": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"creation_date": "1618916387112",
"number_of_shards": "3",
"number_of_replicas": "2",
"uuid": "qnaUfiSyQsSgO6IF58i2Xw",
"version": {
"created": "6040099"
},
"provided_name": "order"
}
}
}
}
Mappings
建立索引时,同时指定mapping
如下表示,创建一个名为emp的索引,并定义了索引中有一个name字段,类型为keyword
PUT /emp
{
"mappings": {
"_doc":{
"properties":{
"name":{"type":"keyword"}
}
}
}
}
查看索引下的mapping信息
GET /emp/_mapping/
索引下的mapping信息
{
"emp": {
"mappings": {
"_doc": {
"properties": {
"name": {
"type": "keyword"
}
}
}
}
}
}
删除索引
DELETE /order
返回如下信息表示删除成功
{
"acknowledged": true
}
也可以直接删除所有索引
DELETE /*
查看索引是否存在,如果存在返回 200 - OK,否则返回 404 - Not Found
HEAD /order
关闭索引
POST /my_index/_close
再查询时,报索引被关闭的错误
{
"error": {
"root_cause": [
{
"type": "index_closed_exception",
"reason": "closed",
"index_uuid": "ixA8QpgLQDOaOj09Amm3dw",
"index": "emp"
}
],
"type": "index_closed_exception",
"reason": "closed",
"index_uuid": "ixA8QpgLQDOaOj09Amm3dw",
"index": "emp"
},
"status": 400
}
开启索引
POST /my_index/_open