Adding a new field to two billion documents


(kurtis) #1

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


(Christian Dahlqvist) #2

Any update will require reindexing.


(kurtis) #3

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?


(kurtis) #4
POST indexname/doctype/_update_by_query
{
  "script": {
    "source": "ctx._source.id = ctx._id",
    "lang": "painless"
  },
  "query":{
    "bool":{
        "must_not":{
          "exists":{
          "field":"mongo_id"
          }
        }
    }
  }
}

(system) #5

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