# Mapper Parsing Exception in elasticsearch

**URL:** https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825
**Category:** Elasticsearch
**Created:** [October 23, 2015, 7:46am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825 "2015-10-23T07:46:12Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Tarneet\_Singh](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tarneet\_Singh](https://discuss.elastic.co/u/Tarneet_Singh)
#### Post date: [October 23, 2015, 7:46am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/1 "2015-10-23T07:46:12Z")

</div>

i have installed the mapper attachment plugin successfully.i am using Elasticsearch - 1.7.3 and mapper attachment - 2.7.1. i want to use attachments for searching purpose. with the help of this link [https://github.com/elastic/elasticsearch-mapper-attachments/tree/v2.7.1/#version-271-for-elasticsearch-17](https://github.com/elastic/elasticsearch-mapper-attachments/tree/v2.7.1/#version-271-for-elasticsearch-17) i was trying to understand how it is done

i complete the first step i.e i have set a json element as attachment through this  
PUT /test/person/\_mapping  
{  
"person" : {  
"properties" : {  
"my\_attachment" : { "type" : "attachment" }  
}  
}  
}  
it worked, but in the second step i.e  
PUT /test/person/1  
{  
"my\_attachment" : "... base64 encoded attachment ..."  
}  
i got a mapper parsing exception. i am using postman for this. i have not used elasticsearch before so please help me to resolve this error please reply asap

thanks  
tarneet

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 23, 2015, 8:43am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/2 "2015-10-23T08:43:11Z")

</div>

If you post the full error, that could help. May be with logs.

---

<div class="post-metadata">

### Author: ![Tarneet\_Singh](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tarneet\_Singh](https://discuss.elastic.co/u/Tarneet_Singh)
#### Post date: [October 23, 2015, 9:05am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/3 "2015-10-23T09:05:57Z")

</div>

{  
"error": "MapperParsingException[failed to parse]; nested: JsonParseException[Failed to decode VALUE\_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character '.' (code 0x2e) in base64 content\n at [Source: [B@e946b; line: 2, column: 25]]; ",  
"status": 400  
}

[2015-10-23 14:34:48,281][INFO][cluster.metadata] [Lockjaw] [test] cre  
ate\_mapping [person]  
[2015-10-23 14:35:21,791][DEBUG][action.index] [Lockjaw] [test][2],  
node[pCltRcnLRamM0Ch9Hke3xg], [P], s[STARTED]: Failed to execute [index {[test]  
[person][1], source[{  
"my\_attachment" : "... base64 encoded attachment ..."  
}]}]  
org.elasticsearch.index.mapper.MapperParsingException: failed to parse  
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.ja  
va:565)  
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.ja  
va:493)  
at org.elasticsearch.index.shard.IndexShard.prepareIndex(IndexShard.java  
:493)  
at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnP  
rimary(TransportIndexAction.java:192)  
at org.elasticsearch.action.support.replication.TransportShardReplicatio  
nOperationAction$PrimaryPhase.performOnPrimary(TransportShardReplicationOperatio  
nAction.java:574)  
at org.elasticsearch.action.support.replication.TransportShardReplicatio  
nOperationAction$PrimaryPhase$1.doRun(TransportShardReplicationOperationAction.j  
ava:440)  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(Abstrac  
tRunnable.java:36)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.  
java:1142)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor  
.java:617)  
at java.lang.Thread.run(Thread.java:745)  
Caused by: org.elasticsearch.common.jackson.core.JsonParseException: Failed to d  
ecode VALUE\_STRING as base64 (MIME-NO-LINEFEEDS): Illegal character '.' (code 0x  
2e) in base64 content  
at [Source: [B@e946b; line: 2, column: 25]  
at org.elasticsearch.common.jackson.core.JsonParser.\_constructError(Json  
Parser.java:1487)  
at org.elasticsearch.common.jackson.core.json.UTF8StreamJsonParser.getBi  
naryValue(UTF8StreamJsonParser.java:444)  
at org.elasticsearch.common.jackson.core.JsonParser.getBinaryValue(JsonP  
arser.java:1131)  
at org.elasticsearch.common.xcontent.json.JsonXContentParser.binaryValue  
(JsonXContentParser.java:188)  
at org.elasticsearch.index.mapper.attachment.AttachmentMapper.parse(Atta  
chmentMapper.java:390)  
at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(Obj  
ectMapper.java:706)  
at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper  
.java:497)  
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.ja  
va:544)

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 23, 2015, 9:25am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/4 "2015-10-23T09:25:22Z")

</div>

Your BASE64 encoding is "incorrect " as it's on multiple lines.

You should have no \n within the value.

---

<div class="post-metadata">

### Author: ![Tarneet\_Singh](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tarneet\_Singh](https://discuss.elastic.co/u/Tarneet_Singh)
#### Post date: [October 23, 2015, 9:32am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/5 "2015-10-23T09:32:42Z")

</div>

how to remove this \n and in which file??  
actually the thing is users will upload a file and i want to search users by the help of uploaded files

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 23, 2015, 10:02am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/6 "2015-10-23T10:02:22Z")

</div>

You have to generate BASE64 strings without Line breaks.  
I'm not saying you should remove line breaks in files themselves.

Instead of sending incorrect JSON like:

```
"field": "AAAAAAAAAAAA
AAAAAAAAAA"

```

Send:

```
"field": "AAAAAAAAAAAAAAAAAAAAAA"
```

---

<div class="post-metadata">

### Author: ![Tarneet\_Singh](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tarneet\_Singh](https://discuss.elastic.co/u/Tarneet_Singh)
#### Post date: [October 23, 2015, 10:30am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/7 "2015-10-23T10:30:51Z")

</div>

ya it worked thank you very much sir

can you tell me one more thing when user send their file, should it be first converted into base64?  
and also when we do the searching what code should i use??

for simple text search i do this:  
$query = $es-\>search([  
'body' =\> [  
'query' =\> [  
'bool' =\> [  
'should' =\> [  
'match' =\> ['skills2' =\> $q],  
'match' =\> ['location2' =\> $l]  
]  
]  
]  
]  
]);  
if($query['hits']['total'] \>= 1){  
$results = $query['hits']['hits'];  
}  
skills2 and location2 are just field names  
and it worked but for files i do not know what code to use??

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 23, 2015, 10:45am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/8 "2015-10-23T10:45:06Z")

</div>

> [@Tarneet\_Singh](#):
>
> can you tell me one more thing when user send their file, should it be first converted into base64? and also when we do the searching what code should i use??

I don't exactly understand the question. You need to provide to elasticsearch a JSON document. The only way to add a binary content in a JSon document is by converting it first to BASE64.

About searching, you have many examples I think on the mapper attachments plugin README file.

---

<div class="post-metadata">

### Author: ![Tarneet\_Singh](https://avatars.discourse-cdn.com/v4/letter/t/f0a364/32.png) [@Tarneet\_Singh](https://discuss.elastic.co/u/Tarneet_Singh)
#### Post date: [October 23, 2015, 10:48am UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/9 "2015-10-23T10:48:27Z")

</div>

ok thank you sir

---

<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, 11:43pm UTC](https://discuss.elastic.co/t/mapper-parsing-exception-in-elasticsearch/32825/10 "2017-07-05T23:43:04Z")

</div>


