curl以上的请求是一个有效的请求,实际上如果你有索引和数据,那么你可以检查你的命令的输出。
我在我的系统和 ES 索引中尝试了它,它给了我正确的响应。
curl -v -X GET "localhost:9500/querytime/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"query_string" : {
"query" : "(avengers) OR (big apple)",
"default_field" : "movie_name"
}
}
}'
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 9500 (#0)
> GET /querytime/_search?pretty HTTP/1.1
> Host: localhost:9500
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 156
>
* upload completely sent off: 156 out of 156 bytes
< HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
< content-length: 905
<
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 0.14874382,
"hits" : [
{
"_index" : "querytime",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.14874382,
"_source" : {
"movie_name" : "Avengers: Infinity War"
}
}
]
}
}
在 curl 命令的官方手册中提到,如果您使用的是基于*nix 的系统,那么您可以在下面的curl 手册中搜索。
-G, --get
使用时,此选项将使所有使用 -d、--data、--data-binary 或 --data-urlencode 指定的数据用于
HTTP GET 请求而不是 POST 请求,否则将是
用过的。这
数据将附加到带有“?”的 URL分隔符
正如this SO 回答中所解释的,它还依赖于网络服务器来解析 GET 请求中的正文。