# Elasticsearch JAVA API - Update by script - throws error when field value contains special characters ("&" , " " " , " \>" , etc)

**URL:** <https://discuss.elastic.co/t/elasticsearch-java-api-update-by-script-throws-error-when-field-value-contains-special-characters-etc/18455>\
**Category:** Elasticsearch\
**Created:** [July 3, 2014, 6:39am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-by-script-throws-error-when-field-value-contains-special-characters-etc/18455 "2014-07-03T06:39:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![baskaran\_vaithiyanat](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@baskaran\_vaithiyanat](https://discuss.elastic.co/u/baskaran_vaithiyanat)\
**Post date:** [July 3, 2014, 6:39am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-by-script-throws-error-when-field-value-contains-special-characters-etc/18455/1 "2014-07-03T06:39:19Z")

</div>

Hi ,

When I try to update a field, the field variable (here "body")  
contains special characters ("&" , " " " , " \>" ....) it throws exception.  
_ES version : 1.0.0_

I have mentioned my code snippet and stack-trace below:

Thanks in advance.

_My code snippet:_

String body = GetBody();  
UpdateResponse ur = client.prepareUpdate("help","help",id)  
.setScript("ctx.\_source.body = "+body)  
.execute().actionGet();

_Stacktrace :_

at  
org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:153)  
at  
org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:80)  
at  
org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:189)  
at  
org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:185)  
at  
org.elasticsearch.action.update.TransportUpdateAction.shardOperation(TransportUpdateAction.java:64)  
at  
org.elasticsearch.action.support.single.instance.TransportInstanceSingleOperationAction$AsyncSingleAction$1.run(TransportInstanceSingleOperationAction.java:192)  
at  
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
at java.lang.Thread.run(Thread.java:744)  
Caused by: [Error: unexpected token: known\_Y]  
[Near : {... CalcQuickBase["known\_Y"] \> ....}]

[Line: 25, Column: 23]  
at  
org.elasticsearch.common.mvel2.compiler.ExpressionCompiler.\_compile(ExpressionCompiler.java:255)  
at  
org.elasticsearch.common.mvel2.util.ParseTools.subCompileExpression(ParseTools.java:2115)  
at  
org.elasticsearch.common.mvel2.ast.DeepAssignmentNode.(DeepAssignmentNode.java:70)  
at  
org.elasticsearch.common.mvel2.ast.DeepAssignmentNode.(DeepAssignmentNode.java:83)  
at  
org.elasticsearch.common.mvel2.compiler.AbstractParser.nextToken(AbstractParser.java:785)  
at  
org.elasticsearch.common.mvel2.compiler.ExpressionCompiler.\_compile(ExpressionCompiler.java:128)  
at  
org.elasticsearch.common.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:62)  
at org.elasticsearch.common.mvel2.MVEL.compileExpression(MVEL.java:810)  
at  
org.elasticsearch.script.mvel.MvelScriptEngineService.compile(MvelScriptEngineService.java:84)  
at org.elasticsearch.script.ScriptService.compile(ScriptService.java:145)  
at org.elasticsearch.script.ScriptService.executable(ScriptService.java:151)  
at  
org.elasticsearch.action.update.UpdateHelper.prepare(UpdateHelper.java:147)  
... 8 more

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/286106af-af57-4cdb-a219-9d74d061a280%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/286106af-af57-4cdb-a219-9d74d061a280%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:18am UTC](https://discuss.elastic.co/t/elasticsearch-java-api-update-by-script-throws-error-when-field-value-contains-special-characters-etc/18455/2 "2017-07-06T01:18:13Z")

</div>


