I create a simple mapping:
curl -XPUT 'localhost:9200/ficherosindex?pretty=true' -d '{
"mappings": {
"items": {
"dynamic": "strict",
"properties" : {
"title" : { "type": "string" },
"body" : { "type": "string" },
"attachments" : { "type": "attachment" }
}}}}'
I make PUT
the title
and the body
, leaving attachments
empty.
curl -XPUT 'localhost:9200/ficherosindex/items/1' -d '{
"title": "This is a test title",
"body" : "This is the body of the java",
"attachments" : ""
}'
And then I make the following script to update the attachments
fields with the content of the MY_PDF.pdf
file, converting it to base64
.
#!/bin/sh
coded=`cat MY_PDF.pdf | perl -MMIME::Base64 -ne 'print encode_base64($_)'`
curl -X POST 'localhost:9200/ficherosindex/items/1/_update?pretty=true' -d '{
"doc" : {
"attachments" : \"${coded}\"
}}'
When I run the script I'm getting the following error:
{
"error" : {
"root_cause" : [ {
"type" : "json_parse_exception",
"reason" : "Unexpected character ('\\' (code 92)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [B@6c8caddf; line: 3, column: 30]"
} ],
"type" : "json_parse_exception",
"reason" : "Unexpected character ('\\' (code 92)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: [B@6c8caddf; line: 3, column: 30]"
},
"status" : 500
}
What I'm doing wrong? Maybe I've to change the following line?
{
"doc" : {
"attachments" : \"${coded}\"
}}'
I also tried this solution with no luck. I have to mantain the order I'm showing. First create the item without the attachments
and then use the _update
to append the content of the .PDF to it.
Thanks in advance