一、RESTAPI
# 查看版本信息
http://192.168.17.101:9200/
# 查看支持的命令
http://192.168.17.101:9200/_cat
# 比如
http://192.168.17.101:9200/_cat/allocation
http://192.168.17.101:9200/_cat/shards
http://192.168.17.101:9200/_cat/templates
......
# 显示详细的信息,每个命令都支持使用?v参数,来显示详细的信息
http://192.168.17.101:9200/_cat/indices?v
# 比如
http://192.168.17.101:9200/_cat/allocation?v
http://192.168.17.101:9200/_cat/shards?v
http://192.168.17.101:9200/_cat/templates?v
......
# 输出可以显示的列help,每个命令都支持使用help参数,来输出可以显示的列
http://192.168.17.101:9200/_cat/indices?help
# 比如
http://192.168.17.101:9200/_cat/allocation?help
http://192.168.17.101:9200/_cat/shards?help
http://192.168.17.101:9200/_cat/templates?help
......
# 指定输出的字段headers,通过h参数,可以指定输出的字段
http://192.168.17.101:9200/_cat/indices?h=uuid,health,status,creation.date.string
# 比如可以根据help查看可以输出的列,然后通过h指定输出所需要的列字段
http://192.168.17.101:9200/_cat/master?help
http://192.168.17.101:9200/_cat/master?h=id,host,ip
......
help查看支持的列字段
h指定输出列字段
二、CRUD
以下操作在postman执行
2.1 索引
# 添加一个spring索引,PUT请求
http://192.168.17.101:9200/spring
# 查询一个spring索引,GET请求
http://192.168.17.101:9200/spring
# 删除一个spring索引,DELETE请求
http://192.168.17.101:9200/spring
2.2 文档
2.2.1 添加
# POST请求,不指定ID自动生成
http://192.168.17.101:9200/account/_doc
# PUT请求,指定ID为875667601
http://192.168.17.101:9200/account/_doc/875667601
# 请求体
{
"accountName": "小强崽",
"accountBalance": "45",
"accountPosition": "混泥土瞬间移动工程师"
}
# 响应体
{
"_index": "account",
"_type": "_doc",
"_id": "ynzbmHYBxPa82iN0CYzM",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
ID自动生成
指定ID的值
2.2.2 查询
# GET请求,指定ID的值
http://192.168.17.101:9200/account/_doc/875667601
# 响应体
{
"_index": "account",
"_type": "_doc",
"_id": "875667601",
"_version": 6,
"found": true,
"_source": {
"accountName": "小强崽",
"accountBalance": "45",
"accountPosition": "混泥土瞬间移动工程师"
}
}
2.2.3 修改
# POST请求,指定ID的值
http://192.168.17.101:9200/account/_doc/875667601
# 请求体
{
"accountName": "小强",
"accountBalance": "45",
"accountPosition": "混泥土瞬间移动工程师"
}
# 响应体
{
"_index": "account",
"_type": "_doc",
"_id": "875667601",
"_version": 7,
"result": "updated",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 8,
"_primary_term": 1
}
2.2.4 删除
# DELETE请求,指定ID的值
http://192.168.17.101:9200/account/_doc/875667601
# 响应体
{
"_index": "account",
"_type": "_doc",
"_id": "875667601",
"_version": 8,
"result": "deleted",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 9,
"_primary_term": 1
}