重建索引过程

# 创建索引 index1v1
curl -X PUT http://localhost:9200/index1v1?pretty

# 给索引 index1v1 创建别名 index1,做增删改查使用别名
# 好处是 如果想要更改_mapping,可以通过重建索引的方式,不停机即可实现更改
curl -X PUT "http://localhost:9200/_alias?pretty" -H 'Content-Type: application/json' -d'
{
  "actions": [
     {
        "add": {
          "index": "index1v1",
          "alias": "index1"
        }
      }
  ]
}
'

# 给索引index1的文档 book1 设置 mapping,这里给publishDate建text类型
# 之后演示重建索引重新设置mapping,将publishDate更改为date类型
curl -X POST "http://localhost:9200/index1/book1/_mapping?pretty" -H 'Content-Type: application/json' -d'
{
    "book1": {
		"properties": {
			"bookId": {
				"type": "long"
			},
			"bookName": {
				"type": "text"
			},
			"publishDate": {
				"type": "text"
			}
		}
	}
}
'

# 插入数据
curl -X PUT "http://localhost:9200/index1/book1/1?pretty" -H 'Content-Type: application/json' -d'
{
  "bookId":1,
  "bookName":"Java程序设计",
  "publishDate":"2018-01-12"
}
'

# 重建索引 步骤1
# 重建索引前 先建立 index1v2,设置最终的mapping后,再执行 重建索引
curl -X PUT http://localhost:9200/index1v2?pretty
curl -H 'Content-Type: application/json' -X POST "http://localhost:9200/index1v2/book1/_mapping?pretty" -d'
{
    "book1": {
		"properties": {
			"bookId": {
				"type": "long"
			},
			"bookName": {
				"type": "text"
			},
			"publishDate": {
				"type": "date"
			}
		}
	}
}
'

# 重建索引 步骤2
# 重建索引 数据从index1v1索引重建到index1v2索引 文档 book
# wait_for_completion=false 将不等待重建完成,接口返回 taskid 
# 使用 GET _tasks/{taskID} 查看重建进度
curl -X POST "http://localhost:9200/_reindex?wait_for_completion=false" -H 'Content-Type: application/json' -d'
{
    "source": { "index": "index1v1", "type": "book1" },
	"dest": { "index": "index1v2", "type": "book1" }
}
'

# 重建索引 步骤3
# 切索引别名
curl -X POST "http://localhost:9200/_aliases?pretty" -H 'Content-Type: application/json' -d'
{
    "actions": [
        { "remove": { "index": "index1v1", "alias": "index1" }},
        { "add":    { "index": "index1v2", "alias": "index1" }}
    ]
}
'

# 重建索引 步骤4
# 删除原index1v1索引
curl -X DELETE "http://localhost:9200/index1v1?pretty"

 

转载于:https://my.oschina.net/tita/blog/3058163

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值