2013-05-02 88 views
0

我试图在特定命名空间下的一个集合内创建一个索引,但我不确定如何去做。使用REST API创建索引

我的资源都有这个HTTP例如:

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

和一个例子输入:

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

消耗了

但是当我写这篇文章出来作为

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" 

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

回答

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会在尝试执行命令时出错。

-1

你在你的媒体类型有一个错字:

application/json;charset=UTF=8 

应该是:

+0

啊,是的。发布问题时只是一个印刷错误。我打电话时听起来很健康 – MITjanitor 2013-05-02 18:22:22