What typeless endpoint should I use in my script, I want to index the json files in a given directory. Getting a slight error, searched a lot but got no clue. The full error:
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)
My script:
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
This is my first time trying out Elasticsearch, I am dumb and solutions are appriciated.
CodePudding user response:
you need to change doc_type='docket'
to doc_type='_doc'
and it'll work with what you have
https://www.elastic.co/guide/en/elasticsearch/reference/7.15/removal-of-types.html goes into it more, are it's a deprecated approach