python - 如何将 json 作为 json 而不是 PUT 方法推送到弹性搜索
问题描述
如何从 python 代码将数据推送到弹性搜索中
现在我用PUT
命令推送数据
PUT /data/test/1
{
"id": "Accounting 101",
"dataproduct": "E3",
"professor": {
"name": "Thomas Baszo",
"department": "finance",
"facutly_type": "part-time",
"email": "baszot@onuni.com"
},
"students_enrolled": 27,
"course_publish_date": "2015-01-19",
"course_description": "Act 101 is a course from the business school on the introduction to accounting that teaches students how to read and compose basic financial statements"
}
PUT /data/test/2
{
"name": "Accounting 101",
"room": "E3",
"professor": {
"name": "Thomas Baszo",
"department": "finance",
"facutly_type": "part-time",
"email": "baszot@onuni.com"
},
"students_enrolled": 27,
"course_publish_date": "2015-01-19",
"course_description": "Act 101 is a course from the business school on the introduction to accounting that teaches students how to read and compose basic financial statements"
}
如何用python推送
伪代码
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.cluster.health()
es.indices.create(index='data', ignore=400)
解决方案
您可以使用_bulk
端点,也可以index
一一使用您的文档:
es.index('data',
body={
"name": "Accounting 101",
"room": "E3"
# ...
},
id=2)
推荐阅读
- python - 破折号,将输入保存为变量
- vba - 如何将 Access 中的 basColorPicker 模块更新为 64 位?
- excel - 在给定半径、高度和深度的情况下,在 VBA 中找到罐的体积
- java - Spark foreachPartition 仅在 master 上运行
- javascript - Angular 单元测试:为什么我的 expect(1).toBe(2) 总是通过?
- database - 在 Postgres 中存储加密数据最合适的方式
- python - ValueError:托管端点错误。生产变体 AllTraffic 的主容器未通过 ping 健康检查
- windows-installer - 错误代码 1703,没有消息和选项,按 OK 后强制重启
- c# - 如何将具有属性的类传递给 WPF 模式窗口,对其进行修改,然后将类返回父窗口?
- regex - 在字符串前后添加一个单词