1
votes

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?

1
I'm afraid this is not a lucene or elasticsearch question but rather something related to curl, bash, perl - bpgergo
It is elasticsearch question regarding attachment type: elasticsearch.org/guide/reference/mapping/attachment-type.html - suraz
@suraz Please upvote and select the answer if it resolves the question. - Potatoswatter

1 Answers

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