我正在尝试将python
客户端用于elasticsearch
。这是一个最小的示例:
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')
输出为:
{u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}}
我有两个问题:
u'
(u
后接单引号)?res
,res['count'] returns the number
则为836780`。elasticsearch.py将json响应转换为python的字典,因此很容易提取信息。
即
{u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}}
是python字典。
如果您希望将其包含在json结构中,则可以这样做,
json.dumps()
看起来更多的python
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句