Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No handler found for uri [/<index>/<type>/] and method [PUT]

Tags:

I'm trying to make a raw NodeJS http request to my elasticsearch index using the insert document api's auto increment id feature.

So this works with curl:

curl -XPOST http://host:3333/catalog/products -d '{ "hello": "world" }'

But when I try the same in nodejs via this:

var http = require('http');  var options = {   protocol: 'http:',   mehtod: 'PUT',   hostname: 'host',   port: 3333,   path: '/catalog/products/' }  http.request(options, ...); 

It returns this error:

No handler found for uri [/catalog/products/] and method [PUT]

However if I add an id to the end of that path it will work. What's wrong here?

like image 433
Breedly Avatar asked Jan 26 '16 22:01

Breedly


1 Answers

The problem here is the way POST and PUT works, when you use POST, _id is optional, ES will generate a unique _id for you every time.

Here you are using PUT so _id is required, ES will either create a new document with that id or it will update the document with that id if it exists. You can read more about this.

Try indexing with POST request as you did with curl if you dont want to specify id

var options = {   protocol: 'http:',   hostname: 'host',   port: 3333,   path: '/catalog/products/',   method: 'POST'                  <--- specify method } 

Hope this helps!

like image 100
ChintanShah25 Avatar answered Sep 21 '22 18:09

ChintanShah25