我有两个用python创建的字典,我想把它转换成elasticsearch json格式。
下面是我要转换的示例json(bulk\u movies.json)格式的链接:https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-gsg-upload-data.html
以下是两本词典:
dic1 = {'index': {'_index': 'movies', '_id': '1'}
dic2 = {'id': '1', 'year': '2009'}
我使用以下代码将数据导入json文件。然而,这两部词典是同一条线。
with open(file, 'w') as fd:
fd.write(json.dumps([dic1, dic2]))
实际输出:
[{'index': {'_index': 'movies', '_id': '1'}}, {'id': '1', 'year': '2009'}]
所需输出:
{'index': {'_index': 'movies', '_id': '1'}
{'id': '1', 'year': '2009'}
如果有人能帮我,那就太好了!!
暂无答案!
目前还没有任何答案,快来回答吧!