elasticsearch,curl,Python,elasticsearch,Curl" /> elasticsearch,curl,Python,elasticsearch,Curl" />

如何通过pythonapi在弹性搜索中执行putincurl

如何通过pythonapi在弹性搜索中执行putincurl,python,elasticsearch,curl,Python,elasticsearch,Curl,下面是两个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=

下面是两个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\u index\u 5
)但不同的文档
country、state、city

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

如果我理解得很好,那么您希望使用python中显示为
doc\u type
type
<代码>类型在版本7中被省略。在低于7的elasticsearch版本中,您可以通过在索引参数中发送
doc\u 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)

如果我理解得很好,那么您希望使用python中显示为
doc\u type
type
<代码>类型在版本7中被省略。在低于7的elasticsearch版本中,您可以通过在索引参数中发送
doc\u 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)

@艾哈迈德,第一个卷曲在
我的国家索引5/国家
,第二个卷曲在
我的国家索引5/州
,第三个卷曲在我的国家索引5/州/city@Ahmad,第一个卷曲位于
我的国家索引\u 5/国家
,第二个卷曲位于
我的国家索引\u 5/州
,第三个卷曲位于我的国家索引\u 5/城市