Lucene 6.0.0 deleting document from index
<p>I'm trying to delete a document from a Lucene index I created. And my delete code looks something like this : </p>

<pre><code>public void delete(String fname, String index_path)
   {
        try {
            Analyzer analyzer = new StandardAnalyzer();
            QueryParser parser = new QueryParser(LuceneConstants.FILE_NAME, analyzer);
            Directory indexDirectory = FSDirectory.open(Paths.get(index_path));
            IndexWriterConfig iwg = new IndexWriterConfig(analyzer);
            iwg.setMaxBufferedDeleteTerms(1);
            iwg.setOpenMode(IndexWriterConfig.OpenMode.APPEND);
            IndexWriter writer = new IndexWriter(indexDirectory,iwg);
            writer.deleteDocuments(new Term(LuceneConstants.FILE_NAME,fname));
            writer.forceMergeDeletes();
            writer.commit();
            writer.flush();
            System.out.println(writer.hasDeletions());
            writer.close();
            System.out.println("Deleted File :"+fname);
        } catch (IOException ex) {
            Logger.getLogger(IndexHandler.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            Logger.getLogger(IndexHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
   }
</code></pre>

<p>I have tried executing the above code with and without <code>forceMergeDeletes</code> and both show me <code>hasDeletions</code> as false. Is there something wrong with my code ?
I also tried opening the IndexReader in a new program to search to check if there are any delays to delete the file but I am able to search in the deleted file. When i try to delete documents using query, the whole index is deleted (even in APPEND mode) and I am sure the filenames are different for each document in the index. I am  new to Lucene if someone can help me it would be great :)</p>