# Use the \_update\_by\_query API for a mapping change

**URL:** <https://discuss.elastic.co/t/use-the--update-by-query-api-for-a-mapping-change/88723>\
**Category:** Elasticsearch\
**Created:** [June 8, 2017, 2:13pm UTC](https://discuss.elastic.co/t/use-the--update-by-query-api-for-a-mapping-change/88723 "2017-06-08T14:13:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![xgantan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xgantan/32/14786_2.png) [@xgantan](https://discuss.elastic.co/u/xgantan)\
**Post date:** [June 8, 2017, 2:13pm UTC](https://discuss.elastic.co/t/use-the--update-by-query-api-for-a-mapping-change/88723/1 "2017-06-08T14:13:14Z")

</div>

Hello,

I have the following mappings defined for a field in an index that has hundreds of thousands of documents:

```auto
{
  "status": {
      "type": "text"
  }
}

```

and I want to change its definition to:

```auto
{
  "status": {
      "type": "keyword"
  }
}

```

Is this do-able using the `_update_by_query` API? What will the performance impact be? If I can run it offline, would it be quicker than the reindexing to v2, dropping the original alias, creating an alias, and then removing the v1 index technique described in the zero-downtime post ([https://www.elastic.co/guide/en/elasticsearch/guide/current/index-aliases.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/index-aliases.html))?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [June 8, 2017, 9:22pm UTC](https://discuss.elastic.co/t/use-the--update-by-query-api-for-a-mapping-change/88723/2 "2017-06-08T21:22:39Z")

</div>

> [@xgantan](#):
>
> Is this do-able using the `_update_by_query` API? What will the performance impact be?

You cannot do this with the update by query API. The `_update_by_query` API only allows you to reindex a subset of documents, replacing the existing version of the documents (in the same index). The problem is that in order to make the change you want, you'll have to change the mappings, and since this is not an additive change you can only make it on a new index.

One way to accomplish this would be to create a new index with the different mappings you want, and then to use the `_reindex` API [https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docs-reindex.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docs-reindex.html) to reindex the data into the new index with the correct mapping.

---

<div class="post-metadata">

**Author:** ![xgantan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xgantan/32/14786_2.png) [@xgantan](https://discuss.elastic.co/u/xgantan)\
**Post date:** [June 8, 2017, 9:42pm UTC](https://discuss.elastic.co/t/use-the--update-by-query-api-for-a-mapping-change/88723/3 "2017-06-08T21:42:37Z")

</div>

Yes. I tried it and realized that type change requires reindex. Thanks

---

<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 6, 2017, 9:42pm UTC](https://discuss.elastic.co/t/use-the--update-by-query-api-for-a-mapping-change/88723/4 "2017-07-06T21:42:43Z")

</div>

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