Updating data in elasticsearch from urllib2 (Python)

Hi everyone,

I'm trying to do a simple update. With curl simply I put following command
in console.

curl -XPOST
http://localhost:9200/peticiones-2014.04.08/logs/pJ_T-Lt1QW6u3luxVrI_ZQ/_update
-d '{"doc": { "Parametros" : "PruebaParametros"}}'{'doc': '{ Parametros :
PruebaParametros}'}

And it works perfectly. The problem is that I want do exactly the same
thing in a script, with urllib2 in Python. My code is:

    values = { "doc" : "{ Parametros : PruebaParametros }" }

postData = urllib.urlencode(values)
req = urllib2.Request(query, postData)
response = urllib2.urlopen(req)

Query is
"http://localhost:9200/peticiones-2014.04.08/logs/pJ_T-Lt1QW6u3luxVrI_ZQ/_update".
But I'm getting the following error: "urllib2.HTTPError: HTTP Error 500:
Internal Server Error"

What am I doing wrong?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/00c788f1-ebac-4904-a12d-1db32fd47c85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hello Josep,

you need to send the data as json, not as urlencoded, so:

values = { "doc" : "{ Parametros : PruebaParametros }" }
postData = json.dumps(values)
req = urllib2.Request(query, postData)
response = urllib2.urlopen(req)

but unless you have very specific requirements I'd strongly suggest
you use the official python client - http://elasticsearch-py.rtfd.org

Hope this helps,
Honza

On Tue, Apr 8, 2014 at 2:11 AM, Josep Floriach Ventosinos
josep.floriach.ventosinos@gmail.com wrote:

Hi everyone,

I'm trying to do a simple update. With curl simply I put following command
in console.

curl -XPOST
http://localhost:9200/peticiones-2014.04.08/logs/pJ_T-Lt1QW6u3luxVrI_ZQ/_update
-d '{"doc": { "Parametros" : "PruebaParametros"}}'{'doc': '{ Parametros :
PruebaParametros}'}

And it works perfectly. The problem is that I want do exactly the same thing
in a script, with urllib2 in Python. My code is:

    values = { "doc" : "{ Parametros : PruebaParametros }" }

postData = urllib.urlencode(values)
req = urllib2.Request(query, postData)
response = urllib2.urlopen(req)

Query is
"http://localhost:9200/peticiones-2014.04.08/logs/pJ_T-Lt1QW6u3luxVrI_ZQ/_update".
But I'm getting the following error: "urllib2.HTTPError: HTTP Error 500:
Internal Server Error"

What am I doing wrong?

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/00c788f1-ebac-4904-a12d-1db32fd47c85%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CABfdDio4_BSFi-Hf5AQ_-iMhkLRQq-jzvqXX7iiPLVaZcp249A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

That was so helpful! Thanks!

However, my index is not being updated... I'm gonna try Python
elasticsearch client...

Thanks again!

On Tuesday, April 8, 2014 11:20:31 AM UTC+2, Honza Král wrote:

Hello Josep,

you need to send the data as json, not as urlencoded, so:

values = { "doc" : "{ Parametros : PruebaParametros }" }
postData = json.dumps(values)
req = urllib2.Request(query, postData)
response = urllib2.urlopen(req)

but unless you have very specific requirements I'd strongly suggest
you use the official python client - http://elasticsearch-py.rtfd.org

Hope this helps,
Honza

On Tue, Apr 8, 2014 at 2:11 AM, Josep Floriach Ventosinos
<josep.floria...@gmail.com <javascript:>> wrote:

Hi everyone,

I'm trying to do a simple update. With curl simply I put following
command
in console.

curl -XPOST

http://localhost:9200/peticiones-2014.04.08/logs/pJ_T-Lt1QW6u3luxVrI_ZQ/_update

-d '{"doc": { "Parametros" : "PruebaParametros"}}'{'doc': '{ Parametros
:
PruebaParametros}'}

And it works perfectly. The problem is that I want do exactly the same
thing
in a script, with urllib2 in Python. My code is:

    values = { "doc" : "{ Parametros : PruebaParametros }" } 

postData = urllib.urlencode(values)
req = urllib2.Request(query, postData)
response = urllib2.urlopen(req)

Query is
"
http://localhost:9200/peticiones-2014.04.08/logs/pJ_T-Lt1QW6u3luxVrI_ZQ/_update".

But I'm getting the following error: "urllib2.HTTPError: HTTP Error 500:
Internal Server Error"

What am I doing wrong?

--
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 elasticsearc...@googlegroups.com <javascript:>.
To view this discussion on the web visit

https://groups.google.com/d/msgid/elasticsearch/00c788f1-ebac-4904-a12d-1db32fd47c85%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/090f094c-e7c8-4163-971a-cd3633a48714%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Your index may not be updating due to the way you are creating the doc.

values = { "doc" : "{ Parametros : PruebaParametros }" }

Should be...

values = { "doc" : { "Parametros" : "PruebaParametros" } }

-> Notice the change in quotes and where they are being placed

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/de8e51ec-4447-417a-bf8e-375d0a2f31ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.