ElasticSearch的reIndex
来源:互联网 发布:谷歌输入法mac版 编辑:程序博客网 时间:2024/05/21 21:26
由于Elasticsearch已创建的index是不允许修改的,其原因是由于创建的时候就会创建倒排索引,但是此时应用程序已经在使用了该索引,并且不允许应用暂停,那么怎么去处理这样的事情呢?下面就是一个比较靠谱的解决方案,就是使用alias,scroll api,bucket api。
具体案例如下:
保存数据
PUT /index_before/type_before/1
{
"title":"2017-01-01"
}
查询数据
GET index_before/_mapping/type_before
结果发现类型不对
{
"index_before": {
"mappings": {
"type_before": {
"properties": {
"title": {
"type": "date"
}
}
}
}
}
}
设置别名,index_mid中间过渡(java程序可以使用别名的index),指向之前的索引
PUT index_before/_alias/index_mid
新建正确类型的索引
PUT /index_after
{
"mappings": {
"type_before":{
"properties": {
"title":{
"type": "string"
}
}
}
}
}
使用scroll api获得原始数据
GET index_before/_search?scroll=1m
{
"query": {
"match_all": {}
},
"sort": [
"_doc"
],
"size": 1
}
使用bulk api将查询的数据转存到新的索引中去
POST /_bulk
{"index":{"_index":"index_after","_type":"type_before","_id":1}}
{"title":"2017-01-01"}
更改索引别名
POST /_aliases
{
"actions": [
{ "remove": { "index": "index_before", "alias": "index_mid" }},
{ "add":{ "index": "index_after", "alias": "index_mid" }}
]
}
使用别名查询
GET index_mid/type_before/_search
结果就可以了
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "index_after",
"_type": "type_before",
"_id": "1",
"_score": 1,
"_source": {
"title": "2017-01-01"
}
}
]
}
}
阅读全文
0 0
- ElasticSearch的reIndex
- elasticsearch reindex 工具汇总
- ElasticSearch reindex by JAVA API
- Elasticsearch 5.x Document Reindex
- elasticsearch之Document APIs【Reindex API】
- Elasticsearch索引管理-reindex重建索引
- elasticsearch 重建索引 使用python迁移索引数据 reindex
- python pandas 对series和dataframe的重置索引reindex
- gerrit reindex
- 关于pandas中update的报错cannot reindex from a duplicate axis
- SQLite语法 REINDEX
- gerrit reindex错误
- AX 2009 table reindex
- Reindex API 详解
- JanusGraph重新索引reindex
- pandas dataframe在指定的位置添加一列, 或者一次性添加几列,reindex,pd.concat的使用
- ElasticSearch 个人笔记-ElasticSearch 的安装
- 使用Elasticsearch的java api,操作elasticsearch
- NOIP 2017 Day2 题2:宝藏 状态压缩
- 75. Sort Colors
- 机器学习笔记(XII)决策树(II)剪枝处理
- 关于html5中的部分标签,在IE9以下的支持情况
- nova 中的taskflow的实现
- ElasticSearch的reIndex
- Gobblin data quality checker
- IT风投
- RecyclerView 自适应高度
- vim内容替换命令
- python学习之argparse模块
- JAVA 三 变量,运算符
- 虐,虐,虐,传统超市都被虐了,如何实现涅槃!
- 解决使用adb命令提示“通常每个套接字地址(协议/网络地址/端口)只允许使用一次”错误