# Updating index with new field, based on the values of existing fields

**URL:** <https://discuss.elastic.co/t/updating-index-with-new-field-based-on-the-values-of-existing-fields/275144>\
**Category:** Elasticsearch\
**Created:** [June 7, 2021, 12:03pm UTC](https://discuss.elastic.co/t/updating-index-with-new-field-based-on-the-values-of-existing-fields/275144 "2021-06-07T12:03:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saif3r](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@saif3r](https://discuss.elastic.co/u/saif3r)\
**Post date:** [June 7, 2021, 12:03pm UTC](https://discuss.elastic.co/t/updating-index-with-new-field-based-on-the-values-of-existing-fields/275144/1 "2021-06-07T12:03:19Z")

</div>

Hello,

I have an index with two fields: `City_1` and `City_2`. I would like to create a new field and update all existing documents based on the outcome of the following logical test:  
`If City_1 = City_2 Then Match Else No Match`  
So the index would look like this:

| City\_1 | City\_2 | New\_Field |
| --- | --- | --- |
| Paris | Lion | No Match |
| Madrid | Madrid | Match |

Any tips how could we achieve that?

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [June 7, 2021, 11:44pm UTC](https://discuss.elastic.co/t/updating-index-with-new-field-based-on-the-values-of-existing-fields/275144/2 "2021-06-07T23:44:50Z")

</div>

Use [update by query](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html) or [update](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html) APIs  
you have examples in the documentation.

---

<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:** [July 5, 2021, 11:44pm UTC](https://discuss.elastic.co/t/updating-index-with-new-field-based-on-the-values-of-existing-fields/275144/3 "2021-07-05T23:44:56Z")

</div>

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