【发布时间】:2022-01-21 19:07:02
【问题描述】:
我在 python 中使用Elasticsearch 库来查询弹性搜索服务器,如下所示:
query = {
"query":{
"match_all":{}
}
}
es = Elasticsearch('localhost:9200')
res = es.search(index='myindex', body=query)
with open('response.json', 'w') as out:
out.write(res)
# json.dump(res, out) also gives the same result
我保存到文件的输出具有格式
{
'key':'value',
'key2': {
'key3' : 'value2'
}
}
请注意此处的单引号。我知道我可以做一个简单的查找和替换或使用sed 将单引号更改为双引号,但是,我想知道为什么在终端使用curl 时会发生这种情况。
我希望以正确的json 格式转储输出
【问题讨论】:
标签: python json elasticsearch response dump