I'm trying to use the python
client for elasticsearch
. Here is a minimal example:
import logging
logging.basicConfig()
from elasticsearch import Elasticsearch as ES
print "Setup connection..."
es=ES(['localhost:8080'])
print "Done!"
print "Count number of users..."
print es.count(index='users')
The output is:
{u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}}
I have two questions:
- How do I get rid of the
u'
(u
followed by a single quote )? How can I extract the value of count? I guess I could do string manipulation, but that sounds like the wrong way....Answer: if the output is saved tores
, thenres['count'] returns the number
836780`.
u''
tells you that the string is Unicode (see docs.python.org/2/howto/unicode.html). That structure is a dictionary, string manipulation is definitely not the easiest approach. – Karalee