首先,我们先看文档

es--映射修改和数据迁移

 

 

 文档中百度翻译了一下,大意是:,

除了支持的映射参数外,不能更改现有字段的映射或字段类型。更改现有字段可能会使已编制索引的数据无效。

如果需要更改字段的映射,请使用正确的映射创建一个新索引,并将数据重新索引到该索引中。

重命名字段将使已在旧字段名下编制索引的数据无效。而是添加一个别名字段来创建备用字段名。

 

在es中,是不支持更改现有字段的映射或字段类型的,如果我们非得需要更改字段的类型,怎么办,数据迁移,重建索引,建立我们想要的正确的映射规则;

 

1,查看旧的索引

GET /customer/_mapping
{
  "customer" : {
    "mappings" : {
      "properties" : {
        "addr" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "age" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          },
          "fielddata" : true
        },
        "content" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "interests" : {
          "type" : "text",
          "fielddata" : true
        },
        "name" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "properties" : {
          "properties" : {
            "content" : {
              "properties" : {
                "analyzer" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "search_analyzer" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "type" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            }
          }
        },
        "sex" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    }
  }
}
View Code

相关文章:

  • 2022-03-04
  • 2021-07-24
  • 2021-09-13
  • 2022-02-25
  • 2022-12-23
  • 2021-10-19
  • 2021-10-29
  • 2021-10-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-16
  • 2021-08-27
  • 2021-12-26
  • 2021-09-17
相关资源
相似解决方案