我应该在脚本中使用什么样的无类型端点,我希望在给定目录中索引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,我是哑巴,解决方案是见效的。
发布于 2021-11-30 00:33:01
您需要将doc_type='docket'更改为doc_type='_doc',它将与您拥有的内容一起工作。
https://www.elastic.co/guide/en/elasticsearch/reference/7.15/removal-of-types.html更深入地讨论它,这是一种不推荐的方法吗?
https://stackoverflow.com/questions/70161904
复制相似问题