我不知道我做错了什么.记录没有添加.
这是我的代码:
$ch = curl_init("http://127.0.0.1:8983/solr/collection1/update/json?commit=true");
$data = array(
"add" => array( "doc" => array(
"id" => "HW132",
"name" => "Hello World"
))
);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$response = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)
这是我从索尔得到的回应:
{"responseHeader":{"status":0,"QTime":4}}
Run Code Online (Sandbox Code Playgroud)
显然,我需要让Apache Solr提交文档.它不会自动提交文档,也可能不知道如何配置它来自动提交.以下是工作示例.希望它能帮助那些有同样问题的人.
$ch = curl_init("http://127.0.0.1:8983/solr/collection1/update?wt=json");
$data = array(
"add" => array(
"doc" => array(
"id" => "HW2212",
"title" => "Hello World 2"
),
"commitWithin" => 1000,
),
);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$response = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)