Elastic search redefining mapping of an index

I have an index called sql_session on Elasticsearch and this index has some floating point data which is wrongly indexed as a long data type. I want to correct this, is it possible to do so with a command similar to the following command on the Kibana console or should I delete and recreate the entire index/index pattern?

PUT sql_session/_mapping/doc
{
  "properties": {
    "name": {
      "properties": {
        "price": { 
          "type": "float"
        }
      }
    },
  } 
}

The return of GET sql_session/_mapping/doc is as follows:

{
  "sql_session": {
    "mappings": {
      "doc": {
        "properties": {
          "@timestamp": {
            "type": "date"
          },
          "@version": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "description": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "duration": {
            "type": "long"
          },
          "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "price": {
            "type": "long"
          },
          "processid": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "sessionid": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "starteruserid": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "statusid": {
            "type": "long"
          },
          "tags": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "username": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

Hey Ongun,

If you want to change the mapping of a field in an existing index you'll have to use the reindex API: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html. This blog post explains the process better than I can: https://www.elastic.co/blog/changing-mapping-with-zero-downtime

If you don't care about the data then updating the template and then deleting the index will work, the new index will be created with the correct mapping.

Cheers,
Mike

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.