Skip to content

ElasticSearch 索引增加字段

官方文档:Controlling Analysis

json
PUT /my_index/_mapping/my_type
{
    "my_type": {
        "properties": {
            "english_title": {
                "type":     "string",
                "analyzer": "english"
            }
        }
    }
}

列新增了以后就无法再修改其属性,否则回返回 400 错误。

js
{"error":
    {"root_cause":
        [{
            "type":"merge_mapping_exception",
            "reason":"Merge failed with failures 
                {[
                    mapper [prefix] has different [index] values, 
                    mapper [prefix] has different [omit_norms] values, cannot change from disable to enabled, 
                    mapper [prefix] has different [analyzer]
                ]}"
        }],
    "type":"merge_mapping_exception",
    "reason":"Merge failed with failures 
        {[
            mapper [prefix] has different [index] values, 
            mapper [prefix] has different [omit_norms] values, cannot change from disable to enabled, 
            mapper [prefix] has different [analyzer]
        ]}"
    },
"status":400
}

附上使用 curl 增加字段的命令:

bash
curl -XPUT 127.0.0.1:9200/my_index/_mapping/my_type -d @my_index_info.json