[英]Elasticsearch send a get request not post
This is my code for sending a GET
request to my elasticseach server: 这是用于将GET
请求发送到我的elasticseach服务器的代码:
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
client.search({
index: 'deals',
type: 'couchbaseDocument',
body: {
query: {
match: {
source: 'doc.amenities'
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
}, function (err) {
console.trace(err.message);
});
However, this is the actual request that is being send, after checking chrome developing tools
: 但是,这是after checking chrome developing tools
发送的实际请求:
POST "http://localhost:9200/deals/couchbaseDocument/_search".
but I need it to be GET
not POST
但我需要的是GET
不是POST
how please? 怎么样
I already checked the documentation : 我已经检查了文档 :
and they just say how to send head
and post
, there is no GET
requests 他们只是说如何发送head
和post
,没有GET
请求
Most browsers do not allow you to append a body to a GET
request, which is the reason that the library does not work this way, as well as why the REST API accepts POST
for what is purely a read only request. 大多数浏览器不允许您将主体附加到GET
请求,这是库无法以这种方式工作的原因,以及REST API接受POST
纯粹是只读请求的原因。
You could override the behavior by changing the default method
used (by passing your own method
), but I would suggest against doing that in order to guarantee compatibility. 您可以通过更改所使用的默认method
(通过传递自己的method
)来覆盖行为,但是我建议您不要这样做,以确保兼容性。 I assume that you are fighting a proxy to ensure that only read only requests are allowed. 我假设您正在与代理进行斗争,以确保只允许只读请求。 Instead of trying to fight the browser(s) to work for the proxy, you should just make exceptions for POST
requests whose URLs end with /_search
to Elasticsearch. 与其尝试与浏览器争用该代理, /_search
对URL以/_search
到Elasticsearch结尾的POST
请求进行例外处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.