merlin
merlin

Reputation: 2917

Cant' delete entries in solr 7.7.x with curl after upgrading from 5.x

I upgraded solr to the latest 7.x version and now my application seems not to remove entries via curl anymore.

Original request:

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");

results in :

http://rex:8983/solr/findix/update?stream.body=%3Cdelete%3E%3Cquery%3Eid:978382%3C/query%3E%3C/delete%3E&commit=true

Response:

// 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": "Stream Body is disabled. See http://lucene.apache.org/solr/guide/requestdispatcher-in-solrconfig.html for help", "code": 400 } }

Therefore I altered it as found in this answer at SO:

update?commit=true -H "Content-Type: text/xml" --data-binary '<delete><query>id:978388</query></delete>'

like this: 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']."'");

results in:

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

Response:

// 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 } }

What is wrong with the altered request, and how can I delete entries from the index via curl now?

Edited Question with suggestion for curl via 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);

Response

<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>

Upvotes: 0

Views: 328

Answers (1)

MatsLindh
MatsLindh

Reputation: 52832

The curl parameters are indented to be used with the command line version of curl. In your case you'll have to modify the curl_request method to set the appropriate headers and POST data for your request.

In PHP you can do this through curl_setopt (or with curl_setopt_array):

curl_setopt($ch, CURLOPT_URL, '... .path ...');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml')); 
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, 1);
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);
$result = curl_exec($ch);

Upvotes: 2

Related Questions