Solr, bulk delete by multiple id

Viewed 2433

Workflow:

remote source -> import to mysql -> select all outdated records in mysql -> send request to SOLR with all outdated records ids -> solr delete by multiple ids > push new records to Solr.

What is right query syntax to delete documents by multiple ids?

I trying:

id:(1 OR 2 OR 3)...
id:(1 AND 2 AND 3)

in php:

$query = sprintf('id:(%s)', implode(' AND ', $toDelete));

$solrUrl = sprintf('http://%s:%s/%s/%s', $this->solr['host'], $this->solr['port'], $this->solr['path'], $action);
        $docs = [
            'delete' => ['query' => $query]
        ];
        $http = new Client();
        $http->post($solrUrl, json_encode($docs),['type' => 'json', 'timeout' => 30]);
2 Answers

The clue is to simply rewrite the delete request as a delete by query, and then submit all the id’s to be removed as a simple OR query. Needless to say, that’s more than fast enough and solved our problem.

To sum it up; write a delete-by-query-statement as:

id:(123123 OR 13371337 OR 42424242 .. )

I'd advise against using a delete by query. Instead send the delete command directly via XML or JSON which is more efficient.

  • JSON: {"delete":["1","2","3"]}
  • XML: <delete><id>1</id><id>2</id><id>3</id></delete>
Related