Deleting documents

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Search MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-search -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-search/search-net-mcp:latest
Folders, licensing and more →

Documents can be deleted from the search network using the Delete method of the Indexer class.

To delete documents, pass an array of document keys, as well as a delete options object, to the Delete method of the Indexer class. The keys are the keys that were specified when the documents were added. Since version 26.11, a key of a document that the network has not indexed is reported by the ErrorOccurred event of the master node, and the deletion of the other documents completes.

Deleted documents are excluded from search results immediately, but their data are physically removed from the shards only by optimization.

An asynchronous delete flag is available as an option (DeleteOptions.IsAsync). In the case of asynchronous deletion, you can track the completion of the operation by subscribing to the DeletionCompleted event.

The examples on this page use the master node of a running search network. The following code creates and starts the master node as described on the Search network deployment page; the slave nodes must be started beforehand.

C#

string basePath = @"c:\SearchNetwork\";
int basePort = 49100;

// Loading the search network configuration from a file
Configuration configuration = Configuration.Load(basePath + "Configuration.xml");

// Creating, configuring and starting the master node; the timeouts are specified in milliseconds
SearchNetworkNode node = SearchNetworkNode.CreateMasterNode(
    0,
    basePath + "Node0",
    new TcpSettings(basePort, 3000, 3000, 3000, 1000),
    new FileLogger(basePath + "Log.txt", 4.0),
    configuration);
node.ConfigureAllNodes();
node.Start();

The following code example, which continues the previous one, demonstrates how to delete documents from the search network. The documents were added from the files of the specified folder with the file names as document keys.

C#

Console.WriteLine();
Console.WriteLine("Deleting documents");

string[] filePaths = Directory.GetFiles(@"c:\MyDocuments\");
string[] fileNames = new string[filePaths.Length];
for (int i = 0; i < filePaths.Length; i++)
{
    string filePath = filePaths[i];
    string fileName = Path.GetFileName(filePath);
    fileNames[i] = fileName;
}

Indexer indexer = node.Indexer;

DeleteOptions options = new DeleteOptions();
indexer.Delete(fileNames, options);

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.