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:
u'
(u
followed by a single quote )? res
, then res['count'] returns the number
836780`.What is ElasticSearch? ElasticSearch (ES) is a distributed and highly available open-source search engine that is built on top of Apache Lucene. It's an open-source which is built in Java thus available for many platforms. You store unstructured data in JSON format which also makes it a NoSQL database.
elasticsearch.py convert json response to dictionary for python, so that it is easy to extract information.
I.e
{u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}}
is python dictionary.
If you wan to have it in json structure then you can do,
json.dumps()
look more python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With