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
{
"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)
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??
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.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.