Я обновил solr до последней версии 7.x, и теперь мое приложение, похоже, больше не удаляет записи с помощью curl.
Исходный запрос:
curl_request("http://".SOLR_SERVER_USERNAME.":".SOLR_SERVER_PASSWORD."@".SOLR_SERVER_HOSTNAME.":".SOLR_SERVER_PORT."/".SOLR_SERVER_PATH."/update?stream.body=<delete><query>id:".$cl_active['id']."</query></delete>&commit=true");
приводит к:
http://rex:8983/solr/findix/update?stream.body=%3Cdelete%3E%3Cquery%3Eid:978382%3C/query%3E%3C/delete%3E&commit=true
Ответ:
// 20190329102610 // http://rex:8983/solr/findix/update?stream.body=%3Cdelete%3E%3Cquery%3Eid:978382%3C/query%3E%3C/delete%3E&commit=true
{"error": {"metadata": ["error-class", "org.apache.solr.common.SolrException "," root-error-class "," org.apache.solr.common.SolrException "]," msg ":" Тело потока отключено. Для получения справки см. http://lucene.apache.org/solr/guide/requestdispatcher-in-solrconfig.html"," code ": 400}}
Поэтому я изменил его так, как нашел в этом ответе на SO :
update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>id:978388</query></delete>'
следующим образом: curl_request ("http://".SOLR_SERVER_USERNAME.":".SOLR_SERVER_PASSWORD."@".SOLR_SERVER_HOSTNAME.":".SOLR_SERVER_PORT."/".SOLR_SERVER_PATH."/update?commit=true -H 'Content-Type: text / xml' --data-binary 'id:". $ Cl_active [' id ']. "'");
приводит к:
http://rex:8983/solr/findix/update?commit=true%20-H%20%27Content-Type:%20text/xml%27%20--data-binary%20%27%3Cdelete%3E%3Cquery%3Eid:978384%3C/delete%3E%27
Ответ:
// 20190329102745 // http://rex:8983/solr/findix/update?commit=true%20-H%20%27Content-Type:%20text/xml%27%20--data-binary%20%27%3Cdelete%3E%3Cquery%3Eid:978384%3C/delete%3E%27
{"responseHeader": {"status": 0, "QTime": 0}}
Что не так с измененным запросом, и как я могу сейчас удалить записи из индекса с помощью curl?
Отредактированные вопросыn с предложением для curl через PHP:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".SOLR_SERVER_HOSTNAME.":".SOLR_SERVER_PORT."/".SOLR_SERVER_PATH."/update?commit=true");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml; charset=utf-8'));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch,CURLOPT_USERPWD , "".SOLR_SERVER_USERNAME.":".SOLR_SERVER_PASSWORD."");
curl_setopt($ch, CURLOPT_POSTFIELDS, "<delete><query>id:".$cl_active['id']."</query></delete>");
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
# this is your XML as given in your example above (i.e. <delete>...)
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$data = curl_exec($ch);
Ответ
<lst name="responseHeader"> <int name="status">400</int> <int name="QTime">0</int> </lst> <lst name="error"> <lst name="metadata">
<str name="error-class">org.apache.solr.common.SolrException</str>
<str name="root-error-class">com.ctc.wstx.exc.WstxEOFException</str> </lst> <str name="msg">Unexpected EOF in prolog at [row,col {unknown-source}]: [1,0]</str> <int name="code">400</int> </lst> </response>