gpt4 book ai didi

json - 在elasticsearch中将文件转换为base64以进行附件

转载 作者:行者123 更新时间:2023-12-03 00:30:29 26 4
gpt4 key购买 nike

实际上,我想将文件更改为base64并附加我的 flex 搜索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"
}
}
}'


当我执行此查询时,特别是在发布数据时,出现此错误:

"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


这类问题有解决方案吗?我正在尝试在附加文件时将数据更改为base64。
救命??

即使在我双引号并执行时:


curl -XPOST "http://localhost:9200/test/xmlfile?pretty=1" -d '
{
"attachment" : "'`base64 /path/filename | perl -pe 's/\n/\\n/g'`'"
}'


我得到这个错误

{"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}


我在这里想念什么吗?

最佳答案

"attachment" : '`base64 /path/filename | perl -pe 's/\n/\\n/g'`'
base64周围的引号会在 shell 程序中取消引用,然后在反引号之前执行命令。您需要另一个双引号来表示JSON。
"attachment" : "'`base64 /path/filename | perl -pe 's/\n/\\n/g'`'"

关于json - 在elasticsearch中将文件转换为base64以进行附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12347349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com