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.
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#
stringbasePath=@"c:\SearchNetwork\";intbasePort=49100;// Loading the search network configuration from a fileConfigurationconfiguration=Configuration.Load(basePath+"Configuration.xml");// Creating, configuring and starting the master node; the timeouts are specified in millisecondsSearchNetworkNodenode=SearchNetworkNode.CreateMasterNode(0,basePath+"Node0",newTcpSettings(basePort,3000,3000,3000,1000),newFileLogger(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.