Mapper Parsing Exception in elasticsearch

(Tarneet Singh) #1

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 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


(David Pilato) #2

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

(Tarneet Singh) #3

"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
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.ja
at org.elasticsearch.index.shard.IndexShard.prepareIndex(
at org.elasticsearch.action.index.TransportIndexAction.shardOperationOnP
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
at java.util.concurrent.ThreadPoolExecutor$
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
at org.elasticsearch.common.jackson.core.json.UTF8StreamJsonParser.getBi
at org.elasticsearch.common.jackson.core.JsonParser.getBinaryValue(JsonP
at org.elasticsearch.common.xcontent.json.JsonXContentParser.binaryValue
at org.elasticsearch.index.mapper.attachment.AttachmentMapper.parse(Atta
at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(Obj
at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.ja

(David Pilato) #4

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

You should have no \n within the value.

(Tarneet Singh) #5

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

(David Pilato) #6

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:




(Tarneet Singh) #7

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??

(David Pilato) #8

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.

(Tarneet Singh) #9

ok thank you sir

(system) #10