2016-03-04 125 views
0

我必須更改從字符串到浮點映射中的價格字段類型。 當我想這更改映射字段類型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

回答

1

一旦映射被創建,映射你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!非常感謝! –