[英]Why isn't this urlencode JSON GET request working?
$word = $_GET['search'];
$json = json_encode('{"query":{"match":{"name":"'.$word.'"}}}');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://10.128.0.2:9200/testers/test/_search' . urlencode($json));
$resp = curl_exec($curl);
$word is filled from the URL and this is working normally. $ word是从URL填充的,它可以正常工作。 $resp isn't coming back with any value.
$ resp不会返回任何值。 'name' is the name of elasticsearch field.
“名称”是elasticsearch字段的名称。
I am using PHP to run this curl request as per elasticserch except all in one URL. 我正在使用PHP 按照elasticserch运行此curl请求,除了所有在一个URL中。 Are there any better ways to do this from PHP code?
有没有更好的方法可以从PHP代码执行此操作?
如果使用的是GET调用,则需要在source
查询字符串参数中传递查询:
curl_setopt($curl, CURLOPT_URL, 'http://10.128.0.2:9200/testers/test/_search?source=' . urlencode($json));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.