ES 创建索引设置(setting)基础

来源:互联网 发布:js点击图片显示大图 编辑:程序博客网 时间:2024/06/05 20:15

1.创建索引

PUT /my_index{    "settings": { ... any settings ... },    "mappings": {        "type_one": { ... any mappings ... },        "type_two": { ... any mappings ... },        ...    }}

如果你想禁止自动创建索引,你 可以通过在 config/elasticsearch.yml 的每个节点下添加下面的配置:

action.auto_create_index: false


2.索引设置

   索引设置分为staticdynamic,

 

static
They can only be set at index creation time or on a closed index.
dynamic
They can be changed on a live index using the update-index-settings API.

详见:https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules.html#index-modules-settings


修改分片和副本数:

PUT  /my_index{   "number_of_replicas":0,   "number_of_shards":1}


动态设置:

PUT  /my_index/_settings  {      "index" : {   "number_of_replicas":0    }} 



2.1 创建my_index 索引

使用默认配置:

POST /my_index/products/_bulk{ "index": { "_id": 1 }}{ "price" : 10, "productID" : "XHDK-A-1293-#fJ3" }{ "index": { "_id": 2 }}{ "price" : 20, "productID" : "KDKE-B-9947-#kL5" }{ "index": { "_id": 3 }}{ "price" : 30, "productID" : "JODL-X-1937-#pV7" }{ "index": { "_id": 4 }}{ "price" : 30, "productID" : "QQPX-R-3956-#aD8" }

查看该索引的设置: 5个分片,一个副本

GET /my_index/_settings{   "my_index": {      "settings": {         "index": {            "creation_date": "1507996404894",            "number_of_shards": "5",            "number_of_replicas": "1",            "uuid": "q3xU7mMKTUKmqEq4FUsswA",            "version": {               "created": "5050199"            },            "provided_name": "my_index"         }      }   }}


head 查看如下:




修改副本数量:(分片数不能动态修改)


PUT /my_index/_settings{     "number_of_replicas":0}----------------------{   "acknowledged": true}

副本删除了:




一次修改所有的索引副本数量:(强迫症,自己的虚拟机本来是2个节点的集群的,但每次只启动一台,所以建索引都是按照默认2个副本,不想你改配置,所以,又不想再head 上看到黄色的标识!!用下面全部修改下,线上环境慎用!)

PUT /_all/_settings{    "index": {"number_of_replicas":0}     }



原创粉丝点击