集群操作
- 查看集群健康情况
GET /_cat/health?v
- 查看索引状态
GET /_cat/indices?v
索引操作
- 创建索引
put /xiniu1
- 删除索引
delete /xiniu1
- 创建索引并制定mapping映射
PUT /xiniu
{
"mappings": {
"properties": {
"title": { "type": "text" },
"name": { "type": "text" },
"age": { "type": "integer" },
"created": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
}
}
}
}
- 查看mapping
GET /xiniu/_mapping
- 插入数据
# 不指定id
POST /xiniu/_doc
{
"name":"ls",
"title":"李四",
"age":28,
"created":"2021-06-04"
}
# 指定id插入
POST /xiniu/_doc/1
{
"name":"ls",
"title":"李四",
"age":28,
"created":"2021-06-04"
}
- 查询文档
GET /xiniu/_doc/1
- 修改文档内容
PUT /xiniu/_doc/1
{
"name":"lls",
"title":"李老四"
}
- 删除文档内容
delete /xiniu/_doc/1
- 批量插入
# 使用_bulk方式批量插入
POST /xiniu/_doc/_bulk
{"index":{}}
{"name":"zhaoy","title":"赵杨","age":18,"created":"2021-06-05"}
{"index":{}}
{"name":"yux","title":"宇鑫","age":25,"created":"2021-06-05"}
搜索篇
- 批量插入(指定id)
# 批量插入测试数据
POST /hainiu/user/_bulk
{"index":{"_id":1}}
{"name":"laoli","realname":"老李","age":28,"birthday":"2012-11-17","salary":20000.0,"address":"北京市昌平区"}
{"index":{"_id":2}}
{"name":"laozhang","realname":"老张","age":20,"birthday":"2012-12-21","salary":2000.0,"address":"北京市朝阳区"}
{"index":{"_id":3}}
{"name":"laowang","realname":"老王","age":25,"birthday":"2015-06-16","salary":3300.0,"address":"北京市海淀区"}
{"index":{"_id":4}}
{"name":"laosun","realname":"老孙","age":20,"birthday":"2006-06-16","salary":15300.0,"address":"北京市海淀区中关村软件园"}
{"index":{"_id":5}}
{"name":"laozhao","realname":"老赵","age":35,"birthday":"2011-06-16","salary":1303.0,"address":"北京市海淀区西二旗"}
- 查询所有数据并排序
GET /hainiu/user/_search
{
"query":{
"match_all": {}
},
"sort":{
"age":"desc"
}
}
- 分页查询
GET /hainiu/user/_search
{
"query":{
"match_all": {}
},
"sort":{
"age":"desc"
},
"from":0,
"size":2
}
- 匹配查询
GET /hainiu/user/_search
{
"query":{
"match": {
"birthday": "2015-06-16"
}
}
}
- 精确查询
GET /hainiu/user/_search
{
"query":{
"term": {
"name": {
"value": "laoli"
}
}
}
}
- 范围查询
GET /hainiu/user/_search
{
"query":{
"range": {
"age": {
"gte": 15,
"lte": 24
}
}
}
}