更改映射字段类型 elasticsearch 1.7

Changing mapping field type elasticsearch 1.7

我必须将映射中的价格字段类型从字符串更改为浮点数。 当我尝试这个时

curl -XPUT http://52.73.2.239:9200/products/_mapping/product -d '{ "properties":{ "productOnly.price":{ "type" : "float" } } }' 但没有任何改变。 这是我的数据映射

"properties" : { //I some props and other objects. productOnly is nested object "productOnly" : { "properties" : { "bonus" : { "type" : "string" }, "price" : { "type" : "string" } } } }

创建映射后,您 cannot change it(您可以,但仅适用于前面 link 中解释的非常特殊的情况)。

所以你要做的就是删除你的索引...

curl -XDELETE http://52.73.2.239:9200/products

...并使用适当的映射重新创建它:

curl -XPUT http://52.73.2.239:9200/products -d '{
  "mappings": {
    "product": {
      "properties": {
        ... other properties...
        "productOnly": {
          "properties": {
            "bonus": {
              "type": "string"
            },
            "price": {
              "type": "float"         <--- chance the type here
            }
          }
        }
      }
    }
  }
}'

然后您可以用一些数据重新填充您的索引。