您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
完全群集重新启动与滚动升级以及elasticSearch多索引搜索
发布时间:2021-08-21 23:39:43编辑:雪饮阅读()
- 在Debian或Red Hat节点中 - 可以使用rmp或dpkg通过安装新软件包来升级节点。 不要覆盖配置文件。
- 在Windows(zip文件)或UNIX(tar文件) - 提取新版本,而不覆盖config目录。 您可以从旧安装复制文件或可以更改path.conf或path.data。
上次虽然安装了elasticSearch6.8.18,但是这里先切回我们之前的elasticSearch7.14.0
那么情况是这样的,就是后来考虑了一下,其实版本升级这个事情一般不做的,而且无论写从xxx版升级到yyy版,都无意义,实际上应该是在真正有需求的时候从需求所处elasticSearch版本升级到另外一个目标elasticSearch的,因为不同的版本升级之间的区别很大的。
那么关于完全集群重启的升级方式,实际上可以参考这篇文章:https://www.elastic.co/guide/en/elasticsearch/reference/7.14/restart-upgrade.html#_upgrading_your_cluster_2
既然完全群集重启的升级方式,暂时没有实践的意义,其实对应的滚动升级来说也是一样。
那么其实可以参考如下就知道了:
“
完全群集重新启动
此升级过程包括以下步骤 -
第1步 - 禁用碎片分配程序,并关闭节点。
PUT http://localhost:9200/_cluster/settings
{
"persistent": {
"cluster.routing.allocation.enable": "none"
}
}
在升级0.90.x到1.x的情况下使用以下请求 -
PUT http://localhost:9200/_cluster/settings
{
"persistent": {
"cluster.routing.allocation.disable_allocation": false,
"cluster.routing.allocation.enable": "none"
}
}
第2步 - 对Elasticsearch进行同步刷新 -
POST http://localhost:9200/_flush/synced
第3步 - 在所有节点上,终止所有 elastic 服务。
第4步 - 在每个节点上执行以下操作 -
第5步 - 从群集中的主节点(node.master设置为true,node.data设置为false的节点)开始重新启动节点。等待一段时间以建立群集。可以通过监视日志或使用以下请求进行检查 -
GET _cat/health or http://localhost:9200/_cat/health
GET _cat/nodes or http://localhost:9200/_cat/health
第6步 - 使用GET _cat/health请求监视集群的形成进度,并等待黄色响应,响应将是这样 -
1451295971 17:46:11 elasticsearch yellow 1 1 5 5 0 0 5 0 - 50.0%
第6步 - 启用分片分配过程,这是在第1步中禁用的,使用以下请求 -
PUT http://localhost:9200/_cluster/settings
{
"persistent": {
"cluster.routing.allocation.enable": "all"
}
}
在将0.90.x升级到1.x的情况下,请使用以下请求 -
PUT http://localhost:9200/_cluster/settings
{
"persistent": {
"cluster.routing.allocation.disable_allocation": true,
"cluster.routing.allocation.enable": "all"
}
}
它与完全群集重新启动相同,但第3步除外。在此,停止一个节点并进行升级。升级后,重新启动节点并对所有节点重复这些步骤。 启用分片分配过程后,可以通过以下请求监视:
GET http://localhost:9200/_cat/recovery
“
可以看到这两个升级方式之间的区别其实不是多么大的。
回到正题,这里接下来就是开始了elasticSearch的api约定了。
首先就是多索引下的搜索。这里所说的多索引搜索,就是指指定多个索引,然后进行搜索。
那么首先我这里有两个索引,这两个索引中的内容条目都是一样的,唯一不同的就是索引的名称,那么这两个索引中的所有内容的每个条目的索引都是schools,这个其实有点不合理,是当时添加测试数据为了简单,就只将批量添加的_bulk请求只修改了请求的索引名,而没有修改每个内容条目中的索引名,关键是当时也没有想到这点。那么这里暂且先这样了。
那么用postman去实现schools和schools这两个索引中我搜索Central则请求url如:
http://localhost:9200/schools,schools2/_search
那么就我个人认为因为要发送请求正文,一般如json的话就是postman中的raw请求正文,那么一般都是POST,这里的请求方法就是POST了。
那么请求体如:
{
"query":{
"query_string":{
"query":"Central"
}
}
}
那么最后的请求结果如:
{
"took": 43,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1.0417082,
"hits": [
{
"_index": "schools",
"_type": "school",
"_id": "1",
"_score": 1.0417082,
"_source": {
"name": "Central School",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2000,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.5"
}
}
]
}
}
可以看到这里hits只命中了一个索引就是schools,按理来说应该是schools和schools2,为什么出现这种情况,大概就是因为上面我所说的当时添加的测试数据不合理导致的。
那么我们删除掉schools和schools2这两个索引后分别重建schools和schools2这两个索引并批量添加数据进去如:
Schools索引创建
http://localhost:9200/schools/_bulk post
{"index":{"_index":"schools", "_type":"school", "_id":"1"}}
{"name":"Central School","description":"CBSE Affiliation","street":"Nagan","city":"paprola","state":"HP","zip":"176115","location":[31.8955385, 76.8380405],"fees":2000,"tags":["Senior Secondary","beautiful campus"], "rating":"3.5"}
{"index":{"_index":"schools", "_type":"school", "_id":"2"}}
{"name":"Saint Paul School", "description":"ICSE Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075","location":[28.5733056, 77.0122136], "fees":5000,"tags":["Good Faculty", "Great Sports"], "rating":"4.5"}
{"index":{"_index":"schools", "_type":"school", "_id":"3"}}
{"name":"Crescent School", "description":"State Board Affiliation", "street":"Tonk Road", "city":"Jaipur", "state":"RJ", "zip":"176114","location":[26.8535922, 75.7923988],"fees":2500, "tags":["Well equipped labs"],"rating":"4.5"}
Schools2索引创建
http://localhost:9200/schools2/_bulk post
{"index":{"_index":"schools2", "_type":"school", "_id":"1"}}
{"name":"Central School","description":"CBSE Affiliation","street":"Nagan","city":"paprola","state":"HP","zip":"176115","location":[31.8955385, 76.8380405],"fees":2000,"tags":["Senior Secondary","beautiful campus"], "rating":"3.5"}
{"index":{"_index":"schools2", "_type":"school", "_id":"2"}}
{"name":"Saint Paul School", "description":"ICSE Afiliation", "street":"Dawarka", "city":"Delhi", "state":"Delhi", "zip":"110075","location":[28.5733056, 77.0122136], "fees":5000,"tags":["Good Faculty", "Great Sports"], "rating":"4.5"}
{"index":{"_index":"schools2", "_type":"school", "_id":"3"}}
{"name":"Crescent School", "description":"State Board Affiliation", "street":"Tonk Road", "city":"Jaipur", "state":"RJ", "zip":"176114","location":[26.8535922, 75.7923988],"fees":2500, "tags":["Well equipped labs"],"rating":"4.5"}
那么接下来多索引搜索再次请求下的结果就正常了:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1.8042282,
"hits": [
{
"_index": "schools",
"_type": "school",
"_id": "1",
"_score": 1.8042282,
"_source": {
"name": "Central School",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2000,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.5"
}
},
{
"_index": "schools2",
"_type": "school",
"_id": "1",
"_score": 1.0417082,
"_source": {
"name": "Central School",
"description": "CBSE Affiliation",
"street": "Nagan",
"city": "paprola",
"state": "HP",
"zip": "176115",
"location": [
31.8955385,
76.8380405
],
"fees": 2000,
"tags": [
"Senior Secondary",
"beautiful campus"
],
"rating": "3.5"
}
}
]
}
}
关键字词:elasticSearch,多索引,指定索引
相关文章
- elasticSearch安装及配置elasticSearch默认对外端口
- windows下使用elasticSearch-head为elasticSearch进行
- windows下使用elasticSearch-head为elasticSearch创建
- 配置elasticSearch-head连接elasticSearch服务
- 配置安装elasticSearch-head
- elasticSearch创建映射和添加数据(_bulk批处理)
- elasticSearch创建没有正文的空索引
- elasticSearch无需查询即可进行过滤(match_all、分数
- elasticSearch过滤与布尔查询
- elasticSearch指定搜索的字段