# Json\_parse\_exception in elastic search

**URL:** <https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887>\
**Category:** Elasticsearch\
**Created:** [November 21, 2019, 12:40pm UTC](https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887 "2019-11-21T12:40:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayasree](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jayasree](https://discuss.elastic.co/u/jayasree)\
**Post date:** [November 21, 2019, 12:40pm UTC](https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887/1 "2019-11-21T12:40:08Z")

</div>

{"error":{"root\_cause":[{"type":"json\_parse\_exception","reason":"Unrecognized character escape '&' (code 38)\n at [Source: [org.elasticsearch.transport.netty4.ByteBufStreamInput@5c05c49d](mailto:org.elasticsearch.transport.netty4.ByteBufStreamInput@5c05c49d); line: 7, column: 188]"}]

we are using query structure following below code.

{  
"query": {  
"multi\_match": {  
"query": "' . $searchstringmsg . '",  
"type": "most\_fields",  
"fields": [  
"post\_title",  
"post\_content",  
"custom.cat\_name",  
"custom.series\_name",  
"custom.topic\_name",  
"custom.genre\_name",  
"post\_author.display\_name",  
"post\_meta.wps\_subtitle",  
"terms.post\_tag.name"  
],  
"fuzziness": "1"  
}  
},  
"aggs": {  
"top-sites": {  
"terms": {  
"field": "custom.pos\_format.keyword"  
},  
"aggs": {  
"top\_tags\_hits": {  
"top\_hits": {}  
}  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Julien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julien/32/19688_2.png) [@Julien](https://discuss.elastic.co/u/Julien)\
**Post date:** [November 21, 2019, 8:29pm UTC](https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887/2 "2019-11-21T20:29:57Z")

</div>

I see nothing wrong with the query you copied so maybe we need more backgroud on when you get the error...  
The error message is quite clear and means that on line 7 offset 188, you have invalid json - in this case you have `\&` to be precise... Here backslash should be escaped to be valid json `\\&` if you get the error when you try to index a document  
This invalid json with non-escaped backslash would give out the same error :

```auto
POST test/_doc
{
"myfield" : "test \&"
}

```

---

<div class="post-metadata">

**Author:** ![jayasree](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jayasree](https://discuss.elastic.co/u/jayasree)\
**Post date:** [November 27, 2019, 9:17am UTC](https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887/3 "2019-11-27T09:17:53Z")

</div>

while indexing is not a problem , when user search with special characters getting this type of error.can you please suggest me

---

<div class="post-metadata">

**Author:** ![Julien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julien/32/19688_2.png) [@Julien](https://discuss.elastic.co/u/Julien)\
**Post date:** [December 9, 2019, 10:52pm UTC](https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887/4 "2019-12-09T22:52:09Z")

</div>

Not reproducing any error with the query you sent, what query do you run in dev tools to reproduce the error and which version are you using?

---

<div class="post-metadata">

**Author:** ![jayasree](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jayasree](https://discuss.elastic.co/u/jayasree)\
**Post date:** [December 12, 2019, 7:07am UTC](https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887/5 "2019-12-12T07:07:13Z")

</div>

while indexing we are elastic press plugin in wordpress and we are using elastic search for website searching.

{"error":{"root\_cause":[{"type":"json\_parse\_exception","reason":"Unrecognized character escape '&' (code 38)\n at [Source: [org.elasticsearch.transport.netty4.ByteBufStreamInput@5c05c49d](mailto:org.elasticsearch.transport.netty4.ByteBufStreamInput@5c05c49d); line: 7, column: 188]"}]

[11-Dec-2019 14:50:46 America/Los\_Angeles] PHP Fatal error: Uncaught Elasticsearch\Common\Exceptions\ServerErrorResponseException: {"error":{"root\_cause":[{"type":"json\_parse\_exception","reason":"Unexpected character ('Ã­' (code 237)): was expecting comma to separate Object entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@7bcfef75; line: 6, column: 153]"}],  
The above errors is generated in php error logs.

we are using below coding structure for elastic search.

$json = '{  
"from": '.$data-\>from.',  
"size": 30,  
"query": {  
"multi\_match": {  
"query": "' . $searchstring . '",  
"type": "most\_fields",  
"fields": [  
"post\_title",  
"post\_content",  
"custom.cat\_name",  
"custom.series\_name",  
"custom.topic\_name",  
"custom.genre\_name",  
"post\_author.display\_name",  
"post\_meta.wps\_subtitle",  
"terms.post\_tag.name"  
],  
"fuzziness": "1"  
}  
},  
"post\_filter": {  
"term": {  
"custom.pos\_format": "aside"  
}  
}  
}';

$params = [  
'index' =\> 'devarrecoin-1',  
'type' =\> 'post',  
'body' =\> $json  
];

$results = $client-\>search($params);

Note: wordpress elastic press plugin Version 2.8.2,  
Elasticsearch-PHP Branch : 2.0  
Elastic search version 5.6.16  
can you please suggest me.

---

<div class="post-metadata">

**Author:** ![jayasree](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jayasree](https://discuss.elastic.co/u/jayasree)\
**Post date:** [December 19, 2019, 10:05am UTC](https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887/6 "2019-12-19T10:05:46Z")

</div>

Can you please suggest me  
iam using below query

json = '{ "from": 0, "size": 30, "query": { "multi\_match": { "query": "test and operator &+\_-@#%^!() with elastic search json parse exception",  
"type": "most\_fields",  
"fields": [  
"post\_title",  
"post\_content",  
"custom.cat\_name",  
"custom.series\_name",  
"custom.topic\_name",  
"custom.genre\_name",  
"post\_author.display\_name",  
"post\_meta.wps\_subtitle",  
"terms.post\_tag.name"  
],  
"fuzziness": "1"  
}  
},  
"post\_filter": {  
"term": {  
"custom.pos\_format": "asid"  
}  
}  
}';

$params = [  
'index' =\> 'devarrecoin-1',  
'type' =\> 'post',  
'body' =\> $json  
];

$results = $client-\>search($params);

{"error":{"root\_cause":[{"type":"json\_parse\_exception","reason":"Unrecognized character escape '&' (code 38)\n at [Source: [org.elasticsearch.transport.netty4.ByteBufStreamInput@5c05c49d](mailto:org.elasticsearch.transport.netty4.ByteBufStreamInput@5c05c49d); line: 7, column: 188]"}]

[11-Dec-2019 14:50:46 America/Los\_Angeles] PHP Fatal error: Uncaught Elasticsearch\Common\Exceptions\ServerErrorResponseException: {"error":{"root\_cause":[{"type":"json\_parse\_exception","reason":"Unexpected character ('Ã­' (code 237)): was expecting comma to separate Object entries\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@7bcfef75; line: 6, column: 153]"}],  
The above errors is generated in php error logs.

---

<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:** [January 16, 2020, 10:05am UTC](https://discuss.elastic.co/t/json-parse-exception-in-elastic-search/208887/7 "2020-01-16T10:05:47Z")

</div>

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