Home > Blockchain >  Postman gives me the following error: "error": "no handler found for uri [/megacorp/e
Postman gives me the following error: "error": "no handler found for uri [/megacorp/e

Time:07-12

I am just starting with Elasticsearch and I have started with adding an index, which works and I can get information about it:

GET http://localhost:9200/megacorp

"megacorp": {
    "aliases": {},
    "mappings": {},
    "settings": {
        "index": {
            "routing": {
                "allocation": {
                    "include": {"_tier_preference": "data_content"
                    }
                }
            },
            "number_of_shards": "1",
            "provided_name": "megacorp",
            "creation_date": "1657286196414",
            "number_of_replicas": "1",
            "uuid": "HbsAAv-mRziSUKGiXPMyPA",
            "version": {
                "created": "8030299"

The problem comes when I try to add a document, I get the following error:

PUT http://localhost:9200/megacorp/empoyee/1

"first_name": "John", "last_name": "Smith", "age": 25, "about": "I love to go rock climbing", "interests": ["sports", "music"]

"error": "no handler found for uri [/megacorp/empoyee/1] and method [PUT]"

I think I've done everything right, but it still does not work.

CodePudding user response:

Problem here, that you are using wrong URL in your request. According to documentation you must use use following paths for document index:

Request
PUT /<target>/_doc/<_id>

POST /<target>/_doc/

PUT /<target>/_create/<_id>

POST /<target>/_create/<_id>

So you are missing _doc or _create part.

UPDATE: cURL Example

curl -X PUT --location "http://localhost:9200/megacorp/1" \
-H "Content-Type: application/json" \
-d "{
      \"first_name\": \"John\",
      \"last_name\": \"Smith\",
      \"age\": 25,
      \"about\": \"I love to go rock climbing\",
      \"interests\": [\"sports\", \"music\"]
    }"

CodePudding user response:

From elasticsearch 8.x mapping types are removed. You need to use this for indexing the documents

http://localhost:9200/megacorp/_doc/1
  • Related