Elasticsearch学习---索引(index)的基本操作

版本说明

本文基于Elasticsearch6.4.0版本
在这里插入图片描述

创建索引

PUT /order

返回如下信息,则表示创建成功

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "order"
}

查询索引信息

GET /order

索引信息

{
  "order": {
    "aliases": {},
    "mappings": {},
    "settings": {
      "index": {
        "creation_date": "1618916346622",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "c89QFkZKSK2m5FhiaS8crA",
        "version": {
          "created": "6040099"
        },
        "provided_name": "order"
      }
    }
  }
}

Index Settings

指定一些index设置的索引,比如指定number_of_replicas(副本)为2,number_of_shards(分片)为3。

如不指定,默认副本为1,分片为5。

PUT /order
{
  "settings": {
    "number_of_replicas": 2,
    "number_of_shards": 3
  }
}

查看索引

GET /order

索引信息

{
  "order": {
    "aliases": {},
    "mappings": {},
    "settings": {
      "index": {
        "creation_date": "1618916387112",
        "number_of_shards": "3",
        "number_of_replicas": "2",
        "uuid": "qnaUfiSyQsSgO6IF58i2Xw",
        "version": {
          "created": "6040099"
        },
        "provided_name": "order"
      }
    }
  }
}

Mappings

建立索引时,同时指定mapping

如下表示,创建一个名为emp的索引,并定义了索引中有一个name字段,类型为keyword

PUT /emp
{
  "mappings": {
    "_doc":{
      "properties":{
        "name":{"type":"keyword"}
      }
    }
  }
}

查看索引下的mapping信息

GET /emp/_mapping/

索引下的mapping信息

{
  "emp": {
    "mappings": {
      "_doc": {
        "properties": {
          "name": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

删除索引

DELETE /order

返回如下信息表示删除成功

{
  "acknowledged": true
}

也可以直接删除所有索引

DELETE /*

查看索引是否存在,如果存在返回 200 - OK,否则返回 404 - Not Found

HEAD /order

关闭索引

POST /my_index/_close

再查询时,报索引被关闭的错误

{
  "error": {
    "root_cause": [
      {
        "type": "index_closed_exception",
        "reason": "closed",
        "index_uuid": "ixA8QpgLQDOaOj09Amm3dw",
        "index": "emp"
      }
    ],
    "type": "index_closed_exception",
    "reason": "closed",
    "index_uuid": "ixA8QpgLQDOaOj09Amm3dw",
    "index": "emp"
  },
  "status": 400
}

开启索引

POST /my_index/_open
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码拉松

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值