Elastic Search 命令详解-索引操作

关于Elastic Search安装可以参考《Elastic Search 8.6.2集群安装部署》及Kibana安装可以参考《Elastic Search 8.6.2简单操作》。相关命令将在Kibana工具的Console平台上执行。

Elastic Search索引操作主要包含:创建、删除、关闭和打开索引,以及索引别名的操作。其中,索引别名的操作在生产环境中使用比较广泛,可以和关闭或删除索引配合使用。在生产环境中使用索引时,都应该特别注意操作不当引起数据丢失或异常的问题。

1.创建索引

使用Elastic Search构建搜索引擎的第一步就是创建索引。创建索引以PUT方式发起请求,命令 PUT /indexName

PUT /customer

{

  "settings":{

    "number_of_shards": 5, 

    "number_of_replicas": 2

  },

  "mappings":{

    "properties":{

      "name":{

        "type":"text"

      },

      "age":{

        "type": "integer"

      }

    }

  }

}

{

  "acknowledged": true,

  "shards_acknowledged": true,

  "index": "customer"

}

        

2.删除索引

删除索引使用 DELETE /indexName

DELETE /customer

{

  "acknowledged": true

}

3.关闭索引

有些索引可能在暂时不使用,但未来可能还会使用时,就可以关闭该索引。索引关闭时,只能使用Elastic Search的Api或者监控工具来查看该索引的信息。此时对索引的读写操作都会报错:索引关闭异常。

POST /customer/_close

{

  "acknowledged": true,

  "shards_acknowledged": true,

  "indices": {

    "customer": {

      "closed": true

    }

  }

}

4.打开索引

索引关闭了,想重新使用可以再次打开索引。

POST /customer/_open

{

  "acknowledged": true,

  "shards_acknowledged": true

猜你喜欢

转载自blog.csdn.net/Yu_Yangjun/article/details/129852592
今日推荐