格式化elasticsearch-py的输出

德罗

我正在尝试将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}}

我有两个问题:

  1. 我如何摆脱u'u后接单引号)?
  2. 如何提取计数值?我想我可以进行字符串操作,但这听起来像是错误的方法..答:如果将输出保存到resres['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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章