请问有人可以建议我如何将这个JSON主体转换为REST URI?
GET api/_search { "age":"5", "aggs" : { "uniq_gender" : { "terms" : { "field" : "Gender.keyword" } } } }can someone please advise how can I convert this JSON body into a REST URI ?
GET api/_search { "age":"5", "aggs" : { "uniq_gender" : { "terms" : { "field" : "Gender.keyword" } } } }最满意答案
您可以选择以下两个选项之一:
使用POST与body
POST api/_search { "age":"5", "aggs" : { "uniq_gender" : { "terms" : { "field" : "Gender.keyword" } } } }它可能看起来像一个黑客,但它很简单,坦率地说它被广泛使用。 基本上从REST角度来看,它可以被视为资源创建( filter而不是seach可能是一个更好的词)。
将查询字符串与GET 。就像是:
GET api/_search?age=5,field=Gender.keyword使用查询字符串的问题是它可能是有限的。 在RFC中有一个代码用于这种情况 。 例如IE浏览器有这样的限制 - 请参阅详细信息 。
一般来说,如果没有技术问题,可能会出现可读性问题 - 很难处理1000+符号字符串。
You may proceed with one of two options:
Use POST with body
POST api/_search { "age":"5", "aggs" : { "uniq_gender" : { "terms" : { "field" : "Gender.keyword" } } } }It may seem like a hack, but it is simple and frankly it is widely used. Basically from REST perspective it may be considered as resource creation (filter rather than seach might be a better word here).
Use query string with GET.Something like:
GET api/_search?age=5,field=Gender.keywordThe problem with using query string is that it may be limited. In RFC there is a code for such a case. For example IE browser has such a limit - see details.
Generally speaking if there is no technical problem, readability issue may appear - it is hard to deal with 1000+ symbols string.
更多推荐
发布评论