更改映射字段类型elasticsearch 1.7

问题描述:

我必须更改从字符串到浮点映射中的价格字段类型。 当我想这更改映射字段类型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" } } } }

+0

您[无法这样做](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html#updating-field-mappings),您需要创建另一个带有'float'类型的字段并填充它,或者擦除你的索引,重新创建它并重新填充它。 – Val

+0

但我可以在向我的索引添加数据之前创建映射吗? –

+0

是的,但是一旦你给了你的领域一定的类型,你就不能改变它。您必须删除索引并用新类型重新创建索引。 – Val

一旦映射被创建,映射你cannot change it(你可以,但仅适用于非常特殊的情况在以前的链接解释)。

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

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 
      } 
      } 
     } 
     } 
    } 
    } 
}' 

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

+0

我在邮递员应用 尝试这样做,我得到一个错误 ' “error”:“InvalidIndexNameException [[products -d]索引名无效[products -d]不能包含以下字符[\\,/,*,?,\”,,|,,,]]“, ' –

+0

这是一个curl命令,你不能复制/粘贴邮递员。你需要在邮递员中使用的URL只是'http://52.73.2.239:9200/products',即没有'-d ...' – Val

+0

It works!非常感谢! –