[英]Format the output of elasticsearch-py
I'm trying to use the python
client for elasticsearch
. 我正在尝试使用
python
客户端进行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 )? u'
( u
跟着一个单引号)? res
, then res['count'] returns the number
836780`. res
,则res['count'] returns the number
836780`。 elasticsearch.py convert json response to dictionary for python, so that it is easy to extract information. elasticsearch.py将json响应转换为python的字典,以便于提取信息。
Ie 即
{u'count': 836780, u'_shards': {u'successful': 5, u'failed': 0, u'total': 5}}
is python dictionary. 是python字典。
If you wan to have it in json structure then you can do, 如果你想在json结构中使用它,那么你可以这样做,
json.dumps()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.