Skip to content

Home

Development

IDEs

API Explorer

Releases

Release notes

Martini Runtime

Martini Desktop

Martini Online

Feature requests

Bug reports

Deleting a document from a custom search index

There are two ways you can delete a Solr document in Martini: using one-liners and using a SolrClient object.

Get the code!

The scripts mentioned in this guide are available in the examples package. As bonus, you can find other services in the examples package that demonstrate the use of one-liners from the SolrMethods class, as well as other Solr-related functionality.

Using one-liners

True to its purpose, using a one-liner is the easiest way to delete an existing document. There are three one-liner methods you can use to delete a Solr document, all from SolrMethods:

The example below shows how to delete a document with the ID 4fc1a64f-7226-4aad-bf27-5c399e2c453c:

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

Using SolrClient

A call to the one-liner method SolrMethods.solr(String) returns a SolrClient object which you can use to directly interact with the Solr core tied to it (specified by passing the name of the core as the argument). However to use SolrClient, one must be familiar with SolrJ and Groovy.

The example below shows how to delete a document with the ID 4fc1a64f-7226-4aad-bf27-5c399e2c453c:

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