# Escaping index requests for REST API from Java

**URL:** <https://discuss.elastic.co/t/escaping-index-requests-for-rest-api-from-java/55253>\
**Category:** Elasticsearch\
**Created:** [July 12, 2016, 1:12am UTC](https://discuss.elastic.co/t/escaping-index-requests-for-rest-api-from-java/55253 "2016-07-12T01:12:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hherman1](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@hherman1](https://discuss.elastic.co/u/hherman1)\
**Post date:** [July 12, 2016, 1:12am UTC](https://discuss.elastic.co/t/escaping-index-requests-for-rest-api-from-java/55253/1 "2016-07-12T01:12:59Z")

</div>

Hi, I'm trying to escape my document index PUT requests in Java, and having a hell of a time. Things I've tried:

Apache commons-lang EscapeUtils.escapeJavascript  
Lucene QueryParser.escape

Neither of these work, the first escapes " ' " to " ' " and Elasticsearch is not happy, while the second does not escape new lines. I'm not very interested in a JSON library because its massive overkill, I'm only making one or two very particular type of query ever over the course of my application.

Please, help.

---

<div class="post-metadata">

**Author:** ![hherman1](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@hherman1](https://discuss.elastic.co/u/hherman1)\
**Post date:** [July 12, 2016, 2:52am UTC](https://discuss.elastic.co/t/escaping-index-requests-for-rest-api-from-java/55253/2 "2016-07-12T02:52:47Z")

</div>

The latest version of Apache commons-lang3 (3.4) has escapeJson which worked

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [July 14, 2016, 8:24am UTC](https://discuss.elastic.co/t/escaping-index-requests-for-rest-api-from-java/55253/3 "2016-07-14T08:24:14Z")

</div>

Hi,  
did you solve the problem after all?

If not, I think it would help if you posted what your requests look like and what you already tried.

Cheers  
Luca

---

<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, 2017, 10:35pm UTC](https://discuss.elastic.co/t/escaping-index-requests-for-rest-api-from-java/55253/4 "2017-07-05T22:35:48Z")

</div>


