elasticsearch 并不支持修改mapping映射字段中的信息,如:字段类型、字段名称、分词器等。

需要先创建一个新的索引(mapping用最新的),复制原索引中的数据,删除旧索引(删除前必须检查原索引中的数据是否全部复制到新索引中),设置别名。具体步骤如下:

步骤1:查看原索引mapping&settings

原索引:mapping&settings

GET rosegal/_mapping
{
    "mappings": {
      "sku": {
        "dynamic": "false",
        "_all": {
          "enabled": false
        },
        "properties": {
          "addTime": {
            "type": "long",
            "fields": {
              "raw": {
                "type": "date",
                "format": "epoch_second"
              }
            }
          },
          "appPrice": {
            "type": "double"
          },
          "attentionNum": {
            "type": "integer"
          },
          "availableStock": {
            "type": "integer"
          },
          "baseField": {
            "type": "nested",
            "properties": {
              "itemNo": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              },
              "name": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              },
              "value": {
                "type": "keyword",
                "copy_to": [
                  "searchWords"
                ]
              }
            }
          },
          "baseScore1": {
            "type": "double"
          },
          "baseScore2": {
            "type": "double"
          },
          "baseScore3": {
            "type": "double"
          },
          "baseScore4": {
            "type": "double"
          },
          "baseScore5": {
            "type": "double"
          },
          "catId": {
            "type": "integer"
          },
          "categories": {
            "type": "nested",
            "properties": {
              "catId": {
                "type": "integer"
              },
              "catName": {
                "type": "text"
              },
              "level": {
                "type": "integer"
              }
            }
          },
          "clickCount": {
            "type": "integer"
          },
          "colorAttr": {
            "type": "text",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "whitespace_analyzer"
              },
              "raw": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              }
            },
            "copy_to": [
              "searchWords"
            ],
			"analyzer": "shingle_analyzer"
          },
          "cxj": {
            "type": "float"
          },
          "day3Sale": {
            "type": "integer"
          },
          "disabledCountryCodes": {
            "type": "text",
            "analyzer": "comma_split_pattern_analyzer"
          },
          "discount": {
            "type": "double"
          },
          "displayPrice": {
            "type": "double"
          },
          "exposureSalesRate": {
            "type": "double",
            "index": false
          },
          "exposureSalesVolume": {
            "type": "double",
            "index": false
          },
          "extCategories": {
            "type": "nested",
            "properties": {
              "catId": {
                "type": "integer"
              },
              "catName": {
                "type": "text"
              },
              "level": {
                "type": "integer"
              }
            }
          },
          "firstOnSaleTime": {
            "type": "long",
            "fields": {
              "raw": {
                "type": "date",
                "format": "epoch_second"
              }
            }
          },
          "goodsBrand": {
            "type": "keyword",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "whitespace_analyzer"
              }
            },
            "copy_to": [
              "searchWords"
            ],
            "normalizer": "lowercase_normal"
          },
          "goodsBrief": {
            "type": "text"
          },
          "goodsId": {
            "type": "keyword",
            "normalizer": "lowercase_normal"
          },
          "goodsImg": {
            "type": "keyword",
            "index": false
          },
          "goodsModel": {
            "type": "text",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "standard"
              }
            },
            "copy_to": [
              "searchWords"
            ],
            "analyzer": "shingle_analyzer"
          },
          "goodsNumber": {
            "type": "integer"
          },
          "goodsSearchAttr": {
            "type": "text"
          },
          "goodsSn": {
            "type": "keyword",
            "normalizer": "lowercase_normal"
          },
          "goodsTitle": {
            "type": "text",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "whitespace_analyzer"
              }
            },
            "copy_to": [
              "searchWords",
              "seoSearchWords"
            ],
            "analyzer": "shingle_analyzer"
          },
          "grids": {
            "type": "keyword"
          },
          "groupColorGoodsId": {
            "type": "integer"
          },
          "hasModel": {
            "type": "integer"
          },
          "hotOrder": {
            "type": "keyword"
          },
          "imgType": {
            "type": "integer"
          },
          "integral": {
            "type": "integer"
          },
          "is24hShip": {
            "type": "integer"
          },
          "isBf": {
            "type": "integer"
          },
          "isBlacklistApp": {
            "type": "integer"
          },
          "isDeals": {
            "type": "integer"
          },
          "isDistribution": {
            "type": "integer"
          },
          "isFreeShipping": {
            "type": "integer"
          },
          "isLogin": {
            "type": "integer"
          },
          "isNewPromote": {
            "type": "integer"
          },
          "isOnSaleApp": {
            "type": "integer"
          },
          "isOnSaleSites": {
            "type": "integer"
          },
          "isPromote": {
            "type": "integer"
          },
          "isSampleMaking": {
            "type": "integer"
          },
          "labelCode": {
            "type": "keyword",
            "normalizer": "lowercase_normal"
          },
          "labelIds": {
            "type": "integer"
          },
          "lastReview": {
            "type": "text"
          },
          "lastUpdateTime": {
            "type": "long",
            "fields": {
              "raw": {
                "type": "date",
                "format": "epoch_second"
              }
            }
          },
          "marketPrice": {
            "type": "double"
          },
          "newGoodsWeight": {
            "type": "long"
          },
          "onSaleTime": {
            "type": "long"
          },
          "overallRate": {
            "type": "float"
          },
          "passAvgScore": {
            "type": "float"
          },
          "phoneAttrTable": {
            "type": "text"
          },
          "priceType": {
            "type": "integer"
          },
          "promoteEndDate": {
            "type": "integer"
          },
          "promotePrice": {
            "type": "double"
          },
          "promoteStartDate": {
            "type": "integer"
          },
          "pythonId": {
            "type": "integer"
          },
          "ratio": {
            "type": "integer"
          },
          "realSaleNumber": {
            "type": "integer"
          },
          "realTimeNumber": {
            "type": "integer"
          },
          "recommendation": {
            "type": "double"
          },
          "recommendedLevel": {
            "type": "integer"
          },
          "sameAvgRate": {
            "type": "integer"
          },
          "sameReviewCount": {
            "type": "integer"
          },
          "searchWords": {
            "type": "text",
            "analyzer": "shingle_analyzer"
          },
          "seoAttrTitle": {
            "type": "text",
            "copy_to": [
              "seoSearchWords"
            ],
            "analyzer": "shingle_analyzer"
          },
          "seoSearchWords": {
            "type": "text",
            "analyzer": "shingle_analyzer"
          },
          "shelfDownType": {
            "type": "integer"
          },
          "shopPrice": {
            "type": "double"
          },
          "show": {
            "type": "integer"
          },
          "sizeAttr": {
            "type": "text",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "whitespace_analyzer"
              },
              "raw": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              }
            },
			"analyzer": "shingle_analyzer"
          },
          "skuAttrs": {
            "type": "nested",
            "properties": {
              "attrName": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              },
              "attrValue": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              },
              "templateId": {
                "type": "integer"
              }
            },
			"analyzer": "shingle_analyzer"
          },
          "skuId": {
            "type": "integer"
          },
          "sortOrder": {
            "type": "integer"
          },
          "stockFlag": {
            "type": "integer"
          },
          "unsalable": {
            "type": "integer"
          },
          "urlTitle": {
            "type": "text"
          },
          "week1SaleSpu": {
            "type": "integer"
          },
          "week1Sales": {
            "type": "integer"
          },
          "week1SalesVolume": {
            "type": "double"
          },
          "week2SaleSpu": {
            "type": "integer"
          },
          "week2Sales": {
            "type": "integer"
          },
          "week2SalesVolume": {
            "type": "double"
          },
          "whCode": {
            "type": "keyword",
            "normalizer": "lowercase_normal"
          },
          "whiteList": {
            "type": "integer"
          }
        }
      }
    }
}
GET rosegal/_settings
{
    "settings": {
      "index": {
        "search": {
          "slowlog": {
            "threshold": {
              "fetch": {
                "warn": "200ms"
              },
              "query": {
                "warn": "200ms"
              }
            }
          }
        },
        "number_of_shards": "5",
        "provided_name": "rosegal20210305102833",
        "max_result_window": "100000",
        "creation_date": "1614911313521",
        "analysis": {
          "filter": {
            "shingle": {
              "max_shingle_size": "2",
              "min_shingle_size": "2",
              "output_unigrams": "true",
              "type": "shingle",
              "filler_token": ""
            },
            "synonym": {
              "expand": "false",
              "interval": "3600",
              "type": "dynamic_synonym",
              "synonyms_path": "http://10.4.4.83:8082/api/rosegal/biz/synonym/en"
            },
            "stop_world": {
              "type": "stop",
              "stopwords": [
                "a",
                "and",
                "for",
                "in",
                "of",
                "on",
                "to",
                "with",
                "at",
                "but",
                "by",
                "if",
                "into",
                "is"
              ]
            },
            "custom_stems": {
              "type": "stemmer_override",
              "rules": [
                "legging => legging",
                "leggings => legging"
              ]
            },
            "word_delimiter": {
              "split_on_numerics": "false",
              "split_on_case_change": "false",
              "generate_word_parts": "false",
              "type": "word_delimiter"
            }
          },
          "char_filter": {
            "special_char_replace_filter": {
              "pattern": "_",
              "type": "pattern_replace",
              "replacement": " "
            },
            "whitespace_replace_filter": {
              "pattern": " ",
              "type": "pattern_replace",
              "replacement": ""
            }
          },
          "normalizer": {
            "lowercase_normal": {
              "filter": [
                "lowercase"
              ],
              "type": "custom"
            }
          },
          "analyzer": {
            "whitespace_analyzer": {
              "filter": [
                "lowercase"
              ],
              "type": "custom",
              "tokenizer": "whitespace"
            },
            "default": {
              "filter": [
                "standard",
                "lowercase",
                "word_delimiter",
                "stop_world",
                "porter_stem",
                "synonym",
                "trim",
                "custom_stems"
              ],
              "char_filter": [
                "special_char_replace_filter"
              ],
              "tokenizer": "standard"
            },
            "keyword_analyzer": {
              "filter": [
                "lowercase"
              ],
              "type": "custom",
              "tokenizer": "keyword"
            },
            "shingle_analyzer": {
              "filter": [
                "standard",
                "lowercase",
                "word_delimiter",
                "stop_world",
                "porter_stem",
                "synonym",
                "shingle",
                "trim",
                "custom_stems"
              ],
              "char_filter": [
                "special_char_replace_filter"
              ],
              "type": "custom",
              "tokenizer": "standard"
            },
            "comma_split_pattern_analyzer": {
              "pattern": ",",
              "type": "pattern"
            }
          }
        },
        "number_of_replicas": "1",
        "uuid": "cps95KqoS_2nZzrTC1iGUg",
        "version": {
          "created": "5060499"
        }
      }
    }
}

步骤2:新建索引

PUT rosegal_new
{
    "settings": {
      "index": {
        "search": {
          "slowlog": {
            "threshold": {
              "fetch": {
                "warn": "200ms"
              },
              "query": {
                "warn": "200ms"
              }
            }
          }
        },
        "number_of_shards": "5",
        "max_result_window": "100000",
        "analysis": {
          "filter": {
            "shingle": {
              "max_shingle_size": "2",
              "min_shingle_size": "2",
              "output_unigrams": "true",
              "type": "shingle",
              "filler_token": ""
            },
            "synonym": {
              "expand": "false",
              "interval": "3600",
              "type": "dynamic_synonym",
              "synonyms_path": "http://10.4.4.83:8082/api/rosegal/biz/synonym/en"
            },
            "stop_world": {
              "type": "stop",
              "stopwords": [
                "a",
                "and",
                "for",
                "in",
                "of",
                "on",
                "to",
                "with",
                "at",
                "but",
                "by",
                "if",
                "into",
                "is"
              ]
            },
            "custom_stems": {
              "type": "stemmer_override",
              "rules": [
                "legging => legging",
                "leggings => legging"
              ]
            },
            "word_delimiter": {
              "split_on_numerics": "false",
              "split_on_case_change": "false",
              "generate_word_parts": "false",
              "type": "word_delimiter"
            }
          },
          "char_filter": {
            "special_char_replace_filter": {
              "pattern": "_",
              "type": "pattern_replace",
              "replacement": " "
            },
            "whitespace_replace_filter": {
              "pattern": " ",
              "type": "pattern_replace",
              "replacement": ""
            }
          },
          "normalizer": {
            "lowercase_normal": {
              "filter": [
                "lowercase"
              ],
              "type": "custom"
            }
          },
          "analyzer": {
            "whitespace_analyzer": {
              "filter": [
                "lowercase"
              ],
              "type": "custom",
              "tokenizer": "whitespace"
            },
            "default": {
              "filter": [
                "standard",
                "lowercase",
                "word_delimiter",
                "stop_world",
                "porter_stem",
                "synonym",
                "trim",
                "custom_stems"
              ],
              "char_filter": [
                "special_char_replace_filter"
              ],
              "tokenizer": "standard"
            },
            "keyword_analyzer": {
              "filter": [
                "lowercase"
              ],
              "type": "custom",
              "tokenizer": "keyword"
            },
            "shingle_analyzer": {
              "filter": [
                "standard",
                "lowercase",
                "word_delimiter",
                "stop_world",
                "porter_stem",
                "synonym",
                "shingle",
                "trim",
                "custom_stems"
              ],
              "char_filter": [
                "special_char_replace_filter"
              ],
              "type": "custom",
              "tokenizer": "standard"
            },
            "comma_split_pattern_analyzer": {
              "pattern": ",",
              "type": "pattern"
            }
          }
        },
        "number_of_replicas": "1"
      }
    },
    "mappings": {
      "sku": {
        "dynamic": "false",
        "_all": {
          "enabled": false
        },
        "properties": {
          "addTime": {
            "type": "long",
            "fields": {
              "raw": {
                "type": "date",
                "format": "epoch_second"
              }
            }
          },
          "appPrice": {
            "type": "double"
          },
          "attentionNum": {
            "type": "integer"
          },
          "availableStock": {
            "type": "integer"
          },
          "baseField": {
            "type": "nested",
            "properties": {
              "itemNo": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              },
              "name": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              },
              "value": {
                "type": "keyword",
                "copy_to": [
                  "searchWords"
                ]
              }
            }
          },
          "baseScore1": {
            "type": "double"
          },
          "baseScore2": {
            "type": "double"
          },
          "baseScore3": {
            "type": "double"
          },
          "baseScore4": {
            "type": "double"
          },
          "baseScore5": {
            "type": "double"
          },
          "catId": {
            "type": "integer"
          },
          "categories": {
            "type": "nested",
            "properties": {
              "catId": {
                "type": "integer"
              },
              "catName": {
                "type": "text"
              },
              "level": {
                "type": "integer"
              }
            }
          },
          "clickCount": {
            "type": "integer"
          },
          "colorAttr": {
            "type": "text",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "whitespace_analyzer"
              },
              "raw": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              }
            },
            "copy_to": [
              "searchWords"
            ],
			"analyzer": "shingle_analyzer"
          },
          "cxj": {
            "type": "float"
          },
          "day3Sale": {
            "type": "integer"
          },
          "disabledCountryCodes": {
            "type": "text",
            "analyzer": "comma_split_pattern_analyzer"
          },
          "discount": {
            "type": "double"
          },
          "displayPrice": {
            "type": "double"
          },
          "exposureSalesRate": {
            "type": "double",
            "index": false
          },
          "exposureSalesVolume": {
            "type": "double",
            "index": false
          },
          "extCategories": {
            "type": "nested",
            "properties": {
              "catId": {
                "type": "integer"
              },
              "catName": {
                "type": "text"
              },
              "level": {
                "type": "integer"
              }
            }
          },
          "firstOnSaleTime": {
            "type": "long",
            "fields": {
              "raw": {
                "type": "date",
                "format": "epoch_second"
              }
            }
          },
          "goodsBrand": {
            "type": "keyword",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "whitespace_analyzer"
              }
            },
            "copy_to": [
              "searchWords"
            ],
            "normalizer": "lowercase_normal"
          },
          "goodsBrief": {
            "type": "text"
          },
          "goodsId": {
            "type": "keyword",
            "normalizer": "lowercase_normal"
          },
          "goodsImg": {
            "type": "keyword",
            "index": false
          },
          "goodsModel": {
            "type": "text",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "standard"
              }
            },
            "copy_to": [
              "searchWords"
            ],
            "analyzer": "shingle_analyzer"
          },
          "goodsNumber": {
            "type": "integer"
          },
          "goodsSearchAttr": {
            "type": "text"
          },
          "goodsSn": {
            "type": "keyword",
            "normalizer": "lowercase_normal"
          },
          "goodsTitle": {
            "type": "text",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "whitespace_analyzer"
              }
            },
            "copy_to": [
              "searchWords",
              "seoSearchWords"
            ],
            "analyzer": "shingle_analyzer"
          },
          "grids": {
            "type": "keyword"
          },
          "groupColorGoodsId": {
            "type": "integer"
          },
          "hasModel": {
            "type": "integer"
          },
          "hotOrder": {
            "type": "keyword"
          },
          "imgType": {
            "type": "integer"
          },
          "integral": {
            "type": "integer"
          },
          "is24hShip": {
            "type": "integer"
          },
          "isBf": {
            "type": "integer"
          },
          "isBlacklistApp": {
            "type": "integer"
          },
          "isDeals": {
            "type": "integer"
          },
          "isDistribution": {
            "type": "integer"
          },
          "isFreeShipping": {
            "type": "integer"
          },
          "isLogin": {
            "type": "integer"
          },
          "isNewPromote": {
            "type": "integer"
          },
          "isOnSaleApp": {
            "type": "integer"
          },
          "isOnSaleSites": {
            "type": "integer"
          },
          "isPromote": {
            "type": "integer"
          },
          "isSampleMaking": {
            "type": "integer"
          },
          "labelCode": {
            "type": "keyword",
            "normalizer": "lowercase_normal"
          },
          "labelIds": {
            "type": "integer"
          },
          "lastReview": {
            "type": "text"
          },
          "lastUpdateTime": {
            "type": "long",
            "fields": {
              "raw": {
                "type": "date",
                "format": "epoch_second"
              }
            }
          },
          "marketPrice": {
            "type": "double"
          },
          "newGoodsWeight": {
            "type": "long"
          },
          "onSaleTime": {
            "type": "long"
          },
          "overallRate": {
            "type": "float"
          },
          "passAvgScore": {
            "type": "float"
          },
          "phoneAttrTable": {
            "type": "text"
          },
          "priceType": {
            "type": "integer"
          },
          "promoteEndDate": {
            "type": "integer"
          },
          "promotePrice": {
            "type": "double"
          },
          "promoteStartDate": {
            "type": "integer"
          },
          "pythonId": {
            "type": "integer"
          },
          "ratio": {
            "type": "integer"
          },
          "realSaleNumber": {
            "type": "integer"
          },
          "realTimeNumber": {
            "type": "integer"
          },
          "recommendation": {
            "type": "double"
          },
          "recommendedLevel": {
            "type": "integer"
          },
          "sameAvgRate": {
            "type": "integer"
          },
          "sameReviewCount": {
            "type": "integer"
          },
          "searchWords": {
            "type": "text",
            "analyzer": "shingle_analyzer"
          },
          "seoAttrTitle": {
            "type": "text",
            "copy_to": [
              "seoSearchWords"
            ],
            "analyzer": "shingle_analyzer"
          },
          "seoSearchWords": {
            "type": "text",
            "analyzer": "shingle_analyzer"
          },
          "shelfDownType": {
            "type": "integer"
          },
          "shopPrice": {
            "type": "double"
          },
          "show": {
            "type": "integer"
          },
          "sizeAttr": {
            "type": "text",
            "fields": {
              "correctionRaw": {
                "type": "text",
                "analyzer": "whitespace_analyzer"
              },
              "raw": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              }
            },
			"analyzer": "shingle_analyzer"
          },
          "skuAttrs": {
            "type": "nested",
            "properties": {
              "attrName": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              },
              "attrValue": {
                "type": "keyword",
                "normalizer": "lowercase_normal"
              },
              "templateId": {
                "type": "integer"
              }
            }
          },
          "skuId": {
            "type": "integer"
          },
          "sortOrder": {
            "type": "integer"
          },
          "stockFlag": {
            "type": "integer"
          },
          "unsalable": {
            "type": "integer"
          },
          "urlTitle": {
            "type": "text"
          },
          "week1SaleSpu": {
            "type": "integer"
          },
          "week1Sales": {
            "type": "integer"
          },
          "week1SalesVolume": {
            "type": "double"
          },
          "week2SaleSpu": {
            "type": "integer"
          },
          "week2Sales": {
            "type": "integer"
          },
          "week2SalesVolume": {
            "type": "double"
          },
          "whCode": {
            "type": "keyword",
            "normalizer": "lowercase_normal"
          },
          "whiteList": {
            "type": "integer"
          }
        }
      }
    }
}

步骤3:同步数据

POST _reindex                   
{
  "source": {
    "index": "rosegal"
  },
  "dest": {
    "index": "rosegal_new"
  }
}

步骤4:删除原索引(注意必须等数据同步完后才能删除)

DELETE rosegal

步骤5:设置别名

POST /_aliases
{
    "actions": [
        {"add": {"index": "rosegal_new", "alias": "rosegal"}}
    ]
}

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐