简体   繁体   中英

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. $resp isn't coming back with any value. 'name' is the name of elasticsearch field.

I am using PHP to run this curl request as per elasticserch except all in one URL. Are there any better ways to do this from PHP code?

如果使用的是GET调用,则需要在source查询字符串参数中传递查询:

curl_setopt($curl, CURLOPT_URL, 'http://10.128.0.2:9200/testers/test/_search?source=' . urlencode($json));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM