Adding a new field to two billion documents

After migrating nearly 2billion documents I noticed I DERPED and forgot to set a field we call "mongo_id" on 90% of them.

Is there a way to update all of the documents so that

document.mongo_id = document.meta.id

Any update will require reindexing.

That is fine I suppose, do you happen to have an example query on how a field can be set to the value of a documents id?

POST indexname/doctype/_update_by_query
{
  "script": {
    "source": "ctx._source.id = ctx._id",
    "lang": "painless"
  },
  "query":{
    "bool":{
        "must_not":{
          "exists":{
          "field":"mongo_id"
          }
        }
    }
  }
}
1 Like

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