GroupDocs.Search has the ability to remove individual documents from the index that are indexed from a stream or structure. To remove documents indexed by a file system path, see Deleting indexed paths.
The following example shows how to remove documents from an index by document key.
constfilePath='c:/MyDocuments/SomeDocument.pdf';constindexFolder='c:/MyIndex/';constquery='Einstein';// Creating an index in the specified folder
constindex=newgroupdocs.search.Index(indexFolder,true);// Indexing the document from stream
constdocumentKey=path.basename(filePath);constdocumentLoader=java.newProxy('com.groupdocs.search.common.IDocumentLoader',{closeDocument:function(){},loadDocument:function(){constmillis=java.callStaticMethodSync('java.lang.System','currentTimeMillis');consttime=java.newInstanceSync('java.util.Date',millis);constextension=path.extname(filePath);constbuffer=Utils.readBinaryFile(filePath);constarray=Array.prototype.slice.call(buffer,0);constbuf=java.newArray('byte',array);conststream=java.newInstanceSync('java.io.ByteArrayInputStream',buf);constdocument=java.callStaticMethodSync('com.groupdocs.search.Document','createFromStream',documentKey,time,extension,stream,);returndocument;},});constdocument=java.callStaticMethodSync('com.groupdocs.search.Document','createLazy',groupdocs.search.DocumentSourceKind.Stream,documentKey,documentLoader,);constdocuments=java.newArray('com.groupdocs.search.Document',[document]);// Subscribe to index events
consteventHandler=java.newProxy('com.groupdocs.search.events.EventHandler',{invoke:function(sender,args){console.log(args.getMessage());// Writing error messages to the console
},});index.getEvents().ErrorOccurred.add(eventHandler);index.add(documents,newgroupdocs.search.IndexingOptions());// Getting indexed documents from the index
constindexedDocuments1=index.getIndexedDocuments();// Writing indexed documents to the console
console.log('Indexed documents ('+indexedDocuments1.length+'):');for(leti=0;i<indexedDocuments1.length;i++){constinfo=indexedDocuments1[i];console.log('\t'+info);}// Searching in the index
constsearchResult1=index.search(query);// Deleting indexed document from the index
constdocumentKeys=java.newArray('java.lang.String',[documentKey]);constdeleteResult=index.delete(newgroupdocs.search.UpdateOptions(),documentKeys);console.log('\nDeleted documents: '+deleteResult.getSuccessCount());// Getting indexed paths after deletion
constindexedDocuments2=index.getIndexedDocuments();console.log('\nIndexed documents ('+indexedDocuments2.length+'):');for(leti=0;i<indexedDocuments2.length;i++){constinfo=indexedDocuments2[i];console.log('\t'+info);}// Searching in the index
constsearchResult2=index.search(query);
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: