找不到用于uri的处理程序[/< index> /< type> /]和方法[PUT] [英] No handler found for uri [/<index>/<type>/] and method [PUT]
问题描述
我正在尝试使用插入文档api的自动增量ID功能将原始的NodeJS http请求发送到我的弹性搜索索引。
所以这样与 curl
:
curl -XPOST http:// host:3333 / catalog / products -d' {hello:world}'
但是当我在nodejs中尝试相同时:
var http = require('http');
var options = {
protocol:'http:',
mehtod:'PUT',
hostname:'host',
port:3333 ,
path:'/ catalog / products /'
}
http.request(options,...);
它返回此错误:
找不到uri [/ catalog / products /]和方法[PUT]的处理程序
但是,如果我添加一个 id
到该路径的末尾它将工作。这里有什么问题?
这里的问题是 POST
PUT
可以使用 POST
, _id
是可选的,ES将每次为您生成一个唯一的 _id
。
您正在使用 PUT
所以 _id
是必需,ES将使用该ID创建一个新文档,否则将更新文档该id如果存在的话。您可以阅读关于这一点的更多。 p>
尝试使用 POST
请求索引,如同 curl
你不要指定id
var options = {
protocol:'http:',
hostname :'host',
port:3333,
path:'/ catalog / products /',
method:'POST'< ---指定方法
}
希望这有帮助!
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?
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!
这篇关于找不到用于uri的处理程序[/< index> /< type> /]和方法[PUT]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!