一、创建索引

PUT /索引名/~类型名~/文档id
{请求体}

  1. PUT /test1/type1/1
  2. {
  3. "name":"林大侠",
  4. "age": "18"
  5. }

这里我执行了两次,result则是updated状态~
image.png
完成自动增加索引,数据成功添加,类似数据库学习!
image.png

1.1.字段类型

  • 字符串类型 text 、keyword
  • 数值类型 long、integer、short、byte、doubel、float、half float、scaled float
  • 日期类型 date
  • 布尔值类型 boolean
  • 二进制类型 binary
  • ……………………….

    二、创建索引,指定字段类型

    2.1.创建索引规则

    1. PUT /test2
    2. {
    3. "mappings": {
    4. "properties": {
    5. "name":{
    6. "type": "text"
    7. },
    8. "age":{
    9. "type": "long"
    10. },
    11. "birthday":{
    12. "type": "date"
    13. }
    14. }
    15. }
    16. }
    image.png

    2.3.2.获取索引规则

    1. GET test2

    image.png

    三、查看默认信息

    3.1.新建索引

    1. PUT /test3/_doc/1
    2. {
    3. "name": "林大侠",
    4. "age": "18",
    5. "brith": "1996-11-28"
    6. }
    image.png

    3.2.查看索引

    如果文档字段没有指定,那么ES就会默认配置字段类型!
    1. GET test3
    image.png

    四、查看所有索引

    1. GET _cat/indices?v
    image.png

    五、修改索引

    5.1.方式一之PUT

    1. PUT /test3/_doc/1
    2. {
    3. "name": "林大侠666",
    4. "age": "18",
    5. "brith": "1996-11-28"
    6. }
    image.png

    5.2.方式二之POST

    1. POST /test3/_doc/1/_update
    2. {
    3. "doc":{
    4. "name": "林大侠777"
    5. }
    6. }
    image.png

    六、删除索引

    1. DELETE test1

image.png
删除前
image.png
删除后
image.png