Curl command from terminal works however, php CURL doesnt pull the records

I have the following php curl commands running on the same server where the ES is installed and running on port 9200.

function($data_string){
$ch = curl_init('http://localhost:9200/cfaq/_search');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
}

This curl function is returning the following whatever Search Query i use.

{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":}}

However, when I try same search query on same server using terminal curl command (eg: curl -X POST 'http://localhost:9200/cfaq/_search?q=Job'), I get the desired
results. Here is my configuration on elasticsearch.yml file:


bootstrap.memory_lock: true
network.host: localhost
http.port: 9200


My Elastic search version is 6.5.0
Please let me know if you have any questions.
Can you please let me know what I am doing wrong?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.