0

我正在尝试在特定命名空间下的集合中创建索引,但不确定如何操作。

我的资源有一个 HTTP 示例:

POST /example/v1/index/{namespace}/{set}/{indexName}

对于示例输入:

 {
 "fields": [
     { "indexField": "firstName", "indexReverseOrder": true },
     { "indexField": "lastName" }
 ],
 "options": {
     "isUnique": true
 }
}

这消耗

application/json;charset=UTF-8

但是当我把它写成

curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d " {
 "fields": [
     { "indexField": "firstName", "indexReverseOrder": true },
     { "indexField": "lastName" }
 ],
 "options": {
     "isUnique": true
 } }" -H "Content-type : application/json;charset=UTF-8"

我得到以下 HTTP 状态代码

HTTP/1.1 415 Unsupported Media Type

谁能向我解释发生了什么以及如何解决这个问题?另外,如果您没有足够的有关 API 的信息来理解它,请告诉我,谢谢!

编辑:

作为某种参考,对于这个 API,当我在命名空间中创建一个集合时,我会这样做:

curl -X POST http://exampleurl.com/example/v1/store/example_namespace -d "example_set" -H "Content-type: application/json;charset=UTF-8" 

这是成功的。我认为索引会与此类似,但显然不是。

4

2 回答 2

0

该错误是由于 bash shell 误解了 json 之前的双引号

curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d " {
 "fields": [
     { "indexField": "firstName", "indexReverseOrder": true },
     { "indexField": "lastName" }
 ],
 "options": {
 "isUnique": true
 } }" -H "Content-type : application/json;charset=UTF-8"

应该:

curl -X POST exampleurl.com/example/v1/index/example_namespace/example_set/example
set -d ' {
 "fields": [
     { "indexField": "firstName", "indexReverseOrder": true },
     { "indexField": "lastName" }
 ],
 "options": {
 "isUnique": true
 } }' -H "Content-type : application/json;charset=UTF-8"

不同之处在于封装 json 的单引号。bash shell 在尝试执行命令时会出错。

于 2013-05-02T21:47:48.280 回答
-1

您的媒体类型有错字:

application/json;charset=UTF=8

应该:

application/json;charset=UTF-8
于 2013-05-02T18:21:03.967 回答