ES reindex 数据类型修改

获取mapping

GET http://xxx:9200/demo_index/_mapping

{
    "demo_index": {
        "mappings": {
            "online": {
                "properties": {
                    "did_number": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "end_time": {
                        "type": "long"
                    },
                    "id": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "start_time": {
                        "type": "long"
                    },
                }
            }
        }
    }
}

将字段的类型修改为正确类型

{
    "demo_index": {
        "mappings": {
            "online": {
                "properties": {
                    "did_number": {
                        "type": "keyword",
                    },
                    "end_time": {
                        "type": "long"
                    },
                    "id": {
                        "type": "keyword"
                    },
                    "start_time": {
                        "type": "long"
                    },
                }
            }
        }
    }
}

新建index_new

PUT http://xxx:9200/demo_index_new

{
        "mappings": {
            "online": {
                "properties": {
                    "did_number": {
                        "type": "keyword",
                    },
                    "end_time": {
                        "type": "long"
                    },
                    "id": {
                        "type": "keyword"
                    },
                    "start_time": {
                        "type": "long"
                    },
                }
            }
        }
}

迁移数据

POST http://xxx:9200/_reindex
{
  "source": {
    "index": "demo_index"
  },
  "dest": {
    "index": "demo_index_new"
  }
}

先删除旧索引

DELETE http://xxx:9200/demo_index

添加别名

POST http://xxx:9200/_aliases
{
"actions": [
{"add": {"index": "demo_index_new", "alias": "demo_index"}}
]
}

你可能感兴趣的:(ES reindex 数据类型修改)