Skip to content

Martini Deleting Solr Documents

This section outlines methods for deleting documents from a custom search index in Martini using Solr. There are two primary approaches: using functions and using a SolrClient object.

Using Functions

The easiest way to delete an existing document in Solr is by using function methods from the SolrMethods class. The following methods are available:

  • SolrMethods.deleteById(String, String, List<String>)
  • SolrMethods.deleteByQueryString(String, String, String)
  • SolrMethods.deleteByQuery(String, String, String)

Example

To delete a document with the ID 4fc1a64f-7226-4aad-bf27-5c399e2c453c, you can use either of the following:

1
2
'movie-core'.deleteById(null, ['4fc1a64f-7226-4aad-bf27-5c399e2c453c'])
'movie-core'.deleteByQueryString(null, 'id:4fc1a64f-7226-4aad-bf27-5c399e2c453c')

Using SolrClient

For a more direct interaction with the Solr core, use the SolrClient object. This approach requires familiarity with SolrJ and Groovy.

Example

To delete a document with the ID 4fc1a64f-7226-4aad-bf27-5c399e2c453c using SolrClient:

1
2
3
SolrClient solrClient = 'movie-core'.solr()
solrClient.deleteById(['4fc1a64f-7226-4aad-bf27-5c399e2c453c'])
solrClient.deleteByQuery('id:4fc1a64f-7226-4aad-bf27-5c399e2c453c')