Is there any best way to update existing index without re-indexing and creating alias of index?

I've to re-index the data if there is little change in the existing index.

I've already done reindexing with creating an alias of the index but in that , I've to wait while reindexing the data from one index to another. The index size is about 30 GB. it takes too long to re-index the existing data.

Is there any efficient way of doing it?

Hi @Devang_Prajapati,

For little changes in Index or index settings you can use update API where you can update index settings ( No of replicas, refresh interval etc.) . Also, you can update documents and add field using update API in Elasticsearch.

For more understanding about API like how to update settings and add fields please refer below link.

Regards,
Harsh Bajaj

2 Likes

I would say it depends on what kind of changes you want to make. Adding mapping or changing document structure can sometimes be done in place but changing mappings for existing fields often require reindexing.

Changing in existing field's type( mapping ).

@harshbajaj16
can you pls give an update API reference link.

Yes, @Devang_Prajapati,

I have shared the same. please look into this.

Regards,
Harsh Bajaj

@harshbajaj16 it is for updating documents. i don't want to update the documents. I want to update existing field's mapping.

For ex. current mapping

{
  "mappings": {
    "properties": {
      "field1": {
        "type": "text",
      }
    }
  }

new mapping

{
  "mappings": {
    "properties": {
      "field1": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
  }

To apply this i've to re-index all document to another index first which is created with new mappings. Then delete the old index and create alias of newly created index with the name of old index which is deleted.

There is no way around that approach as far as I know.

1 Like

Hi @Christian_Dahlqvist,

Sorry for this, but I think it is possible in Elasticsearch with put mapping api. it is mentioned the same in documentation that we can add and update fields in existing Elasticsearch indices.

As example given by @Devang_Prajapati he is trying to add new fields in existing index and it is possible to do the same with `PUT mapping API.

Please find below related link for the same to add and update the mapping in existing API.

sorry @Devang_Prajapati as I gave you update API link as you asked in below query.

Please correct me if I misunderstood you guys.

Regards,
Harsh Bajaj

@harshbajaj16

With the PUT mapping API you can create index. But once the index is created you can not be able to change or update existing field of that index without reindexing and creating alias.

For more. https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html#updating-field-mappings

@harshbajaj16 As I said in my first response you can generally add new mappings to an index but not alter existing ones without reindexing.

1 Like

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