我應該在我的腳本中使用什么無型別端點,我想索引給定目錄中的 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,我很笨,解決方案很受歡迎。
uj5u.com熱心網友回復:
您需要更改doc_type='docket'到doc_type='_doc',它會與你有什么作業
https://www.elastic.co/guide/en/elasticsearch/reference/7.15/removal-of-types.html深入探討,是否是一種已棄用的方法
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/375332.html
