【发布时间】:2019-06-04 09:58:45
【问题描述】:
我正在尝试通过批量 API 将文档添加到弹性搜索索引。我的 CURL 查询在命令行上运行良好,我将其转换为 PHP。
当我尝试运行 PHP 代码时,没有任何反应。弹性搜索的索引中没有添加任何文档,也没有出现任何错误。
CURL 查询:
curl -H "Content-Type:application/json" -XPOST "http://localhost:9200/inven/default/_bulk?pretty" --data-binary "@file_name.json"
PHP 查询:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:9200/inven/default/_bulk?pretty');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post = array(
'file' => '@' .realpath('file_name.json')
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
我也设置了ini_set('max_execution_time', 0);,以防它超时。
可能是什么问题?
【问题讨论】:
标签: php elasticsearch curl elasticsearch-php