Python 如何将json作为json而不是PUT方法推送到弹性搜索
如何从python代码将数据推入弹性搜索 现在我用Python 如何将json作为json而不是PUT方法推送到弹性搜索,python,elasticsearch,Python,elasticsearch,如何从python代码将数据推入弹性搜索 现在我用PUT命令推送数据 PUT /data/test/1 { "id": "Accounting 101", "dataproduct": "E3", "professor": { "name": "Thomas Baszo", "departme
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)
您可以使用端点,也可以简单地对文档逐个进行索引:
es.index('data',
body={
"name": "Accounting 101",
"room": "E3"
# ...
},
id=2)