Actually, I want to change the file into base64 and attach with my elastic search JSON data.
My Code is given below:
curl -XDELETE "http://localhost:9200/test"
curl -XPUT "http://localhost:9200/test/?pretty=1" -d '
{
"mapping" : {
"xmlfile" : {
"properties" : {
"attachment": { "type" : "attachment" }
}
}
}
}'
curl -XPOST "http://localhost:9200/test/xmlfile?pretty=1" -d '
{
"attachment" : '`base64 /path/filename | perl -pe 's/\n/\\n/g'`'
}'
curl -XGET "http://localhost:9200/test/xmlfile/_search?pretty=1" -d '
{
"query" : {
"text" : {
"file" : "any text will come here"
}
}
}'
When I execute this queries, specially while posting data I get this Error:
"error" : "MapperParsingException[Failed to parse]; nested: JsonParseException[Unexpected character ('P' (code 80)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\\n at [Source: [B@4daa8b42; line: 3, column: 17]]; ","status" : 400
Is there any solution for this kind of problem? I am trying to change the data into base64 while attaching the file.
Even, when I give double-quote and execute:
curl -XPOST "http://localhost:9200/test/xmlfile?pretty=1" -d '
{
"attachment" : "'`base64 /path/filename | perl -pe 's/\n/\\n/g'`'"
}'
I get this Error
{"error" : "MapperParsingException[Failed to parse]; nested: JsonParseException[Unexpected end-of-input in VALUE_STRING\\n at [Source: [B@39c931fb; line: 2, column: 195]]; ","status" : 400}
Am I missing anything, here?
"attachment" : '`base64 /path/filename | perl -pe 's/\n/\\n/g'`'
The quotes around base64
are unquoting it for the shell and then backtick-quoting to execute the command. You need another double-quote for JSON.
"attachment" : "'`base64 /path/filename | perl -pe 's/\n/\\n/g'`'"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.