Cloudant、PHP和范围查询的错误请求

Cloudant、PHP和范围查询的错误请求,php,curl,couchdb,cloudant,Php,Curl,Couchdb,Cloudant,我正在尝试使用PHP cURL和Cloudant进行范围查询 我已在Cloudant中设置了以下搜索索引: { "_id": "_design/date", "_rev": "20-822ebda694f4fb57dc0a48bf60f6570f", "views": {}, "language": "javascript", "indexes": { "by_date": { "analyzer": "classic", "index": "

我正在尝试使用PHP cURL和Cloudant进行范围查询

我已在Cloudant中设置了以下搜索索引:

{
  "_id": "_design/date",
  "_rev": "20-822ebda694f4fb57dc0a48bf60f6570f",
  "views": {},
  "language": "javascript",
  "indexes": {
    "by_date": {
      "analyzer": "classic",
      "index": "function (doc) {\n  index(\"default\", doc.datequery);\n}"
    }
  }
}
然后在我的PHP文档中,我执行以下操作:

$urlstuff = "[20180110 TO 20180119]";

$url = "https://user:pass.@user.cloudant.com/db/_design/date/_search/by_date?q=".$urlstuff."&include_docs=true&limit=200";
$ch = curl_init();   // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
我收到了一个不好的请求

如果我替换:

$urlstuff = "[20180110 TO 20180119]"; 
为了

然后我得到了很好的结果

是方括号弄乱了我的卷发吗?
我错过了什么?

是的,你在正确的轨道上。如果您转义变量(例如,使用?),您的查询应该可以工作:

curl -g -X GET   'https://user:password@user-bluemix.cloudant.com/db/_design/date/_search/by_date?q=[20180110 TO 20180119]&include_docs=true&limit=20'   


{"error":"bad_request","reason":"Bad request"}
vs


是的,你在正确的轨道上。如果您转义变量(例如,使用?),您的查询应该可以工作:

curl -g -X GET   'https://user:password@user-bluemix.cloudant.com/db/_design/date/_search/by_date?q=[20180110 TO 20180119]&include_docs=true&limit=20'   


{"error":"bad_request","reason":"Bad request"}
vs


你能看到回复的细节吗?这可能会给你更多的信息。我建议您在不使用PHP的情况下尝试请求,以确保您清楚自己的目标-根据这些字段的数据类型,您可能需要引用这些值,例如。@LornaMitchell在控制台中收到相同的“错误请求”消息,仅此而已!:/你能看到回复的细节吗?这可能会给你更多的信息。我建议您在不使用PHP的情况下尝试请求,以确保您清楚自己的目标-根据这些字段的数据类型,您可能需要引用这些值,例如。@LornaMitchell在控制台中收到相同的“错误请求”消息,仅此而已!:/
curl -X GET 'https://user:password@user-bluemix.cloudant.com/db/_design/date/_search/by_date?q=%5B20180110%20TO%2020180119%5D&include_docs=true&limit=20' 

{"total_rows":1, ...