[英]convert the file into base64 in elasticsearch for attachment
实际上,我想将文件更改为base64并附加我的弹性搜索JSON数据。
我的代码如下:
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"
}
}
}'
当我执行此查询时,特别是在发布数据时,出现此错误:
“错误”:“ MapperParsingException [无法解析];嵌套:JsonParseException [意外字符('P'(代码80)):预期为有效值(数字,字符串,数组,对象,'true','false'或' null')\\ n [来源:[B @ 4daa8b42;第3行,第17列]];“,”状态“:400
这类问题有解决方案吗? 我正在尝试在附加文件时将数据更改为base64。
救命??
即使在我双引号并执行时:
curl -XPOST "http://localhost:9200/test/xmlfile?pretty=1" -d '
{
"attachment" : "'`base64 /path/filename | perl -pe 's/\n/\\n/g'`'"
}'
我得到这个错误
{“错误”:“ MapperParsingException [无法解析];嵌套:JsonParseException [在VALUE_STRING \\ n中意外的输入结束,位于[来源:[B @ 39c931fb;第2行,第195行]]];“,”状态:: 400}
我在想什么吗?
"attachment" : '`base64 /path/filename | perl -pe 's/\n/\\n/g'`'
base64
周围的引号会在外壳程序中将其取消引用,然后在反引号之前执行命令。 您需要另一个双引号来表示JSON。
"attachment" : "'`base64 /path/filename | perl -pe 's/\n/\\n/g'`'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.