Index is getting corrupted

I have a process that deletes a large number of instances from a doctype and adds large number of instances one by one. When this process is run
more than once the index seems to get corrupted.

For example if the doctype is ‘person’ and the element in the doctype is ‘id’, which is indexed as text,standard. The query person[id=‘20123’]
results in person instances with ids 20123,23023.
This result varies from id to id.

If the same query above issued as person[id~=‘20123’]. The results are correct.

Once the person doctype is reindexed, the results are correct.

Large amount of inserts and deletes seem to corrupt the index.