弹性搜索GET请求与请求正文 [英] Elasticsearch GET request with request body

查看:154
本文介绍了弹性搜索GET请求与请求正文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



例如,为了过滤Elasticsearch中的一些信息

  curl localhost:9200 / megacorp / employee / _search -d'{query:{filtered:{filter:{range :{age:{gt:30}}},query:{match:{last_name:smith}}}}}'

某些工具甚至设计为避免GET请求中的请求身份(如邮递员)

解决方案

不。这不是。



在REST中,使用 POST 进行查询是没有意义的。 POST 应该修改服务器。当您搜索时,显然不要修改服务器。



GET b
$ b

据说,我们知道一些语言和工具不允许。虽然RFC没有提到你不能有一个具有 GET 的正文。



所以弹性搜索也支持 POST



This:

 code> curl -XPOST localhost:9200 / megacorp / employee / _search -d'{query:{filtered:{filter:{range:{age:{gt 30}}},查询:{match:{last_name:smith}}}}} 

将以同样的方式工作。


Isn't it against REST-style approach to pass a request body together with GET request?

For instance to filter some information in Elasticsearch

curl localhost:9200/megacorp/employee/_search -d '{"query" : {"filtered" : {"filter" : {"range" : {"age" : { "gt" : 30 }}},"query" : {"match" : {"last_name" : "smith"}}}}}'

some tools are even designed to avoid request body in GET request (like postman)

解决方案

No. It's not.

In REST, using POST to query does not make sense. POST is supposed to modify the server. When searching you obviously don't modify the server.

GET applies here very well.

That being said, we are aware that some languages and tools don't allow that. Although the RFC does not mention that you can't have a body with GET.

So elasticsearch supports also POST.

This:

curl -XPOST localhost:9200/megacorp/employee/_search -d '{"query" : {"filtered" : {"filter" : {"range" : {"age" : { "gt" : 30 }}},"query" : {"match" : {"last_name" : "smith"}}}}}'

Will work the same way.

这篇关于弹性搜索GET请求与请求正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆