一、RESTAPI

# 查看版本信息
http://192.168.17.101:9200/
image-20201225143648002
# 查看支持的命令
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
......
image-20201225143818816
# 显示详细的信息,每个命令都支持使用?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
......
image-20201225144120503
# 输出可以显示的列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
......
image-20201225150358004
# 指定输出的字段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
......
image-20201225151441020

help查看支持的列字段

image-20201225151537020

h指定输出列字段

image-20201225151630964

二、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自动生成

image-20201225154722825

指定ID的值

image-20201225155346944

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": "混泥土瞬间移动工程师"
    }
}
image-20201225160107828

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
}
image-20201225160727668

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
}
image-20201225162137632