Command to change fieldtype of an index

I am trying changing the fieldtype using of a field from string to integer and not able to find out to correct syntax.
preferably using _mapping API
Please help

Thanks in advance

Hi @pathri

Once you a field has a fieldtype you can't change this.

If you don't have data in the index, try this:

  1. Get the mapping using

GET <my_index>/_mapping

and copy the JSON to a safe place

  1. delete the index, see:

(I gave a link to avoid accidental deletion)

  1. Create the index using this API

you can modify the mapping you saved and use that in the create request.

Alternatively, if you already have data, you will need to create a new index, following steps 1 and 3

and then use the _reindex API, see

to transfer your data to the new index.

Hope this helps!

  • Dom

thanks for your help Dom :slight_smile:

But this is a big process and also the time consuming one.
and we are aware that the reindex takes long time and if the data in the index will be in TBs then it is going to take much longer time :frowning_face:

no other way to handle this scenario, like using _ingest API ??

Hi @pathri

The _ingest api will allow you to add a pipeline which can change the type of incoming data

What it won't do is allow you to change the already-existing fieldtype on the already existing field or fields. That's because existing indexes will already have data structures in place to store the original fieldtype.

You could also add (the same) pipeline to a reindex request

I understand your concern about the cost in time of a reindex. It will also require space. You might consider adding a query to a reindex to break it down into smaller operations

alright :smiley:
thanks for clearing all doubts,
just 1 question left which is : i was going through ingest API documentation and saw that i can run the created pipeline on a particular document but is it possible to run it on a complete index in 1 go.

Simple example:
i have created a pipeline to delete the "message" field from apache log, i am able to do it for a particular document but wanted to do for all documents, what should be the query for that?

Thanks in advance

Hi @pathri

If you are deleting a field from an existing document or documents you can do this in-place in the same index using the "Update by Query" API, see

If you don't specify a query to scope the operation, this will act on ALL the documents in the index.

You can specify a pipeline on the command line, for example:

`POST twitter/_update_by_query?pipeline=set-foo``

and this will run the pipeline on all the documents in the index

cool :slight_smile:

this query is working but getting time out
"statusCode": 504,
"error": "Gateway Time-out",
"message": "Client request timeout"

this index is having 924851 documents in it and documents are nothing but apache log.

Hi @pathri is this relating to an update_by_query?

Hi @pathri please can you raise this as a new Topic as I'll be out of touch in the short term


Hi @Dominic_Page: yes it was for the update query only

POST twitter/_update_by_query?pipeline=delete-message

sorry for the delayed response got stuck with something

Hi @pathri

you might want to take a look at this thread

where the user had the same issue while using the same API

Hope this helps!

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