'error': 'no handler found for uri [/test_network_data/json/1] and method [PUT]'

As stated in the title, when I try to use the index API in python to index a json document, I get this error every time. I am brand new to the ELK stack but have followed the quick start guides on their website and I have been stuck here for quite some time. If any one could provide some insight into what's going here that would much appreciated. Thank you!!

Below is the code that I am running to try and index my document.

from elasticsearch import Elasticsearch
import configparser
import json

data_file_name = "/home/phil/PcapFiles/test1.json"
config_file_name = "/home/phil/ElasticPython/configuration.ini"

# Load config file for elastic user for ElasticSearch
config = configparser.ConfigParser()
config.read(config_file_name)

# Create the client instance
client = Elasticsearch(
    cloud_id=config["ELASTIC"]["cloud_id"],
    http_auth=(config["ELASTIC"]["user"], config["ELASTIC"]["password"])
)

# Successful response!
print("\n\nConnection Status Server Response...")
print("--------------------------------------------------------------\n")
print(client.info())


# create new index (like a new table in a database)
#print("\n\nIndex Creation Server Response...")
#print("---------------------------------------------------------------\n")
#resp = client.indices.create("test_network_data")
#print(resp)

# refresh newly created index
client.indices.refresh(index="test_network_data")

# send json formated data to ElasticSearch server
print("\n\nData Transmission Server Response...")
print("---------------------------------------------------------------\n")
f = open(data_file_name)
f_content = f.read()
response = client.index(index="test_network_data", ignore=400, doc_type="json", id=1, document=json.loads(f_content))
print(response)

Which version of the Elasticsearch library are you using, and which version is your Elasticsearch?

This should not be used, Elasticsearch does not uses type since version 7.X.

Try to remove this and see if it works.

1 Like

Thanks @leandrojmp for such a quick reply!! I am using version 8.11 for the library and 8.11 for Elastic search (setup through their own cloud service). I removed the doc_type="json" as you mentioned and now I get the following error:

ApiError(500, 'not_x_content_exception', 'not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes')

If I'm not wrong this error happens when the content you are sending to Elasticsearch is not in the correct format.

What is the content of your file?

Add a print(f_content) to your code and share it.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.