# How to add fields with special characters using painless scripting(Java ES SDK)

**URL:** <https://discuss.elastic.co/t/how-to-add-fields-with-special-characters-using-painless-scripting-java-es-sdk/284888>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [September 22, 2021, 2:39pm UTC](https://discuss.elastic.co/t/how-to-add-fields-with-special-characters-using-painless-scripting-java-es-sdk/284888 "2021-09-22T14:39:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rahul\_Balaji](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rahul_balaji/32/94931_2.png) [@Rahul\_Balaji](https://discuss.elastic.co/u/Rahul_Balaji)\
**Post date:** [September 22, 2021, 2:39pm UTC](https://discuss.elastic.co/t/how-to-add-fields-with-special-characters-using-painless-scripting-java-es-sdk/284888/1 "2021-09-22T14:39:06Z")

</div>

Hi All,

I am using ES Java SDK for my insert/update operation. I am using "update by query" with painless scripting. Everything works well but I am facing issues while indexing data with special characters. Please find below what I am trying to achieve.

String bundlescript = "ctx.\_source.content.metadata.emfAttributes.3+=params.3+";  
params.3+ is a map(bundleparameters). so basically the map will have value like - {3+=xyz}  
my requirement is to get the data in Es in the below format  
"3+":"xyz"  
But while running I am getting an script\_exception because of the + symbol. Tried escaping and adding single/double quotes but to no use

short code:

```auto
Map<String, Object> bundleParameters;
bundleParameters.put("3+","xyz");
String bundlescript = "ctx._source.content.metadata.emfAttributes.3+=params.3+";
Script script = new Script(ScriptType.INLINE, "painless", bundleScript, bundleParameters); updateByQueryRequest.setQuery(boolQueryBuilder).setScript(script)

```

Any help would be highly appreciated

---

<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:** [October 20, 2021, 2:39pm UTC](https://discuss.elastic.co/t/how-to-add-fields-with-special-characters-using-painless-scripting-java-es-sdk/284888/2 "2021-10-20T14:39:33Z")

</div>

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