【问题标题】:How to execute PUT in curl in elastic search through python api如何通过python api在弹性搜索中在curl中执行PUT
【发布时间】:2021-01-26 05:15:15
【问题描述】:

下面是两个 curl 命令。

我需要通过python api在elasticsearch的索引中的curl中添加以下内容,如何实现这个

curl -XPUT 'http://localhost:9200/my_country_index_5/country/1' -d '
{
 "name": "Afginastan"
}'


curl -XPUT 'http://localhost:9200/my_country_index_5/state/1?parent=3' -d '
{
 "name": "Andra Pradesh",
 "country": "India"
}'

curl -XPUT 'http://localhost:9200/my_country_index_5/city/1?parent=5' -d '
{
 "name": "Kolhapur",
 "state": "Maharashtra"
}'

我在python中创建了索引下面是代码

from elasticsearch import Elasticsearch
es = Elasticsearch()
es.indices.create(index='my_country_index_5', ignore=400)

如何放入相同的索引(my_country_index_5)但不同的文档country, state, city

doc = {
       "name": "Afginastan"
          }
res = es.index(index="my_country_index_5", id=1, body=doc)
print(res['result'])

【问题讨论】:

标签: python elasticsearch curl


【解决方案1】:

如果我理解得很好,你想要type,它在 python 中显示为doc_type。版本 7 中省略了 type。在低于 7 的 elasticsearch 版本中,您可以通过在索引参数中发送 doc_type 来实现。

res = es.index(index="my_country_index_5", id=1, doc_type="state",  body=doc)
res = es.index(index="my_country_index_5", id=1, doc_type="city",  body=doc)
res = es.index(index="my_country_index_5", id=1, doc_type="country",  body=doc)

【讨论】:

    猜你喜欢
    • 2020-12-01
    • 1970-01-01
    • 2019-07-23
    • 2019-01-29
    • 1970-01-01
    • 2017-07-03
    • 2018-04-14
    • 2014-08-19
    • 1970-01-01
    相关资源
    最近更新 更多