title: Lucene .NET IndexWriter DeleteDocuments Not Working
body: <p>Here is the code:</p>
  
  <pre><code>Try
          Dim util As New IndexerUtil()
          Dim dir As Lucene.Net.Store.Directory = FSDirectory.Open(New DirectoryInfo(util.getIndexDir()))
          Dim indexWriter As New IndexWriter(dir, New SimpleAnalyzer(), indexWriter.MaxFieldLength.UNLIMITED)
  
          Dim numDocs As Integer = indexWriter.NumDocs()
  
          indexWriter.DeleteDocuments(New Term("id", insightId))
          indexWriter.Optimize()
          indexWriter.Commit()
          indexWriter.Close()
          numDocs = indexWriter.NumDocs()
  
      Catch ex As Exception
          LOG.Error("Could not remove insight " + insightId + " from index", ex)
      End Try
  </code></pre>
  
  <p>numDocs = 85 both times</p>
  
  <p>I also have a little gui app I wrote which reads the index and prints the docs out in a nice format. The doc with the id field that equals insightId definitely exists and STILL exists after the "deletion".</p>
  
  <p>Here is how the id field is being created</p>
  
  <pre><code>doc.Add(New Field("id", insightID, Field.Store.YES, Field.Index.ANALYZED)) //insightID is an integer
  </code></pre>