Search code examples
elasticsearchelasticsearch-plugin

Changing mapping field type elasticsearch 1.7


I have to change type of price field in mapping from string to float. when i am trying this

curl -XPUT http://52.73.2.239:9200/products/_mapping/product -d '{ "properties":{ "productOnly.price":{ "type" : "float" } } }' but nothing changes. here is mapping of my data

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


Solution

  • Once a mapping has been created, you cannot change it (you can but only for very special cases explained in the previous link).

    So what you have to do is to delete your index...

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

    ... and recreate it with the proper mapping:

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

    Then you can re-populate your index with some data.