# Reindex with field value converted to uppercase

**URL:** <https://discuss.elastic.co/t/reindex-with-field-value-converted-to-uppercase/108937>\
**Category:** Elasticsearch\
**Created:** [November 23, 2017, 7:30pm UTC](https://discuss.elastic.co/t/reindex-with-field-value-converted-to-uppercase/108937 "2017-11-23T19:30:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abhisheksimion](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abhisheksimion/32/24623_2.png) [@abhisheksimion](https://discuss.elastic.co/u/abhisheksimion)\
**Post date:** [November 23, 2017, 7:30pm UTC](https://discuss.elastic.co/t/reindex-with-field-value-converted-to-uppercase/108937/1 "2017-11-23T19:30:05Z")

</div>

I am trying to migrate from ES 1.4 to ES 5.5. In one of the index I need to change the **name of field** and also convert it's **value to uppercase**. I am able to reindex with change in name of field and remove the unwanted field but need help in converting the value to uppercase.

This is what I tried

```
POST _reindex?wait_for_completion=false
{
  "source": {
	"remote": {
	  "host": "http://source_ip:17002"
	},
	"index": "log_event_2017-09-11",
	"size": 1000,
	"query": {
	  "match_all": {}
	}
  },
  "dest": {
	"index": "logs-ics-2017-09-11"
  },
  "script": {
	"inline": "ctx._source.product = ctx._source.remove(\"product_name\")",
	"lang": "painless"
  }
}

```

The above POST request is able to remove "product\_name" and create "product" with it's value. So in order to uppercase "product" value I tried below inline script but it gives a null\_pointer\_exception. Please help

```
"ctx._source.product = ctx._source.remove(\"product_name\");ctx._source.product = doc[\"product\"].toUpperCase()"
```

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 24, 2017, 12:53am UTC](https://discuss.elastic.co/t/reindex-with-field-value-converted-to-uppercase/108937/2 "2017-11-24T00:53:18Z")

</div>

You should not use the `doc[\"product\"]` syntax when reindexing. That syntax is for accessing fields when using scripts in search queries and aggregations. Instead, use the `ctx._source.product` syntax:

`ctx._source.product = ctx._source.remove(\"product_name\");ctx._source.product = ctx._source.product.toUpperCase()`

You may still run into issues, because you may have documents that do not contain the `product_name` field. Then you will get an error again. A better script would be:

`if (ctx._source.product_name != null) { ctx._source.product = ctx._source.remove(\"product_name\");ctx._source.product = ctx._source.product.toUpperCase()}`

---

<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:** [December 22, 2017, 12:53am UTC](https://discuss.elastic.co/t/reindex-with-field-value-converted-to-uppercase/108937/3 "2017-12-22T00:53:23Z")

</div>

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