Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何将json作为json而不是PUT方法推送到弹性搜索_Python_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Python,elasticsearch" /> elasticsearch,Python,elasticsearch" />

Python 如何将json作为json而不是PUT方法推送到弹性搜索

Python 如何将json作为json而不是PUT方法推送到弹性搜索,python,elasticsearch,Python,elasticsearch,如何从python代码将数据推入弹性搜索 现在我用PUT命令推送数据 PUT /data/test/1 { "id": "Accounting 101", "dataproduct": "E3", "professor": { "name": "Thomas Baszo", "departme

如何从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)

您可以使用端点,也可以简单地对文档逐个进行索引:

es.index('data',
         body={
             "name": "Accounting 101",
             "room": "E3"
             # ...
         },
         id=2)