一、集群
- 健康状态
GET /_cat/health?v
- 集群节点
GET /_cat/nodes?v
二、索引
- 列表索引
GET /_cat/indices?v
- 存在判断
HEAD /goods
- 创建索引
PUT /goods
{
"settings": {
"number_of_shards": "2", // 分片数
"number_of_replicas": "2" // 副本数
}
}
- 查看索引
GET /goods
- 修改设置
PUT /goods/_settings
{
"number_of_replicas" : "4" // 分片数不可修改
}
- 查看设置
GET /goods/_settings
- 添加映射
PUT /goods/_mapping
{
"properties": {
"goodsId": {
"type": "keyword"
},
"goodsName": {
"type": "text",
"analyzer": "ik_max_word"
},
"price": {
"type": "float"
},
"classifyId": {
"type": "integer"
},
"addTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
- 创建索引时同时添加映射
PUT /goods
{
// 添加设置
"settings": {
"number_of_shards": "1",
"number_of_replicas": "1"
},
// 添加映射
"mappings": {
"properties": {
"goodsId": {
"type": "keyword"
},
"goodsName": {
"type": "text",
"analyzer": "ik_max_word"
},
"price": {
"type": "float"
},
"classifyId": {
"type": "integer"
},
"addTime": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
- 查看映射
GET /goods/_mapping
- 修改映射
对于已存在的mapping映射,可以添加新的字段,但不允许修改已存在的字段类型
- 删除索引
DELETE /goods
三、文档
- 新增自动ID
POST /goods/_doc
{
"id":1,
"goodsName":"华硕普通键盘",
"goodsPrice":56.56
}
新增指定ID
POST /goods/_doc/2
{
"id":2,
"goodsName":"华硕机械键盘",
"goodsPrice":488.88
}
-----------------------------
PUT /goods/_doc/3
{
"id":3,
"goodsName":"华硕有线鼠标",
"goodsPrice":39.39
}
覆盖更新
PUT /goods/_doc/1
{
"id":1,
"goodsName":"华硕普通键盘",
"goodsPrice":65.65
}
局部更新
POST /goods/_doc/1
{
"goodsPrice":77.77
}
指定删除
DELETE /goods/_doc/1
列表查询
GET /goods/_search
指定查询
GET /goods/_doc/1
是否存在
HEAD /goods/_doc/1
批量查询
GET /goods/_mget
{
"ids": [1,2]
}
---------------------------------
GET /bemall_goods/_mget
{
"docs": [
{
"_id": "1"
},
{
"_id": "2"
}
]
}
---------------------------------
GET /_mget
{
"docs": [
{
"_index": "product", # 跨索引
"_id": "1"
},
{
"_index": "goods", # 跨索引
"_id": "1"
}
]
}
附、参数
v:用来在管理类结果中返回表头
GET /_cat/indices?v
pretty:用来在查询类结果中美化响应的JSON输出
GET /goods/_doc/1?pretty
_source:用来在查询中只返回原始的JSON数据
GET /goods/_doc/1/_source