1

实际上,我想将文件更改为 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 在 [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'`'"
    }'


我得到这个错误

{“错误”:“MapperParsingException [无法解析];嵌套:JsonParseException [在 [来源:[B@39c931fb;行:2,列:195]] 的 VALUE_STRING\n 中出现意外的输入结束;“,”状态“:400}

我在这里有什么遗漏吗?

4

1 回答 1

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

base64周围的引号是为外壳取消引用它,然后用反引号引用来执行命令。JSON 需要另一个双引号。

"attachment" : "'`base64 /path/filename | perl -pe 's/\n/\\n/g'`'"
于 2012-09-10T07:54:48.490 回答