Reputation: 599
How to push the data into elastic search from python code
Right now i m pushing data with PUT
command
PUT /data/test/1
{
"id": "Accounting 101",
"dataproduct": "E3",
"professor": {
"name": "Thomas Baszo",
"department": "finance",
"facutly_type": "part-time",
"email": "[email protected]"
},
"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": "[email protected]"
},
"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"
}
How to push with python
pseudo code
from elasticsearch import Elasticsearch
es = Elasticsearch()
es.cluster.health()
es.indices.create(index='data', ignore=400)
Upvotes: 0
Views: 106
Reputation: 16923
You can either utilize the _bulk
endpoint or simply index
your docs one by one:
es.index('data',
body={
"name": "Accounting 101",
"room": "E3"
# ...
},
id=2)
Upvotes: 1