找不到用于uri的处理程序[/< index> /< type> /]和方法[PUT]

编程入门 行业动态 更新时间:2024-10-25 14:24:32
本文介绍了找不到用于uri的处理程序[/< index> /< type> /]和方法[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 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的处理程序[/&lt; index&gt; /&lt; type&gt; /]和方法[PUT]

本文发布于:2023-11-09 06:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571595.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:找不到   程序   方法   amp   lt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!