【发布时间】:2018-07-17 07:17:32
【问题描述】:
我想让 cURL/Elasticsearch 理解 HTTP 查询参数作为普通字符串传递,同时由命令编码 url。
如果我通过cURL 运行此 HTTP GET 以将查询提交到 Elasticsearch:
curl \
-H 'Content-Type: application/json' \
-XGET '127.0.0.1:9200/movies/movie/_search?q=%2Byear%3A%3E1980+%2Btitle%3Astar%20wars&pretty'
然后我就可以检索预期的文档了。
但是,如果我运行此 cURL 查询:
curl \
-H 'Content-Type: application/json' \
--data-urlencode "pretty" \
--data-urlencode "q=+year:>1980 +title:star wars&pretty" \
-XGET '127.0.0.1:9200/movies/movie/_search'
然后我得到这个错误:
{
"error": {
"root_cause": [{
"type": "json_parse_exception",
"reason": "Unrecognized token 'pretty': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@7856627; line: 1, column: 8]"
}],
"type": "json_parse_exception",
"reason": "Unrecognized token 'pretty': was expecting ('true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@7856627; line: 1, column: 8]"
},
"status": 500
}
我正在使用:
-
cURL版本 7.47.0 应该理解命令参数--data-urlencode - 弹性搜索 6.3.1
【问题讨论】:
标签: elasticsearch curl urlencode url-encoding