Truncate part of an existing url field value to a new field using painless?

For existing documents, you'll want to look at update by query