【发布时间】:2022-01-06 17:28:38
【问题描述】:
我应该在我的脚本中使用什么无类型端点,我想索引给定目录中的 json 文件。遇到一个小错误,搜索了很多但没有任何线索。 完整的错误:
C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\site-packages\elasticsearch\connection\base.py:209: ElasticsearchWarning: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints instead (/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id}).
warnings.warn(message, category=ElasticsearchWarning)
我的脚本:
import requests, json, os
from elasticsearch import Elasticsearch
#folder containing the json folders of scraped data
directory = '../spider/'
#Elasticsearch instance will listen on port 9200
res = requests.get('http://localhost:9200')
print (res.content)
es = Elasticsearch([{'host': 'localhost', 'port': '9200'}])
#index value object to iterate over the JSON files
i = 1
#Iterate over each JSON file and load it into Elasticsearch
for filename in os.listdir(directory):
if filename.endswith(".json"):
fullpath=os.path.join(directory, filename)
f = open(fullpath)
docket_content = f.read()
# Send the data into es
es.index(index='myIndex', ignore=400, doc_type='docket', id=i, document=json.loads(docket_content),)
i = i + 1
这是我第一次尝试 Elasticsearch,我很笨,解决方案已经被应用了。
【问题讨论】:
标签: python elasticsearch