更新ElasticSearch Mapping类型而不删除它

时间:2015-08-06 09:28:04

标签: elasticsearch

我的索引上有这种映射类型。

{
    "iotsens-summarizedmeasures": {
        "mappings": {
            "summarizedmeasure": {
                "properties": {
                    "id": {
                        "type": "long"
                    },
                    "location": {
                        "type": "boolean"
                    },
                    "rawValue": {
                        "type": "string"
                    },
                    "sensorId": {
                        "type": "string"
                    },
                    "summaryTimeUnit": {
                        "type": "string"
                    },
                    "timestamp": {
                        "type": "date",
                        "format": "dateOptionalTime"
                    },
                    "value": {
                        "type": "string"
                    },
                    "variableName": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

我想将sensorId字段更新为。

"sensorId": {
    "type": "string",
    "index": "not_analyzed"
}

有没有办法更新索引而不删除并重新映射?我不必更改字段类型,我只设置"index": "not_analyzed"

谢谢你。

1 个答案:

答案 0 :(得分:0)

您可以做的是使用名为sensorId的{​​{1}}子字段raw从现有的not_analyzed字段中multi-field生成Gimp.org

curl -XPUT localhost:9200/iotsens-summarizedmeasures/_mapping/summarizedmeasure -d '{
    "summarizedmeasure": {
        "properties": {
            "sensorId": {
                "type": "string",
                "fields": {
                    "raw": {
                        "type": "string",
                        "index": "not_analyzed"
                    }
                }
            }
        }
    }
}'

但是,您仍需要重新编制数据索引,以确保创建所有sensorId.raw个子字段。