我正在尝试将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`。答案 0 :(得分:4)
elasticsearch.py将json响应转换为python的字典,以便于提取信息。
即
{u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}}
是python字典。
如果你想在json结构中使用它,那么你可以做到,
json.dumps()
查看更多python