es索引库配置

索引库配置

settings就是用来修改索引分片和副本数的;

比如有的重要索引,副本数很少甚至没有副本,那么我们可以通过setting来添加副本数

DELETE document
PUT document
{
  "mappings": {
    "article" : {
      "properties":
      {
        "title" : {"type": "text"} , 
        "author" : {"type": "text"} , 
        "titleScore" : {"type": "double"} 
        
      }
    }
  }
}
GET /document/_settings

为了提高容错性,我们可以把副本数改成3或者其他的值

PUT /document/_settings
{
  "number_of_replicas": 3
}

副本可以改,分片不能改。

零停机重新索引数据

我们知道es在字段的mapping建立后就不可再次修改mapping的值。但实际业务中,有时候会需要根据业务修改字段的类型等。

新建索引库articles1,并添加数据
DELETE articles1
PUT articles1
{  
    "settings":{  
         "number_of_shards":3,  
         "number_of_replicas":1  
    },  
    "mappings":{  
         "article":{  
             "dynamic":"strict",  
             "properties":{  
                 "id":{"type": "text", "store": true},  
                 "title":{"type": "text","store": true}, 
                 "readCounts":{"type": "integer","store": true},  
                 "times": {"type": "text", "index": false}
             }  
         }  
    }  
}


PUT articles1/article/1
{
  "id" : "1",
  "title" : "world",
  "readCounts" : 2 , 
  "times" : "2018-09-01"
}

新建索引库articles2
DELETE articles2
PUT articles2
{  
    "settings":{  
         "number_of_shards":5,  
         "number_of_replicas":1  
    },  
    "mappings":{  
         "article":{  
             "dynamic":"strict",  
             "properties":{  
                 "id":{"type": "text", "store": true},  
                 "title":{"type": "text","store": true}, 
                 "readCounts":{"type": "integer","store": true},  
                 "times": {"type": "date", "index": false}
             }  
         }  
    }  
}  
}

拷贝数据并验证
POST _reindex
{
  "source": {
    "index": "articles1"
  },
  "dest": {
    "index": "articles2"
  }
}

GET articles2/article/1

在这里插入图片描述

经测试发现,数据的分片已经从3变了5.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值