Frequently Asked Question

How to change the field type of existing index
Last Updated 3 years ago

The field types in index have to be set during creation. Or the field types will be dynamically set by the index templates. However for certain reason if you plan to change the field type after it is created, it can be done only by reindexing. Create a different index with the required field types and reindex the same.

Note that by default the field types are set to text with sub field.keyword set to keyword. For example if you need to set IP address and dates, we need to ensure it is set properly. Also geopoint is a special field type that will be required to identify points on a map.

Example of setting an index with specific field types from linux command prompt

 curl -H 'Content-Type: application/json'  -XPUT localhost:9200/newfb?pretty -d '
{
  "mappings": {  
     "properties": { 
        "clientip" : {"type" :"ip" },
        "geoip": {"properties" :{"location" :{"type":"geo_point"}}}
     }
  }
}' 
Reindex from Devtools
PUT /newindex 
{
  "mappings": {  
    "properties": { 
       "clientip" : {"type" :"ip" },
       "geoip": {"properties" :{"location" :{"type":"geo_point"}}}
    }
  }
}'

Reindex from sourceindex to newindex
POST _reindex
{
  "source": {"index": "sourceindexname"},
  "dest": {"index": "newindexname"}
}

Multiple indexes can also be copied to new index as follows
POST _reindex
{
 "source": {"index": "sourceindexname*"},
 "dest": {"index": "newindexname"}
} 

Monitor the reindex status 
GET _tasks?detailed=true&actions=*reindex

Output will be similar to the following 
{
  "nodes" : {
     "Ct93nmCaTPWlZIDNHB8sAg" : {
       "name" : "es01",
       "transport_address" : "172.22.0.3:9300",
       "host" : "172.22.0.3",
       "ip" : "172.22.0.3:9300",
       "roles" : [
         "data",
         "ingest",
         "master",
         "ml",
         "remote_cluster_client",
         "transform"
       ],
       "attributes" : {
         "ml.machine_memory" : "7937060864",
         "xpack.installed" : "true",
         "transform.node" : "true",
         "ml.max_open_jobs" : "20"
       },
       "tasks" : {
         "Ct93nmCaTPWlZIDNHB8sAg:10257507" : {
           "node" : "Ct93nmCaTPWlZIDNHB8sAg",
           "id" : 10257507,
           "type" : "transport",
           "action" : "indices:data/write/reindex",
           "status" : {
             "total" : 78285,
             "updated" : 0,
             "created" : 46000,
             "deleted" : 0,
             "batches" : 46,
             "version_conflicts" : 0,
             "noops" : 0,
             "retries" : {
               "bulk" : 0,
               "search" : 0
             },
             "throttled_millis" : 0,
             "requests_per_second" : -1.0,
             "throttled_until_millis" : 0
           },
           "description" : "reindex from [winlogbeat*] to [logstash1-2020.10][_doc]",
           "start_time_in_millis" : 1602387327488,
           "running_time_in_nanos" : 23845740752,
           "cancellable" : true,
           "headers" : { }
        }
      }
    }
  }
}

Output will be blank like below once completed 
{
   "nodes" : { }
} 

Loading ...