首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ElasticsearchWarning:[类型删除]不推荐在文档索引请求中指定类型,而是使用无类型端点

ElasticsearchWarning:[类型删除]不推荐在文档索引请求中指定类型,而是使用无类型端点
EN

Stack Overflow用户
提问于 2021-11-29 22:07:41
回答 1查看 765关注 0票数 1

我应该在脚本中使用什么样的无类型端点,我希望在给定目录中索引json文件。犯了个小错误,搜了很多遍,却毫无头绪。完全错误:

代码语言:javascript
复制
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)

我的剧本:

代码语言:javascript
复制
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,我是哑巴,解决方案是见效的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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更深入地讨论它,这是一种不推荐的方法吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70161904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档