-1

I am trying to add data to elasticsearch with both PUT and POST

curl -k -XPUT 'https://localhost:9200/blog/article/1' -d '{"title": "New version of Elasticsearch released!", "content": "Version 2.2 released today!", "priority": 10, "tags": ["announce", "elasticsearch", "release"] }'

but I am getting error:

{"error":"no handler found for uri [/blog/article/1] and method [PUT]"}
curl -k -XPOST 'https://localhost:9200/blog/article/' -d '{"title": "New version of Elasticsearch released!", "content": "Version 2.2 released today!", "priority": 10, "tags": ["announce", "elasticsearch", "release"] }'
{"error":"no handler found for uri [/blog/article/] and method [POST]"}
Paulo
  • 8,690
  • 5
  • 20
  • 34
Ankit Raj
  • 1
  • 2

2 Answers2

0

Tldr;

This is expected behaviour as those endpoint do not exist. You should refer to the official documentation for indexing documents.

Solution

Request to index a document should look like so:

PUT /<target>/_doc/<_id>

POST /<target>/_doc/

PUT /<target>/_create/<_id>

POST /<target>/_create/<_id>

In my example I choose the first flavour.

Noticed I have renamed the index to blog_article

curl -k -XPOST 'https://localhost:9200/blog_article/_doc/1' -H "Content-Type: application/json" -d '{"title": "New version of Elasticsearch released!", "content": "Version 2.2 released today!", "priority": 10, "tags": ["announce", "elasticsearch", "release"] }'
Paulo
  • 8,690
  • 5
  • 20
  • 34
  • But now I am getting this {"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406} – Ankit Raj Sep 29 '22 at 11:06
  • Ah because you need the header `-H "Content-Type: application/json"`, I forgot about it – Paulo Sep 29 '22 at 11:30
  • error":{"root_cause":[{"type":"security_exception","reason":"missing authentication credentials for REST request [/blog_article/_doc/1]","header":{"WWW-Authenticate":["Basic realm=\"security\" charset=\"UTF-8\"","Bearer realm=\"security\"","ApiKey"]}}],"type":"security_exception","reason":"missing authentication credentials for REST request [/blog_article/_doc/1]","header":{"WWW-Authenticate":["Basic realm=\"security\" charset=\"UTF-8\"","Bearer realm=\"security\"","ApiKey"]}},"status":401}curl: (3) URL using bad/illegal format or missing URL this time above error is coming – Ankit Raj Sep 29 '22 at 11:34
  • You need to authenticate yourself – Paulo Sep 29 '22 at 11:35
  • I am new to elasticsearch can you please help me with command like where to put authentication value also I have tried to index this way according to curl -u ank:password https://localhost:9200/my_index/_doc -H "Content-Type: application/json" -XPOST -k 'Content-Type: application/json' -d '{ "title": "One", "tags": ["ruby"] }' as suggested here elastic.co/guide/en/cloud/current/… but it also gives the same error as above – Ankit Raj Sep 29 '22 at 11:46
  • That is a different question @AnkitRaj. We need more information about your set up. what password did you set ? which user has been created ? are you using `xpack` ? Ask another question – Paulo Sep 29 '22 at 11:53
  • Try again without "-u" flag, because you already informed the user inside the url. – Trickster Júnior Sep 29 '22 at 16:26
0

I also got the error No handler found for uri [/indexname/ ] and method [DELETE], which was caused by left over undesired white space. If you are using Linux, check with VI whether there is any left-over white space by moving the cursor to the end of the call to curl.

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Luqman
  • 1