He or she who answers this question will have a very special place in my heart. I'm trying to update many records at once using Curl with PHP on elasticsearch 7.13. It seems that no matter what I do, I get the error "The bulk request must be terminated by a newline". I have tried many, many renditions of this code. Is there perhaps a way to overload what PHP CURL is doing to force it to use binary data? I believe it is stripping the newline characters, but if I change to plain text submission it won't be accepted by elasticsearch.
public function bulkUpdate(){
$query_json_store = '';
foreach($this->records['hits']['hits'] as $person){
$entry1 = [
"update"=>[
"_id"=> $person['_id'],
"type"=> "doc",
"_index"=> "human_data",
]
];
$entry2 = [
"doc"=>[
"scanned"=> true
]
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'localhost:9200/human_data/doc/_bulk');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, '\n'.json_encode($params)).'\n';
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$headers = array();
$headers[] = 'Content-Type: application/x-ndjson';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
\Log::info($result);
}
}