es 不停机更新索引

索引更新方法

1. 新建索引 product_v2          ==>  i 
2. 将老索引数据导入新索引         ==>  ii
3. 删除老索引别名,新建新索引别名   ==>  iii

i 新建产品索引

PUT /product_v2

{
    "settings": {
        "analysis": {
            "analyzer": {
                "ik": {
                    "tokenizer": "ik_smart"
                },
                "douhao": {
                    "tokenizer": "douhao_tokenizer"
                }
            },
            "tokenizer": {
                "douhao_tokenizer": {
                    "type": "pattern",
                    "pattern": ","
                }
            }
        }
    },
    "mappings": {
        "record": {
            "properties": {
                "productGoodsId": {
                    "type": "long"
                },
                "productName": {
                    "type": "text",
                    "analyzer": "ik_smart",
                    "search_analyzer": "ik_smart"
                },
                "originalPrice": {
                    "type": "double"
                },
                "promotionPrice": {
                    "type": "double"
                },
                "salesVolume": {
                    "type": "long"
                },
                "picturePath": {
                    "enabled": "false"
                },
                "selfSupport": {
                    "type": "long"
                },
                "eipMemberId": {
                    "type": "long"
                },
                "eipMemberName": {
                    "type": "text",
                    "analyzer": "ik_smart",
                    "search_analyzer": "ik_smart"
                },
                "clickVolume": {
                    "type": "long"
                },
                "isNew": {
                    "type": "long"
                },
                "updateTime": {
                    "type": "date",
                    "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
                },
                "categoryId": {
                    "type": "long"
                },
                "category_id_lv1": {
                    "type": "long"
                },
                "category_id_lv2": {
                    "type": "long"
                },
                "brand": {
                    "type": "keyword"
                },
                "specOptionName": {
                    "type": "text",
                    "analyzer": "douhao"
                },
                "unit": {
                    "enabled": "false"
                },
                "customCategoryId": {
                    "type": "text",
                    "analyzer": "douhao"
                },
                "gramWeight": {
                    "type": "double"
                },
                "kind": {
                    "type": "keyword"
                }
            }
        }
    }
}

ii 将老索引导入新索引办法

POST /_reindex

{"source":{"index":"products_v1"},"dest":{"index":"products_v2"}}

iii 新建索引别名方法

PUT /_aliases

{"actions":[{"remove":{"alias":"product","index":"products_v1"}},{"add":{"alias":"product","index":"products_v2"}}]}

你可能感兴趣的:(es 不停机更新索引)