Convert the file into base64 in elasticsearch for attachment

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

--

I think that your concern is here:
"attachment" : 'base64 /path/filename | perl -pe 's/\n/\\n/g''
you use a simple ' to wrap your base64 content.
You should have a "

So your JSON content is like :

curl -XPOST "http://localhost:9200/test/xmlfile?pretty=1" -d '
{
"attachment" : 'XXXXXX'
}'

which is IMHO, incorrect

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 10 sept. 2012 à 09:53, suraz surajyonzon@gmail.com a écrit :

Actually, I want to change the file into base64 and attach with my Elasticsearch 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??

--

--

Actually, I want to convert the file into base64 while posting the data
instead of converting the file into base64 format separately.

I think, there is a way for doing this but have to little dig up.

On Monday, September 10, 2012 1:52:22 PM UTC+5:45, David Pilato wrote:

I think that your concern is here:

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

you use a simple ' to wrap your base64 content.
You should have a "

So your JSON content is like :

curl -XPOST "http://localhost:9200/test/xmlfile?pretty=1" -d '
{
"attachment" : 'XXXXXX'
}'

which is IMHO, incorrect

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 10 sept. 2012 à 09:53, suraz <suraj...@gmail.com <javascript:>> a
écrit :

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

--

--

hi

what you have to do is add extra " quotes into the GET command:

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

On Monday, 10 September 2012 17:53:24 UTC+10, suraz wrote:

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

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

obviously POST not GET method

On Tuesday, 23 April 2013 18:00:46 UTC+10, gondo wrote:

hi

what you have to do is add extra " quotes into the GET command:

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

On Monday, 10 September 2012 17:53:24 UTC+10, suraz wrote:

Actually, I want to change the file into base64 and attach with my
Elasticsearch 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??

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I indexed the attachment value into base64 but while searching it didn't get the result?
Need to set anything?

Hi, how can i get the same result on windows platform? How can i encode the file base64 inside json string on the fly during document post ?

thanx a lot

valeiro

Don't answer to a thread which is 2 years old. You should open a new one and eventually link to this one.

You need to build a service which does that. Elasticsearch doesn't support dropping binary files directly. You could write a plugin may be.

Thanx

actually i have noticed it is possible converting using a command line inside the <> field, for linux platform like :
"attachment" : 'base64 /path/filename | perl -pe 's/\n/\\n/g''I am wondering how getting the same result in windows.

thanx valerio