# Update Documents with new Field

**URL:** <https://discuss.elastic.co/t/update-documents-with-new-field/260906>\
**Category:** Elasticsearch\
**Created:** [January 12, 2021, 9:00pm UTC](https://discuss.elastic.co/t/update-documents-with-new-field/260906 "2021-01-12T21:00:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevezemlicka](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stevezemlicka](https://discuss.elastic.co/u/stevezemlicka)\
**Post date:** [January 12, 2021, 9:00pm UTC](https://discuss.elastic.co/t/update-documents-with-new-field/260906/1 "2021-01-12T21:00:53Z")

</div>

I have a set of data wherein generic identifiers exist. This is partially due to another index which also uses these generic identifiers and our use of Timelion to display dashboards with a combination of data from both indexes. I noticed the controls visualization in kibana and would like to use that to easily select based on these identifiers but would like a friendly name rather than the number/id.

While I could just manipulate the source data and re-ingest, I'm trying to learn Elasticsearch and would like to figure out how to do this for when I run into situations where re-ingesting isn't possible.

I was looking at the update by query documentation. It looks like you can use an ingest pipeline to create and assign a value to field. So does this mean I can do something like the following to update all documents in "my-index-000001" with the ID field having a value of "15" with a new field called "Name" and a value of "FirendlyID"?

```auto
PUT _ingest/pipeline/set-name
{
  "description" : "sets name",
  "processors" : [ {
      "set" : {
        "field": "Name",
        "value": "FriendlyID"
      }
  } ]
}
POST my-index-000001/_update_by_query?pipeline=set-name
{
  "query": { 
    "term": {
      "ID": "15"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [January 12, 2021, 9:21pm UTC](https://discuss.elastic.co/t/update-documents-with-new-field/260906/2 "2021-01-12T21:21:04Z")

</div>

Yes this is a good option  
An other option is to use a painless script to update docs

> **[Update By Query API | Elasticsearch Reference \[7.10\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html#docs-update-by-query-api-source)**

---

<div class="post-metadata">

**Author:** ![stevezemlicka](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@stevezemlicka](https://discuss.elastic.co/u/stevezemlicka)\
**Post date:** [January 12, 2021, 9:40pm UTC](https://discuss.elastic.co/t/update-documents-with-new-field/260906/3 "2021-01-12T21:40:22Z")

</div>

Thank you. Did some more digging into the script option which I didn't really understand until I did so. Would that look something like:

```auto
POST my-index-000001/_update_by_query
{
  "script": {
    "source": "ctx._source.Name = 'FriendlyID'",
    "lang": "painless"
  },
  "query": {
    "term": {
      "ID": "15"
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 9, 2021, 9:40pm UTC](https://discuss.elastic.co/t/update-documents-with-new-field/260906/4 "2021-02-09T21:40:51Z")

</div>

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