将文件转换为弹性搜索中的base64以进行附件 [英] convert the file into base64 in elasticsearch for attachment

查看:378
本文介绍了将文件转换为弹性搜索中的base64以进行附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我想将文件更改为base64,并附加弹性搜索JSON数据。

我的代码如下:

 


curl -XDELETEhttp:// localhost:9200 / test

curl -XPUThttp:// localhost:9200 / test /?pretty = 1-d'
{
mapping:{
xmlfile:{
properties:{
attachment:{type:attachment}
}
}
}
}'

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

curl -XGEThttp:// localhost:9200 / test / xmlfile / _search?pretty = 1-d'
{
查询:{
文本:{
文件:任何文本都会来这里
}
}
}'

/ p>

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


error:MapperParsingException [无法解析];嵌套:JsonParseException [意外字符('P'(代码80)):期望一个有效的值(number,String,array,object,'true','false'或null)\在[来源:[B @ 4daa8b42;行:3,列:17]];,状态:400


这种问题有解决方法吗?我正在尝试在附加文件时将数据更改为base64。
帮助??




即使我给双引号和执行:

 


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



我得到这个错误


{error:MapperParsingException [无法解析];嵌套: JsonParseException [VALUE_STRING\\\
中的[来源:[B @ 39c931fb;行:2,列:195]]的意外结束输入];,status:400}


我在这里缺少什么?

解决方案

 attachment:'`base64 / path / filename | perl -pe's / \\\
/ \\\\
/g'`'

引用围绕 base64 的引号用于shell,然后使用反引号来执行命令。您需要另一个双引号的JSON。

 附件:'base64 / path / filename | perl -pe' s / \\\
/ \\\\
/ g'`'


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.
Help??

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'`'"

这篇关于将文件转换为弹性搜索中的base64以进行附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆