6

Let's say I've an elasticsearch index with around 10M documents on it. Now I need to add a new filed with a default value e.g is_hotel_type=0 for each and every ES document. Later I'll update as per my requirments.

To do that I've modified myindex with a PUT request like below-

PUT myindex
{
  "mappings": {
    "rp": {
      "properties": {
        "is_hotel_type": {
          "type": "integer" 
        }
      }
    }
  }
}

Then run a painless script query with POST to update all the existing documents with the value is_hotel_type=0

POST myindex/_update_by_query
{
  "query": {
    "match_all": {}
  },
  "script" : "ctx._source.is_hotel_type = 0;"
}

But this process is very time consuming for a large index with 10M documents. Usually we can set default values on SQL while creating new columns. So my question- Is there any way in Elasticsearch so I can add a new field with a default value.I've tried below PUT request with null_value but it doesn't work for.

PUT myindex/_mapping/rp
{
  "properties": {
        "is_hotel_type": {
          "type": "integer",
           "null_value" : 0 
        }
      }
}

I just want to know is there any other way to do that without the script query?

1
  • 1
    this is a very good question. Very similar to this question was asked by someone else a week ago .. basically that poster wanted to reindex and run the reindex through the second mappings that has this default field. Very interesting. Here is the link stackoverflow.com/questions/56889629/… Commented Jul 12, 2019 at 12:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.