【问题标题】:ElasticsearchWarning: [types removal] Specifying types in document index requests is deprecated, use the typeless endpoints insteadElasticsearchWarning:[删除类型] 不推荐在文档索引请求中指定类型,请改用无类型端点
【发布时间】: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


    【解决方案1】:

    您需要将doc_type='docket' 更改为doc_type='_doc',它将与您所拥有的一起工作

    https://www.elastic.co/guide/en/elasticsearch/reference/7.15/removal-of-types.html 更深入地了解它,这是一种已弃用的方法

    【讨论】:

    • 谢谢,它成功了,不再是错误。最后你能告诉我如何从 Kibana 查看索引吗?索引,myIndex 还没有,我不应该可以从那里查看索引吗?
    • 或者至少,我如何确认这个索引是通过 Elasticsearch 上的脚本建立的?
    猜你喜欢
    • 2021-04-02
    • 2021-03-03
    • 2019-10-18
    • 2020-05-09
    • 1970-01-01
    • 2020-09-10
    • 1970-01-01
    • 2021-02-05
    • 2016-02-14
    相关资源
    最近更新 更多